Skip to content

Instantly share code, notes, and snippets.

View camsaul's full-sized avatar
💭
I am Cam

Cam Saul camsaul

💭
I am Cam
View GitHub Profile
@camsaul
camsaul / init_ramdisk.sh
Created September 24, 2014 20:13
Mount a Ramdisk in OS X
#! /bin/bash
diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://16951708` # max size ~= 8.68 GB (how ?)
@camsaul
camsaul / postgres_db_dump.sh
Created September 25, 2014 19:09
Make a Postgres DB Dump
#!/bin/bash
pg_dump --clean --create --file db.out --format p --verbose --host $DBHOST --port $DBPORT -U $DBUSER $DBNAME
@camsaul
camsaul / load_pg_dump.sh
Last active August 29, 2015 14:06
Load a Postgres DB Dump
psql -d $DBNAME --host $DBHOST --port $DBPORT -U $DBUSER -f db.out
@camsaul
camsaul / gist:84911afe1fa20c573cac
Created September 30, 2014 19:19
Git ignore changes made to a file
git update-index --assume-unchanged my.file
@camsaul
camsaul / replace.sh
Created October 3, 2014 23:13
Perl replace one-liner
TABLE="DROP TABLE public.timeseries_metriccomment;"
echo $TABLE | perl -ne 's/(^DROP TABLE.*);/$1 CASCADE;/, print'
# -> DROP TABLE public.timeseries_metriccomment CASCADE;
@camsaul
camsaul / select_tables_by_name.psql
Created October 3, 2014 23:16
Postgres select tables by name
SELECT table_name
FROM information_schema.tables
WHERE table_name LIKE 'prefix_%';
@camsaul
camsaul / finder_enable_hidden.sh
Created October 23, 2014 08:38
OS X finder to show hidden files
#!/bin/bash
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
@camsaul
camsaul / file_modifed_date.sh
Created October 23, 2014 08:39
Bash function to get the date a file is modified, works for BSD or Linux
#!/bin/bash
# return unix timestamp for file or 0 if it doesn't exist
[ `uname` == "Darwin" ] && STAT_FORMAT_FLAG='-f' || STAT_FORMAT_FLAG='-c'
file_modified () {
file=$1
if [ -f "$file" ] && [ -n "$file" ]; then # make sure filename is non-empty, -f will return true otherwise
echo `stat $STAT_FORMAT_FLAG "%a" $file`
else
echo "0";
fi
@camsaul
camsaul / filter_docker_logs.sh
Created February 25, 2015 00:57
Filtered Docker Logs
docker attach expa_data | perl -ne 'if (!m/^\s*$/ && !m/stdout/) { s/^\[[^\]]+\]\s*(.*$)/$1/m; print; }'
@camsaul
camsaul / git_ssh.sh
Created April 24, 2015 18:17
Setting Up Git SSH Access
pbcopy < ~/.ssh/id_rsa.pub
git remote set-url origin git@github.com:cammsaul/lein-instant-cheatsheet.git