Skip to content

Instantly share code, notes, and snippets.

View davewalk's full-sized avatar
💭
test

Dave Walk davewalk

💭
test
  • Philadelphia, PA
View GitHub Profile
@davewalk
davewalk / go_projects_april17.md
Created April 11, 2017 00:12
Interesting Go projects that perhaps you'll like (April 2017)
@davewalk
davewalk / profiling.go
Created May 3, 2016 21:14
Spin up a pprof web server and print some RAM stats too
_ "net/http/pprof"
go func() {
for _ = range time.Tick(time.Duration(10) * time.Second) {
fmt.Printf("Number of goroutines: %d\n", runtime.NumGoroutine())
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("heap in use: %v\n", m.HeapInuse)
fmt.Printf("heap alloc: %v\n", m.HeapAlloc)
fmt.Printf("next GC: %v\n", m.NextGC)
@davewalk
davewalk / interface_slice.go
Created April 4, 2016 16:27
Go empty interface value that is actually of type []string to a comma-separated string
package main
import (
"encoding/json"
"fmt"
"reflect"
"strings"
)
type Product struct {
@davewalk
davewalk / custom_unmarshal.go
Created March 4, 2016 18:57
Custom unmarhsaling of JSON example
package main
import (
"encoding/json"
"fmt"
)
type Record struct {
SiteId string `json:"site_id"`
JsonData interface{} `json:"json_data"`
@davewalk
davewalk / gist:69e0bd8fd1b4e0c2db81
Created April 28, 2015 20:55
Save all of the AWS EC2 IP ranges for a given region using jq (more info: http://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html)
cat ip-ranges.json | jq '.prefixes' | jq '.[]' | jq '.service = "EC2"' | jq '.region = "us-east-1"' | jq '.ip_prefix' > ec2-us-east-1-ranges.txt
@davewalk
davewalk / docker bulk container delete
Created March 14, 2015 23:42
Remove old Docker containers in bulk that from "weeks ago". Can obviously be edited to delete on a different string. Originally from https://twitter.com/jpetazzo/status/347431091415703552 via http://stackoverflow.com/questions/17236796/how-to-remove-old-docker-containers
docker ps -a | grep "weeks ago" | awk '{print $1}' | xargs docker rm
@davewalk
davewalk / gist:64a6621db86adc8ebb75
Created October 15, 2014 17:50
Allow access to your stuff from a U.S. IP or a local IP (you know, for a load balancer or something) in Nginx
geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $allowed_country {
default no;
US yes;
}
geo $inNet {
default no;
10.0.0.0/8 yes;
@davewalk
davewalk / gist:5211e7db094cee5082ca
Created September 18, 2014 15:40
mySQL metadata queries
# Get the charset of a table
SELECT CCSA.character_set_name FROM information_schema.`TABLES` T,
information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE CCSA.collation_name = T.table_collation
AND T.table_schema = "schemaname"
AND T.table_name = "tablename";
# Get a bunch of details about a table including its collation
SHOW TABLE STATUS IN dbname like 'tablename'
@davewalk
davewalk / gist:59a438325fca5214f3de
Last active August 29, 2015 14:05
Dumb JS object debugging in NodeJS
var util = require('util'),
fs =require('fs');
// Print a nested object to the console for full inspection
console.log(util.inspect(data, showHidden=false, depth=16, colorize=true));
// Print a thing to a file
fs.writeFile('debug.txt', aThing, function(err) {
if (err) console.log('Write error for some reason!');
});
@davewalk
davewalk / account.cfg
Last active August 29, 2015 14:01
Python standard config module
[login]
password = abc123