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 / make_db_ssh_tunnel.sh
Created September 24, 2014 20:16
Make a SSH Tunnel to a Postgres DB hosted in Vagrant VM
#! /bin/bash
ssh -L 5555:localhost:5432 vagrant@localhost -p 2222 -i ~/.vagrant.d/insecure_private_key -fNg # local port 5555 <-> Vagrant port 5432
@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 / colors.sh
Last active October 29, 2022 11:48
bash colors
# Use \033 if you need OS X compatibility
# e.g. RED='\033[0;31m' && echo -e ${RED}"My red text"...
# Reset
Color_Off='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
@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