Skip to content

Instantly share code, notes, and snippets.

View sayanriju's full-sized avatar

Sayan "Riju" Chakrabarti sayanriju

View GitHub Profile
@sayanriju
sayanriju / README.md
Created May 18, 2017 18:32 — forked from jxson/README.md
README.md template

Synopsis

At the top of the file there should be a short introduction and/ or overview that explains what the project is. This description should match descriptions added for package managers (Gemspec, package.json, etc.)

Code Example

Show what the library does as concisely as possible, developers should be able to figure out how your project solves their problem by looking at the code example. Make sure the API you are showing off is obvious, and that your code is short and concise.

Motivation

#!/usr/bin/env python
import sys
import json
import jinja2
templateLoader = jinja2.FileSystemLoader( searchpath="./" )
templateEnv = jinja2.Environment( loader=templateLoader )
template_file = sys.argv[1]
{
"env": {
"es6": true,
"node": true,
"mocha": true
},
"extends": "airbnb-base",
"rules": {
"func-names": ["error", "never"],
"comma-dangle": ["error", "only-multiline"],
@sayanriju
sayanriju / sayanrju.zsh-theme
Last active February 28, 2021 08:37
My ZSH Theme
local ret_status="%(?:%{$fg_bold[green]%}λ:%{$fg_bold[red]%}λ%s)"
PROMPT='${ret_status}%{$fg_bold[cyan]%}%p %{$fg[cyan]%}%c » %{$fg[green]%}%{$reset_color%}'
RPROMPT='$(git_prompt_info)%{$fg_bold[white]%}%{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[yellow]%} "
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[yellow]%}%{$fg[red]%} 🗴 %{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[yellow]%}%{$fg[green]%} 🗹 %{$reset_color%}"
@sayanriju
sayanriju / curry.js
Last active March 5, 2017 14:13 — forked from kevincennis/curry.js
curry.js
function curry( fn, arity ) {
//var arity = fn.length;
return (function resolver() {
let mem = Array.prototype.slice.call( arguments );
return function() {
let args = mem.slice();
Array.prototype.push.apply( args, arguments );
return ( args.length >= arity ? fn : resolver ).apply( null, args );
};
@sayanriju
sayanriju / isObjectEmpty.js
Created February 24, 2017 13:17
Hack to test if an Object is "empty"
Object.prototype.isEmpty = function () {
return !Object.keys(this)
.map(k => this.hasOwnProperty(k), this) // bind the value of `this` for each callback
.length
}
// Usage:
// > let obj0 = {}
// > let obj1 = {foo: 1, bar: 2}
// > obj0.isEmpty() // true
@sayanriju
sayanriju / countLetterFreq.js
Created February 17, 2017 08:45
JS Find Frequency of Letters in a Sentence
String.prototype.countLetterFreq = function () {
return this
.split('')
.filter(l => l.trim())
.map(l => l.toLowerCase())
.reduce( (acc, cur) => { acc[cur] = (acc[cur] === undefined) ? 1 : acc[cur] + 1; return acc; }, {} )
}
// Usage:
// > "This is a nice sentence".countLetterFreq()
@sayanriju
sayanriju / validator.js
Created September 27, 2016 08:09
A collection of simple validators for using with html forms
var validateEmail = function (email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
var validateAlphanumeric = function (txt) {
var re = /^[a-z0-9]*$/i;
return re.test(txt);
}
@sayanriju
sayanriju / gulpfile.js
Last active August 18, 2016 05:31
A Gulp config file for Express using goodies like livereload, nodemon & css minification
// Dependencies
var gulp = require('gulp');
var nodemon = require('gulp-nodemon');
var notify = require('gulp-notify');
var livereload = require('gulp-livereload');
// Task
gulp.task('server', function() {
// listen for changes
livereload.listen();
@sayanriju
sayanriju / Recursive Search-Replace in Shell
Created July 2, 2015 19:01
Bulk Search & Replace recursively on Bash
## Source: http://stackoverflow.com/a/1585810/1823866
find /home/www/ -type f -exec \
sed -i 's/subdomainA\.example\.com/subdomainB.example.com/g' {} +