Skip to content

Instantly share code, notes, and snippets.

View detj's full-sized avatar
🖥️
deep into work

Debjeet Biswas detj

🖥️
deep into work
View GitHub Profile
@detj
detj / deferred-returns.js
Last active July 4, 2016 08:07
Deferred returns inside try/finally blocks
/**
* Return inside try/finally
*/
// THIS IS JUST A TEST CASE
// AVOID USING SUCH CONSTRUCTS IN PRODUCTION CODE
// foo is either 0 or 1
var foo = Math.round(Math.random() * 10) % 2;
@detj
detj / deploy.sh
Last active August 29, 2015 13:55
Deployment script. Installs latest nodejs and mongodb
#!/bin/bash
#Set up a fresh system
#NODE_VERSION="0.10.31"
#MONGO_VERSION="2.6.4"
ENVIRONMENT="production"
#Set up a base tmp directory for installation
mkdir -p ~/tmp
@detj
detj / upstart.sh
Created January 19, 2014 21:39
Upstart script for node.js apps
#example upstart script
description "Example upstart script"
author "detj"
# Environment variables
env LOG_FILE=/home/debjeet/test.log
env NODE_ENV="production"
start on filesystem or runlevel [2345]
stop on runlevel [016]
description "Upstart script to run a nodejs app as a service"
author "Louis Chatriot"
env NODE_BIN=/usr/local/bin/node
env APP_DIR=/path/to/app/dir
env SCRIPT_FILE="scriptfile.js" # Entry point for the nodejs app
env LOG_FILE=/path/to/logfile.log
env RUN_AS="anyuser" # Upstart can only be run nicely as root, need to drop privileges
env SERVER_ENV="anything" # Usual apps can be run in different environments (development, test, production ...)
# I typically use the environment variable NODE_ENV (see below)
@detj
detj / one-line-passwd.js
Last active January 3, 2016 08:09
Generate password
(function() { var i = 0;var arr = [];while(i < 16) { arr.push('abcdefghjkmnpqrstuvwyzABCDEFGHJKLMNPQRSTUVWXYZ123456789#$%&*~'[Math.floor(Math.random() * 61)]); ++i; } console.log(arr.join('')); })();
@detj
detj / createKey.js
Created December 26, 2013 21:59
Simple function to create API keys consisting of only lower case, upper case alphabets and numbers
function createKey(len) {
var out = [], rand;
len = len || 20;
while(len > 0) {
rand = Math.round(Math.random() * 123);
if ((rand > 47 && rand < 58) || (rand > 64 && rand < 91) || (rand > 96 && rand < 123)) {
out.push(rand);
len--;
}
}
@detj
detj / parse-youtube.js
Created November 21, 2013 13:31
Parse youtube urls
var foo = document.querySelectorAll('a');
foo.map(function(i, v) {
var m = v.getAttribute('href');
var c = m && m.match(/(?:watch\?v=([-_a-zA-Z0-9]+))/);
return c && c[1];
});
@detj
detj / install-phantom.sh
Created October 11, 2013 17:33
Install PhantomJS on Ubuntu 12.04 LTS x64
#!/bin/sh
wget https://phantomjs.googlecode.com/files/phantomjs-1.9.0-linux-x86_64.tar.bz2
tar xjf phantomjs-1.9.0-linux-i686.tar.bz2
sudo ln -s /usr/local/share/phantomjs-1.9.0-linux-x8664/bin/phantomjs /usr/local/share/phantomjs; sudo ln -s /usr/local/share/phantomjs-1.9.0-linux-x8664/bin/phantomjs /usr/local/bin/phantomjs; sudo ln -s /usr/local/share/phantomjs-1.9.0-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
@detj
detj / awscli.sh
Last active December 24, 2015 15:59
Install aws cli tools.Tests if comamnds are available. If not echo error
#!/bin/bash
# Make executable
chmod +x $0;
###########
# Helpers #
###########
# test availability of the command
@detj
detj / github-issue-list.js
Created October 1, 2013 20:20
Run this snippet in your console on a github issues to get a list in this format #<issue-no> - <issue-title>
(function() {
var text = [];
$('.list-group .list-group-item').each(function(index, listGroupItem) {
text.push($(listGroupItem).find('.list-group-item-number').text() + ' - ' + $(listGroupItem).find('.list-group-item-name .js-navigation-open').text());
});
console.log(text.join("\n"));
})();