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 / git-undo.sh
Created April 9, 2016 01:33
Undo last git commit
brew install git-extras
git undo
@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 / 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 / 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 / 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 / project-authors.pl
Created December 15, 2015 18:00
Perl script to deduce the primary authors of a git project
#! /usr/bin/perl # -*- coding: utf-8 -*-
use strict;
use warnings;
use List::Util qw(reduce);
my %author_aliases = ('Cameron T Saul' => 'Cam',
'Cam Saul' => 'Cam Saül',
'Cam Saül' => 'Cam Saül'); # different umlauts, apparently
@camsaul
camsaul / generate_sudoku.clj
Created November 13, 2015 23:59
Core.logic Sudoku Generator
(defn- solve-board [hints & {:keys [max-solutions], :or {max-solutions 1}}]
(let [vars (vec (repeatedly 81 lvar))
rows (mapv vec (partition 9 vars))
cols (apply map vector rows)
squares (for [corner-x (range 0 9 3)
corner-y (range 0 9 3)]
(for [x (range corner-x (+ corner-x 3))
y (range corner-y (+ corner-y 3))]
(get-in rows [x y])))]
(run max-solutions [q]
@camsaul
camsaul / all_of_the_imessages.sh
Created September 23, 2015 21:49
Send an annoying amount of iMessages
#! /bin/bash
NUM_SECONDS_DELAY=1
while "TRUE"; do
osascript -e 'tell application "Messages" to send "YO!" to buddy "+14151234567" of service "E:[email protected]"'
sleep $NUM_SECONDS_DELAY
done
@camsaul
camsaul / https.sh
Last active August 30, 2015 02:43
Self-Signed HTTPS
#!/bin/bash
# PEM files are Base-64 format starting with -----BEGIN. Extensions: .pem, .crt, .cer, .key
# DER files are binary versions. Extensions: .der, .cer
# Keystores:
# PKSC7/P7B - Base64. Extensions: .p7b, .p7c
# PKCS12/PFX - Binary. Extensions: .pfx, .p12
# Generate a new private key
openssl genrsa -out private.pem 2048
@camsaul
camsaul / .git_submodules.sh
Created August 18, 2015 21:04
Setup Git Submodules To Auto-Pull
git submodule update --init
git config --add fetch.recurseSubmodules true
git config alias.pull '!f(){ git pull "$@" && git submodule update --init --recursive; }; f'