Skip to content

Instantly share code, notes, and snippets.

@drocamor
drocamor / keybase.md
Last active January 31, 2017 22:49
keybase.md

Keybase proof

I hereby claim:

  • I am drocamor on github.
  • I am drocamor (https://keybase.io/drocamor) on keybase.
  • I have a public key ASAeaNEjXiG_J2c8hv_9BPvEFmZS42ml7b4HRu0Cl9Vc9go

To claim this, I am signing this object:

@drocamor
drocamor / coreos.json
Created August 27, 2013 13:20
Simple CoreOS CloudFormation template. Launches, but etcd doesn't seem to work right.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Simple CoreOS install",
"Parameters": {
"GistURL": {
"Description": "URL to a github gist with your public key",
"Type": "String"
},
"KeyName": {
"Description": "EC2 keypair name",
@drocamor
drocamor / networks.clj
Created July 1, 2013 15:18
I want to use core.logic to help me find out if an IP is inside of a network. core.logic doesn't have bitwise operations in it now, so I tried to rig one up my self. The code is tedious and runs pretty slowly, but it is sort of neat to see it start to work.
(ns networks.core
(:refer-clojure :exclude [==])
(:use [clojure.core.logic])
(:require [clojure.core.logic.fd :as fd]))
(defn bit-ando
"Ensure that r is a bitwise AND of x and y."
[x y r]
(conde
[(== 0 x) (== 0 y) (== 0 r)]
@drocamor
drocamor / timezoning.py
Last active December 17, 2015 12:19
This gets the timezone for a given latitude/longitude pair. Not efficient.
#!/usr/bin/env python
import shapefile
# Get the shapefile from here: http://efele.net/maps/tz/world/
sf = shapefile.Reader("/Users/drocamor/Downloads/world/tz_world.shp")
# I took this from here: http://geospatialpython.com/2011/08/point-in-polygon-2-on-line.html
# Improved point in polygon test which includes edge
# and vertex points
@drocamor
drocamor / pre-commit.sh
Created April 23, 2013 16:21
A pre-commit git hook that will make sure CloudFormation templates have had their JSON cleaned up. Really helps with merging and diffing of CloudFormation templates.
#!/bin/bash
#
# git pre-commit hook to make sure you are commiting properly formatted CloudFormation code
# This should go in .git/hooks/pre-commit in a repo with CFN templates.
if git-rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
@drocamor
drocamor / gist:5213443
Created March 21, 2013 14:29
A function to use json.tool to beautify JSON.
;; beautify json
(defun beautify-json ()
(interactive)
(let ((b (if mark-active (min (point) (mark)) (point-min)))
(e (if mark-active (max (point) (mark)) (point-max))))
(shell-command-on-region b e
"python -mjson.tool" (current-buffer) t)))
@drocamor
drocamor / iterated-prisoners-dilemma.py
Created February 25, 2013 03:59
Thinking about the prisoners dilemma with iPython. This is an iPython notebook. I made it python to share it with people.
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <headingcell level=1>
# The Game World
# <codecell>
@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
@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 / 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