Skip to content

Instantly share code, notes, and snippets.

@asmedrano
asmedrano / slice_to_args
Created November 29, 2013 17:05
A slice of interfaces to args?
package main
import "fmt"
import "reflect"
func main() {
a := []interface{}{1,3,4,5,"!@"}
dothis(a...)
}
@asmedrano
asmedrano / Comma String to int string
Created November 28, 2013 16:20
Turn a comma delmited string of ints into a slice of actual ints
package main
import "fmt"
import "strings"
import "strconv"
func main() {
fmt.Println("Hello, playground")
s := "1,2,4"
n := commaStringToIntSlice(s)
@asmedrano
asmedrano / morning_routine.sh
Created November 20, 2013 01:49
Same script different day.
#!/bin/bash
firefox google.com </dev/null &>/dev/null &
sleep 3
firefox -new-tab mail.provplan.org </dev/null &>/dev/null
firefox -new-tab toggl.com </dev/null &>/dev/null
google-chrome gmail.com
google-chrome twitter.com
@asmedrano
asmedrano / jsonLoads
Created October 20, 2013 01:31
My simplified version of python's json.loads in Go
func jsonLoads(j string) map[string]interface{} {
sB := []byte(j)
var f interface{}
// At this point the Go value in f would be a map whose keys are strings and whose values are themselves stored as empty interface values:
// If the json is formated wrong, f will be nil :TODO catch that error
json.Unmarshal(sB, &f)
// To access this data we can use a type assertion to access `f`'s underlying map[string]interface{}:
m := f.(map[string]interface{})
return m
@asmedrano
asmedrano / init_env.sh
Created August 29, 2013 22:40
Set Go Env vars
#!/bin/bash
export GOPATH=`pwd`
export PATH=$PATH:$GOPATH/bin
# in order to have the env variables set you need to run this script with 'source' or '.' instead of just 'bash' or './'
@asmedrano
asmedrano / gist:6196275
Created August 9, 2013 19:08
What hour of the year is it?
import datetime
now = datetime.now()
day_of_year = now.timetuple().tm_yday
current_hour_of_day = now.timetuple().tm_hour
hour_of_year = day_of_year * 24 - 24 + current_hour_of_day
@asmedrano
asmedrano / asyncLs
Created August 8, 2013 01:05 — forked from nstadigs/asyncLs
(function(exports) {
var mod = function (databaseName, saveInterval) {
var self;
saveInterval = saveInterval || 2000;
databaseName = databaseName || 'unnamed';
this.hasChanged = false;
this.store = {};
@asmedrano
asmedrano / gist:6065275
Created July 23, 2013 19:14
Installing postgis on ubuntu 13.04
sudo add-apt-repository ppa:ubuntugis
sudo apt-get update
sudo apt-get install postgis postgresql-9.1-postgis
# youll need this /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
# and this /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql
# now create a spatially enabled template db
The first step in creating a PostGIS database is to create a simple PostgreSQL database.
@asmedrano
asmedrano / gist:4708675
Created February 4, 2013 18:49
Get the location of the bash script you are running. Great for making alias..ssss
SCRIPTPATH=$(cd "$(dirname "$0")"; pwd)
echo SCRIPTPATH
@asmedrano
asmedrano / gist:4627261
Last active December 11, 2015 16:19
Simple script to download a list of files with wget
Give a list like so...
Lets call it list.txt
jquery|http://code.jquery.com/jquery-1.8.3.min.js
modernizr|http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js
pydocs|http://docs.python.org/2/archives/python-2.7.3-docs-html.zip
djangodocs|https://www.djangoproject.com/m/docs/django-docs-1.4-en.zip
leaflet|http://cdn.leafletjs.com/leaflet-0.5/leaflet.js
leafletdocs|http://leafletjs.com/reference.html