Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View josephwecker's full-sized avatar

Joseph Wecker josephwecker

View GitHub Profile
@josephwecker
josephwecker / pgstore.rb
Created March 28, 2018 23:24 — forked from noteflakes/pgstore.rb
A lightweight PostgreSQL ORM using JSONB. Provides an API for retreiving documents by arbitrary key, and performing queries on arbitrary keys and sub-keys.
require 'pg'
PGDB = PG.connect(host: '/tmp', dbname: 'mydb')
PGDB.type_map_for_results = PG::BasicTypeMapForResults.new(PGDB)
class Hash
def symbolize_keys
inject({}) { |m, kv| v = kv[1];
m[kv[0].to_sym] = v.is_a?(Hash) ? v.symbolize_keys : v; m }
end
end
@josephwecker
josephwecker / gist:8105846
Created December 23, 2013 22:23
Slightly more robust "current directory" for bash script if ruby is already a dependency
#!/bin/bash
D=`ruby -e 'puts File.dirname(File.realpath(File.expand_path("'${BASH_SOURCE[0]}'")))'`
pushd "${D}" >/dev/null
# ... Do stuff ...
popd >/dev/null
@josephwecker
josephwecker / new_bashrc.sh
Created August 11, 2012 04:36
Replace .bashrc, .bash_profile, .profile, etc. with something much more clean, consistent, and meaningful. Now a repo: https://github.com/josephwecker/bashrc_dispatch
#!/bin/bash
# License: Public Domain.
# Author: Joseph Wecker, 2012
#
# -- DEPRICATED --
# This gist is slow and is missing .bashrc_once
# Use the one in the repo instead! https://github.com/josephwecker/bashrc_dispatch
# (Thanks gioele)
#
# Are you tired of trying to remember what .bashrc does vs .bash_profile vs .profile?
@josephwecker
josephwecker / gist:2884332
Created June 6, 2012 19:55
Robustly get script's actual directory (bash)
#!/bin/bash
# Put's the script's directory in the $BS variable.
# Follows symlinks, works on mac-os as well as linux etc.
# Move final popd to the end of your script if you want to run your script with the script's directory as the working directory.
BS="${BASH_SOURCE[0]}";RL="readlink";([[ `uname -s`=='Darwin' ]] || RL="$RL -f")
while([ -h "${BS}" ]) do BS=`$RL "${BS}"`; done
N="/dev/null";pushd .>$N;cd `dirname ${BS}`>$N;BS=`pwd`;popd>$N
# ... rest of the script ... use ${BS} when referring to this script's directory