This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |