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 / cla_script.sh
Created September 13, 2017 07:06
Sample to show how to use getopt
#!/bin/bash
# 'arg-x' and 'x' behave like flags
# 'arg-y' and 'y' have required arguments.
# 'arg-z' and 'z' have optional arguments
# Initial value for the flag parameter (default false)
X=0
# create the option string
@s-ashwinkumar
s-ashwinkumar / RsyncSSH.md
Created August 21, 2017 16:52 — forked from KartikTalwar/Documentation.md
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
@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.
@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 / 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 / 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 / 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 / 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 / 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 / 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));