Skip to content

Instantly share code, notes, and snippets.

View s-ashwinkumar's full-sized avatar

Ashwin Kumar Subramanian s-ashwinkumar

View GitHub Profile
@s-ashwinkumar
s-ashwinkumar / happy_git_on_osx.md
Created March 13, 2017 18:18 — forked from trey/happy_git_on_osx.md
Creating a Happy Git Environment on OS X

Creating a Happy Git Environment on OS X

Step 1: Install Git

brew install git bash-completion

Configure things:

git config --global user.name "Your Name"

git config --global user.email "[email protected]"

@s-ashwinkumar
s-ashwinkumar / getStuff.js
Last active August 4, 2017 08:14
Sample code to demostrate async basics
function getStuff() {
var result;
jQuery.get("amazing/long/method"), function(response) {
result = response;
}
return result;
}
var stuff = getStuff();
console.log("This is THE stuff - "+ stuff);
@s-ashwinkumar
s-ashwinkumar / firstPromise.js
Last active August 4, 2017 08:34
Sample first promise
let iReturnEarly = true;
const willAddNewPost = new Promise(
(resolve, reject) => {
if(iReturnEarly) {
resolve("This is new post");
}else {
reject("Damn I missed it.");
}
}
@s-ashwinkumar
s-ashwinkumar / consumeFirstPromise.js
Created August 4, 2017 08:16
Consume the first promise
willAddNewPost
.then(new_post => console.log(new_post))
.catch(error_message => console.log(error_message));
@s-ashwinkumar
s-ashwinkumar / chainedPromise.js
Last active August 4, 2017 08:31
Add a promise to the old one and chain it
const recordSong = function(new_post) {
// This is a shorthand for functions with just resolved state.
return Promise.resolve("I have recorded a song and "+new_post);
};
willAddNewPost
.then(recordSong)
.then(console.log)
.catch(console.log);
// Kudos to you if you caught the shorthand in 'console.log'
@s-ashwinkumar
s-ashwinkumar / synchronousCode.js
Created August 4, 2017 08:21
Sample synchronous code
try {
var result1 = syncMeth1();
var result2 = syncMeth2(result1);
var finalResult = syncMeth3(result2);
console.log("I DID IT - "+finalResult);
}catch(error){
failCall(error);
}
@s-ashwinkumar
s-ashwinkumar / asynchCode.js
Last active August 4, 2017 08:29
Async equivalent of the synchronous code
asyncMeth1()
.then(asyncMethod2)
.then(asyncMethod3)
.then(finalResult => console.log("I DID IT - "+finalResult))
.catch(failCall);
@s-ashwinkumar
s-ashwinkumar / 0_reuse_code.js
Created August 4, 2017 08:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@s-ashwinkumar
s-ashwinkumar / methodMissingDeprecation.rb
Last active August 15, 2017 05:49
Method deprecation using method_missing
class Myclass
@@old_methods = { oldMethod1: :new_method1, oldMethod2: :new_method2 }
def new_method1
'Myclass#new_method1'
end
def new_method2
'Myclass#new_method2'
end
@s-ashwinkumar
s-ashwinkumar / basicAlias.rb
Last active August 21, 2017 06:15
A sample for alias method in ruby
class MyClass
def old_method
'old_method OR new_method'
end
alias :new_method :old_method
# NOTE-1 : 'alias' is a keyword and not a method, that is why
# there is no comma (I almost everytime type a comma there !)
# NOTE-2 : If you want to use the method kind of syntax you can use
# the 'method' Module#alias_method which does the same thing
# but is actually a method.