Skip to content

Instantly share code, notes, and snippets.

Avatar

Joseph Wecker josephwecker

View GitHub Profile
@josephwecker
josephwecker / pgstore.rb
Created Mar 28, 2018 — forked from ciconia/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.
View pgstore.rb
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 Dec 23, 2013
Slightly more robust "current directory" for bash script if ruby is already a dependency
View gist:8105846
#!/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 Aug 11, 2012
Replace .bashrc, .bash_profile, .profile, etc. with something much more clean, consistent, and meaningful. Now a repo: https://github.com/josephwecker/bashrc_dispatch
View new_bashrc.sh
#!/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 Jun 6, 2012
Robustly get script's actual directory (bash)
View gist:2884332
#!/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