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 / implementation_comparitor.clj
Last active December 17, 2015 04:33
function that returns function to compare performance of 2 different implementations
(defn implementation-comparitor [f1 f2]
(let [f1-runtime (atom 0)
f2-runtime (atom 0)
performance-ratios (atom [])]
(fn [& args]
(let [f1-start (System/nanoTime)
_ (apply f1 args)
f1-time (- (System/nanoTime) f1-start)
f2-start (System/nanoTime)
return (apply f2 args)
@camsaul
camsaul / which-process-is-listen-on-port.sh
Created January 25, 2016 21:57
Figure out which process is listening to a given TCP port
lsof -i tcp:8090 | grep LISTEN
@camsaul
camsaul / squash-git-commits.sh
Created February 6, 2016 00:43
Squash several Git commits into a single commit
# Switch to the master branch and make sure you are up to date.
git checkout master
git fetch # this may be necessary (depending on your git config) to receive updates on origin/master
git pull
# Merge the feature branch into the master branch.
git merge feature_branch
# Reset the master branch to origin's state.
git reset origin/master
@camsaul
camsaul / hello_world.asm
Last active December 10, 2024 00:52
Hello World in NES (6502 / NESASM) Assembly. Display a single sprite
;;; -*- tab-width: 2 -*-
;;; These four lines go at the beginning of almost every code file. 16-byte iNES header
.inesprg 1 ; one bank of program code
.ineschr 1 ; one bank of picture data
.inesmap 0 ; we use mapper 0
.inesmir 1 ; Mirror setting always 1
;;; BANKING
@camsaul
camsaul / git-undo.sh
Created April 9, 2016 01:33
Undo last git commit
brew install git-extras
git undo
@camsaul
camsaul / killing_processes.sh
Created June 22, 2016 22:44
Killing process locking a file
# list process that owns a file
lsof | grep myfile
# kill all java processes
killall -9 java
@camsaul
camsaul / fake-smtp.sh
Created July 13, 2016 22:19
Run local fake SMTP server for debugging
#!/bin/bash
sudo python -m smtpd -n -c DebuggingServer localhost:25
@camsaul
camsaul / kill_pg_connections.sql
Created August 5, 2016 19:45
Terminate all other connections to Postgres DB
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '<db-name>'
AND pid <> pg_backend_pid();
@camsaul
camsaul / .bash_profile
Last active May 9, 2018 02:41
.bash_profile
alias ls='ls -AFGh'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias emacs=/Applications/Emacs.app/Contents/MacOS/Emacs
PATH=$PATH:/usr/local/bin
PATH=$PATH:~/scripts
PATH=/usr/local/opt/ruby/bin:$PATH
PATH=/usr/local/Cellar/perl/5.20.1/bin/:$PATH
PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH
@camsaul
camsaul / git_cleanup.sh
Created January 4, 2017 21:08
Cleanup old branches in local git repo
#! /bin/bash
# Switch back to master
git checkout master
# Delete all local branches besides master
for branch in `git branch | grep -v 'master'`
do
git branch -D $branch
done