Skip to content

Instantly share code, notes, and snippets.

View sayanriju's full-sized avatar

Sayan "Riju" Chakrabarti sayanriju

View GitHub Profile
testing
testing
#!/bin/sh
# This script was written by Abhi Datt.
# This is the script is the result of joint effort of Abhi Datt
# Copyright (C) 2009 Abhi Datt
#!/usr/bin/env bash
if [ $# -ne 2 ];then
echo -n "Usage: $0 directory_name timeout_in_seconds
Leave the directory name blank for Current Directory
For you lazy pal, I assume timeout as 5 sec and Directory as current
Do you want to accept this settings? (Y/n): ";
read response
if [[ "$response" =~ ^[^yY] ]];then
exit 0
@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
@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 <[email protected]>
*
* 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 / 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 / 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 / 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 / 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 / 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