Skip to content

Instantly share code, notes, and snippets.

View hrwgc's full-sized avatar

Chris Herwig hrwgc

  • Google
  • San Francisco
View GitHub Profile
@hrwgc
hrwgc / 1_how_to_fix.md
Last active December 29, 2015 11:19
postgres / postgis randomly stops working on osx mavericks - fix

Following advice of Psql: could not connect...:

Running the following command resets PostgreSQL's transaction log, which resolves the problem.

 pg_resetxlog -f /usr/local/Cellar/postgresql/9.3.1/data

you should replace /usr/local/Cellar/postgresql/9.3.1/data with your own pg_datadir (eg., pg_ctl -D $DATADIR start)

perf guide

Profiling tools are critical for trying to understand performance bottlenecks in code.

Without real data about what a program is doing while running, detecting bottlenecks is at best a process of trial and error for both users and developers. While thoughtful testing of various program configurations along with measuring time elapsed for decrete runs can often be enough - why not learn faster and funner ways to rapidly collect real data about what a program is doing?

Actual data about program execution like which functions are being called while a program is active helps point to hot parts of the code where most time may be being spent. While users of applications may not easily understand the output of profiling tools, being equipped to generate profiling output can be extremely useful for sharing with developers, since the time to set up robust test cases for developers is can be greater than the time it takes to understand and optimize slow code paths. Therefore it can be invaluable to get

@hrwgc
hrwgc / xml2json.js
Created September 17, 2014 18:28
convert xml to json nodejs command line utility
#!/usr/bin/env node
var parser = require('xml2json');
var fs = require('fs');
function onFile(err, data) {
if (err) {
console.log('Uh oh: ' + err);
return;
}
var json = parser.toJson(data);
@hrwgc
hrwgc / aws-cli-s3cmd-du.sh
Last active June 19, 2023 15:32
aws-cli get total size of all objects within s3 prefix. (mimic behavior of `s3cmd du` with aws-cli)
#!/bin/bash
function s3du(){
bucket=`cut -d/ -f3 <<< $1`
prefix=`awk -F/ '{for (i=4; i<NF; i++) printf $i"/"; print $NF}' <<< $1`
aws s3api list-objects --bucket $bucket --prefix=$prefix --output json --query '[sum(Contents[].Size), length(Contents[])]' | jq '. |{ size:.[0],num_objects: .[1]}'
}
s3du $1;
@hrwgc
hrwgc / mercantile-tiles-from-geojson.sh
Last active August 29, 2015 14:11
mercantile find web mercator tiles for a given zoom level based on geojson feature collection
#!/bin/bash
function to_tiles(){
geojson=$1;
zoom=$2;
jq -c .features[] < "$geojson" | mercantile tiles $zoom | sort | uniq
}