Skip to content

Instantly share code, notes, and snippets.

View gsingharoy's full-sized avatar

Gaurav Singha Roy gsingharoy

View GitHub Profile
@gsingharoy
gsingharoy / string_date_to_age.js
Created November 10, 2014 09:47
Returns the integer current age from the D.O.B. string which is in format 'YYYY-MM-DD'
//dob is of format 'YYYY<separator>MM<separator>DD'
//eg, to find the age with DOB string 1969-08-02 we need to call the method getAge('1969-08-02','-')
function getAge(dob,separator){
var arr_d = dob.split(separator);
var date_d = new Date(parseInt(arr_d[0]),parseInt(arr_d[1])-1,parseInt(arr_d[2]));//In javaScript month values are from 0-11. So January is 0.
var date_now = Date.now();
var one_year=1000*60*60*24*365; //getting the millisecond in one year
var str_age = ((date_now-date_d)/one_year).toString();
@gsingharoy
gsingharoy / get_long_number_display.js
Created November 14, 2014 10:12
Gets a short description of long numbers with a suffix. eg, 1931200 will become 192.1K
//Gets a short description of long numbers with a suffix. eg, 1931200 will become 192.1K
function get_long_number_display(long_number){
if(long_number/1000000000 > 1)
return (Number((long_number/1000000000).toFixed(1))).toString()+"B"; //in billions
else if(long_number/1000000 > 1)
return (Number((long_number/1000000).toFixed(1))).toString()+"M"; //in millions
else if(long_number/1000 > 1)
return (Number((long_number/1000).toFixed(1))).toString()+"K"; //in thousands
else
return long_number.toString();
@gsingharoy
gsingharoy / git_clean_branches
Created November 11, 2016 06:37
An alias to delete all your local branches in git apart from master and staging
alias git_clean_branches="git branch | grep -v \"master\" | grep -v \"staging\" | xargs git branch -D"
package main
import (
"fmt"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
)
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/julienschmidt/httprouter"
)
package main
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/julienschmidt/httprouter"
)
package main
import (
"log"
"net/http"
"time"
"github.com/julienschmidt/httprouter"
)
package main
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"github.com/julienschmidt/httprouter"
package main
import "github.com/julienschmidt/httprouter"
/*
Define all the routes here.
A new Route entry passed to the routes slice will be automatically
translated to a handler with the NewRouter() function
*/
type Route struct {
package main
import "github.com/julienschmidt/httprouter"
//Reads from the routes slice to translate the values to httprouter.Handle
func NewRouter(routes Routes) *httprouter.Router {
router := httprouter.New()
for _, route := range routes {
var handle httprouter.Handle