Skip to content

Instantly share code, notes, and snippets.

View sayanriju's full-sized avatar

Sayan "Riju" Chakrabarti sayanriju

View GitHub Profile
{
"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' {} +
@sayanriju
sayanriju / genurl.php
Created December 27, 2010 11:03
PHP Script to generate temporary redirection URL-s to permalinks (with an example form) & to perform the actual redirection!
<?php
/*
* genurl.php
*
* Copyright 2010-11 Sayan "Riju" Chakrabarti <me@sayanriju.co.cc>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
@sayanriju
sayanriju / remuco-gmusicbrowser.py
Created November 27, 2010 06:26
Remuco Player Adapter for Gmusicbrowser
#!/usr/bin/python
# =============================================================================
#
# Remuco - A remote control system for media players.
# Copyright (C) 2006-2010 by the Remuco team, see AUTHORS.
#
# This file is part of Remuco.
#
# Remuco is free software: you can redistribute it and/or modify