Skip to content

Instantly share code, notes, and snippets.

@rishabhmhjn
rishabhmhjn / calcStandardDeviation.js
Created November 14, 2013 04:08
Standard Deviation Calculator
function calcStandardDeviation(arr) {
// var arr = [23, 37, 45, 49, 56, 63, 63, 70, 72, 82];
var count = arr.length
var mean = arr.reduce(function(total, num) {
total += num;
return total;
}, 0) / count;
var variance = arr.reduce(function(total, num) {
HTTP Verb   Path              Controller#Action   Used for
GET         /photos           photos#index        display a list of all photos
GET         /photos/new       photos#new          return an HTML form for creating a new photo
POST        /photos           photos#create       create a new photo
GET         /photos/:id       photos#show         display a specific photo
GET         /photos/:id/edit  photos#edit         return an HTML form for editing a photo
PATCH/PUT   /photos/:id       photos#update       update a specific photo
DELETE /photos/:id photos#destroy delete a specific photo
@rishabhmhjn
rishabhmhjn / gist:6137456
Created August 2, 2013 04:17
Ruby on rails installation manual
# Getting started with Ruby
# http://guides.rubyonrails.org/getting_started.html
# Install ruby
curl -L https://get.rvm.io | bash -s stable --ruby
# Install ruby 1.8.7, since rvm installs 1.8.7 as default
rvm install 1.9.3
rvm --default use 1.9.3
var ItemModel = Backbone.Model.extend({
defaults : {
"item_id" : 0,
"item_content" : "this is a content"
}
});
var ItemColl = Backbone.Collection.extend({
@rishabhmhjn
rishabhmhjn / redis-pool.js
Created June 11, 2013 04:20
Implementation of Redis connection pooling
var redisConfig = {
"host" : "localhost",
"port" : "6379",
"maxConnections" : 10,
"minConnections" : 5,
"debug" : true
}
var redis = require("redis");
@rishabhmhjn
rishabhmhjn / node_install_with_nvm.sh
Last active December 18, 2015 04:39
Install nodejs using nvm
vi ~/.bashrc
# [add the following]
# -------------------------------------------------------------
. ~/.nvm/nvm.sh && nvm use default
# -------------------------------------------------------------
mkdir ~/src
cd !$
@rishabhmhjn
rishabhmhjn / JS.inheritance.js
Created May 31, 2013 06:57
Javascript inheritance
var Person = function () {
this.fname = 'douglas';
this.lname = 'crockford';
};
var Student = function() {
return this;
};
Student.prototype = new Person();
@rishabhmhjn
rishabhmhjn / Array.myLast.js
Last active December 17, 2015 17:58
Encapsulating Array Object to add a custom method
var MyArray = function() { return this; } ;
MyArray.prototype = new Array();
MyArray.prototype.constructor = MyArray; // http://stackoverflow.com/a/10430875/842214
Object.defineProperty(MyArray.prototype, 'myLast', (function () {
return {
configurable : true,
enumerable : true,
get : function () {
return this[this.length - 1];
@rishabhmhjn
rishabhmhjn / ssh.config
Created December 16, 2015 04:57
SSH remote login via app-nat to app-remote
Host app-nat
Hostname app-nat.example.com
User app-nat-user
IdentityFile ~/.ssh/app-nat-id_rsa
Host app-remote
ProxyCommand ssh -q app-nat nc app-remote.example.com 22
User app-remote-user
IdentityFile ~/.ssh/app-remote-id_rsa
@rishabhmhjn
rishabhmhjn / TwttrMaxlengthDirective.js
Last active December 15, 2015 07:12
An extension to md-maxlength from Angular Material (https://material.angularjs.org/latest/api/directive/mdInput) to calculate a tweet's length using the twitter-text-js library. Demo http://plnkr.co/edit/UC0aHq?p=preview
(function() {
// angular.module('TwttrMaxlengthDirectiveDemo', ['ngMaterial'])
// .constant('twttr', twttr) // https://github.com/twitter/twitter-text/tree/master/js
// .directive('twttrMaxlength', TwttrMaxlengthDirective);
TwttrMaxlengthDirective.$inject = ['$animate', 'twttr'];
function TwttrMaxlengthDirective($animate, twttr) {
return {