Skip to content

Instantly share code, notes, and snippets.

View yelhady's full-sized avatar

Yehia Ahmed El Hady yelhady

View GitHub Profile
@yelhady
yelhady / display_current_git_branch_name.sh
Created August 5, 2018 21:27
Display the current git branch name
#source: https://coderwall.com/p/fasnya/add-git-branch-name-to-bash-prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
.directive('trAutoFocus', ['$timeout', function($timeout) { // A new directive that auto focuses on an element based on a boolean expression.
return {
restrict: 'A', // restricts how the directive can be used, E = as an element, A = as an attribute, C = class, M = comment.
scope: { isAutoFocus: '@trAutoFocus' }, // here we make an isolated child scope & assign a value to it, @ here works in case of attribute values of when using restrict: 'A' to get the value of the expression
link: function(scope, element) { // a function for DOM manipulation, based on the value evaluated [isAutoFocus] we set the focus of the element we have.
scope.$watch('isAutoFocus', function(value) {
if(value === "true") {
$timeout(function() {
element[0].focus();
});
@yelhady
yelhady / array-filter.js
Last active December 7, 2016 22:01
Filter elements in a given Javascript array using .filter function
var myArr = [];
myArr.push({key: 0, value: "elem-0"});
myArr.push({key: 1, value: "elem-1"});
myArr.push({key: 2, value: "elem-2"});
myArr.push({key: 3, value: "elem-3"});
//Note: to my knowlage, the .filter function returns a new array with the filtered elements.
console.log(myArr.filter(function(entry) {
if(entry.key % 2 == 0)
return true;
@yelhady
yelhady / gist:512285382b5cb9b64750d95b82c69f8a
Created December 7, 2016 00:18 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@yelhady
yelhady / gist:7d7b8a095d353bef531a1b06925162df
Created November 24, 2016 16:20 — forked from stuart11n/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@yelhady
yelhady / gist:b249b6511e4dd02397a9878ca2bae14c
Created September 8, 2016 23:22 — forked from bigsnarfdude/gist:b2eb1cabfdaf7e62a8fc
ubuntu 14.04 install scala 2.11.7 and sbt 13.9 and java 8 and git
# scala install
wget www.scala-lang.org/files/archive/scala-2.11.7.deb
sudo dpkg -i scala-2.11.7.deb
# sbt installation
echo "deb https://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 642AC823
sudo apt-get update
sudo apt-get install sbt