This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias git_clean_branches="git branch | grep -v \"master\" | grep -v \"staging\" | xargs git branch -D" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/julienschmidt/httprouter" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/julienschmidt/httprouter" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"net/http/httptest" | |
"testing" | |
"github.com/julienschmidt/httprouter" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
"time" | |
"github.com/julienschmidt/httprouter" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io" | |
"io/ioutil" | |
"net/http" | |
"github.com/julienschmidt/httprouter" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer