Skip to content

Instantly share code, notes, and snippets.

(defn pick-a-door [doors]
(nth doors (rand-int (count doors))))
(defn play-the-game [strategy]
(let [*doors* '(1 2 3)
*winning-door* (pick-a-door *doors*) ; Computer picks one door to be a winner
*chosen-door* (pick-a-door *doors*) ; player picks a door
*remaining-doors* (filter (fn [value]
(or (= value *winning-door*)
(= value *chosen-door*))) *doors*)] ; Of the remaining doors, remove one that is not good
@drocamor
drocamor / cronicd.sh
Created October 15, 2010 16:01
run some jobs once a day, at 4:20
#!/bin/bash
# cronicd - run some jobs once a day, at 4:20
# Sleep every minute until it is 4:20
while true; do
if [ `date +%H:%M` eq '16:20' ]; then # Military time bro
# Run the jobs s l o w l y
cat /etc/cronicdtab | while read job; do
nice -n 19 $job
@drocamor
drocamor / color-theme-drr.el
Created December 14, 2010 14:13
My Emacs color theme
;;; David Rocamora's emacs color theme.
;;; Colors stolen from Puredyne
;;; Based on a Tango theme created by danranx@gmail.com
(defun color-theme-drr ()
"David Rocamora's Emacs color theme."
(interactive)
(color-theme-install
'(color-theme-drr
((background-color . "#262626")
@drocamor
drocamor / sort_renders.sh
Created January 5, 2011 17:53
To help sort out your multipass renders!
#!/bin/bash
# sort_renders.sh - Sorts multipass renders in a given directory
# usage: sort_renders.sh [directory]
## Here are some things to customize:
# Populate this with a list of all the pass names seperated by spaces
PASSNAMES="foo bar baz quux _ao"
@drocamor
drocamor / Enabling gnupg-agent for SSH authentication.sh
Created March 20, 2011 22:18
Exporting the public part of your PGP authentication subkey
# I took this from here: http://www.programmierecke.net/howto/gpg-ssh.html
# Deactivate the gnome-keyring. We will be replacing it with gnupg-agent
gconftool-2 --type bool --set /apps/gnome-keyring/daemon-components/ssh false
# Configure gpg to use the agent
echo "use-agent" >> ~/.gnupg/gpg.conf
# Enable ssh-agent drop in replacement support for gpg-agent
echo "enable-ssh-support" >> ~/.gnupg/gpg-agent.conf
@drocamor
drocamor / ec2-quick-describe-instances.py
Created April 20, 2011 17:08
Greatly simplified view of what EC2 instances are in your account. Faster than running ec2-describe-instances on my laptop (which sucks at running Java).
#!/usr/bin/env python
import boto
# Connect to EC2. Picks up environment variables
conn = boto.connect_ec2()
# Get a list of my instances
reservations = conn.get_all_instances()
for reservation in reservations:
for instance in reservation.instances:
@drocamor
drocamor / blog.sh
Created December 15, 2011 02:05
My blog updater script
#! /bin/bash
# Customize these
jekyll_root=~/Documents/Personal/n22t
remote_site_root="drocamor@n22t.com:sites/n22t.com"
publish()
{
@drocamor
drocamor / gist:2595645
Created May 4, 2012 15:46
w3 super duper caching htaccess
# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
@drocamor
drocamor / shuffler.clj
Created June 24, 2012 20:09
Clojure deck shuffling
(ns shuffler.core)
(defn shuffle-a-deck []
"""Shuffles one deck of cards"""
(clojure.string/join "," (shuffle (range 0 52))))
;; this is an infinite number of shuffled decks of cards
(def shuffled-decks (repeatedly shuffle-a-deck))
(defn find-a-dup [seq index]
"""Finds the first duplicate in a seq"""
@drocamor
drocamor / json-beautifier.sh
Created February 22, 2013 15:13
Uses Python to clean up JSON
#!/bin/bash
TMPFILE=`mktemp /tmp/prettyjson.XXXXXX` || exit 1
python -mjson.tool $1 > $TMPFILE || exit 1
mv $TMPFILE $1 || exit 1