Skip to content

Instantly share code, notes, and snippets.

View Kasahs's full-sized avatar

Shasak Raina Kasahs

  • O4S
  • Gurugram, India
View GitHub Profile
@Kasahs
Kasahs / syncec2
Last active August 29, 2015 14:06
automatically rsync local files with EC2 when local directory content changes, using inotifywait
#!/bin/sh
LOCAL="/path/to/local/dir"
while true
do
inotifywait -r $LOCAL
rsync -avL --progress --exclude-from rsync_exclude.list -e "ssh -i /path/to/id_rsa" /path/to/local/dir username@host:~/
done
@Kasahs
Kasahs / visibility_toggle.js
Last active August 29, 2015 14:08
Toggle visibility of an element. Chainable.
Element.prototype.toggleVisibility = function () {
this.style.visibility = (this.style.visibility == '' || this.style.visibility == 'visible') ? 'hidden' : 'visible';
return this;
}
@Kasahs
Kasahs / lnr_substring.py
Last active August 29, 2015 14:11
longest substring with non repeating chars
def lnrss(s):
"""
Returns the length of longest substring of input string with no repeated letter.
Assumes input string to be in lower case and ignores any other characters.
"""
l = 0
for i in range(len(s)):
for j in range(len(s) - i):
ss = s[j:j+i+1]
if (not has_rep(ss)) and len(ss)>=l:
@Kasahs
Kasahs / union.js
Last active August 29, 2015 14:24
Efficient pure Javascript array union
var array1 = [1,2,3,4,5];
var array2 = [1,2,3,4,5,6,7,8,9,10];
var union = [];
set = {};
for(var j = 0; j < array1.length; j++){
set[array1[j]] = true;
}
for(var k = 0; k < array2.length; k++){
set[array2[k]] = true;
}
@Kasahs
Kasahs / gitauthorstat.sh
Last active September 8, 2015 13:14
script to check author loc in git
git log --author="_author_name_" --pretty=tformat: --numstat \
| awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s\n", add, subs, loc }' -
function findUrlsAndPlaceAnchorTags(str) {
var urlRegex = /((http|https|ftp|ftps)\:\/\/)([a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)/g;
return str.replace(urlRegex, function(match, p1, p2, p3){
return "<a href='"+ match +"'>" + p3 + "</a>";
});
}
function foo(){
var callback = arguments[0] || function(){return "do nothing"};
var options = arguments[1] || {};
return [callback(), options.a || "no A", options.b || "no B", this];
}
// try these out to understand how to use apply and what it means to write functions which might be called in this way
foo(null, {a:1, b:2});
foo.apply("apples", [function(){return "do something"}, {a:1, b:2}]);
@Kasahs
Kasahs / pubsubExample.js
Last active September 15, 2015 13:00
simple javascript pubsub example
var PubSub = (function(){
var mapping = {};
return {
sub: function(eventName, callback, obj){
callback = callback || _.noop;
if(!_.isFunction(callback)){
console.error("callback is not a function");
return;
}
@Kasahs
Kasahs / .eslintrc
Created November 26, 2015 10:56
eslintrc based on google style guide with a few mods.
{
"env": {
"browser": true, // browser global variables.
"node": false, // Node.js global variables and Node.js-specific rules.
"worker": false, // web workers global variables.
"amd": false, // defines require() and define() as global variables as per the amd spec.
"mocha": false, // adds all of the Mocha testing global variables.
"jasmine": false, // adds all of the Jasmine testing global variables for version 1.3 and 2.0.
"phantomjs": false, // phantomjs global variables.
"jquery": true, // jquery global variables.
@Kasahs
Kasahs / stacked-column-chart.html
Last active December 8, 2015 14:48
Highcharts stacked vertical column graph config.
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>