Skip to content

Instantly share code, notes, and snippets.

Avatar

Ashwin Kumar Subramanian s-ashwinkumar

View GitHub Profile
@s-ashwinkumar
s-ashwinkumar / cla_script.sh
Created Sep 13, 2017
Sample to show how to use getopt
View cla_script.sh
#!/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 Aug 21, 2017 — forked from KartikTalwar/Documentation.md
Rsync over SSH - (40MB/s over 1GB NICs)
View RsyncSSH.md

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 Aug 21, 2017
A sample for alias method in ruby
View basicAlias.rb
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 Aug 15, 2017
Method deprecation using method_missing
View methodMissingDeprecation.rb
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 Aug 4, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// 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 / asynchCode.js
Last active Aug 4, 2017
Async equivalent of the synchronous code
View asynchCode.js
asyncMeth1()
.then(asyncMethod2)
.then(asyncMethod3)
.then(finalResult => console.log("I DID IT - "+finalResult))
.catch(failCall);
View synchronousCode.js
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 / chainedPromise.js
Last active Aug 4, 2017
Add a promise to the old one and chain it
View chainedPromise.js
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'
View consumeFirstPromise.js
willAddNewPost
.then(new_post => console.log(new_post))
.catch(error_message => console.log(error_message));
@s-ashwinkumar
s-ashwinkumar / firstPromise.js
Last active Aug 4, 2017
Sample first promise
View firstPromise.js
let iReturnEarly = true;
const willAddNewPost = new Promise(
(resolve, reject) => {
if(iReturnEarly) {
resolve("This is new post");
}else {
reject("Damn I missed it.");
}
}