Skip to content

Instantly share code, notes, and snippets.

View jcromartie's full-sized avatar

John Cromartie jcromartie

View GitHub Profile
@jcromartie
jcromartie / entropy.sh
Created May 1, 2012 21:14
simple entropy calculator for files/stdin
#!/bin/bash
# Uses gzip to calculate crude entropy of a file or stdin
#
# usage:
#
# entropy [file]
#
# probably downloaded from https://gist.github.com/2571452
@jcromartie
jcromartie / pre-commit
Created May 25, 2011 14:40
Git pre-commit hook to help stay up-to-date with master
#!/usr/bin/env bash
# hook to enforce that current branch is up-to-date with latest
# changes from master before committing
# put me in .git/hooks and make me executable
# the output of rev-list in the following test will be empty if there
# are no commits in master that aren't in the current branch
@jcromartie
jcromartie / arcc.clj
Created October 31, 2012 14:57
arc challenge in Clojure
(ns arc.core
(:use compojure.core)
(:require [compojure.route :as route]
[compojure.handler :as handler]
[ring.util.response :as response]
[ring.adapter.jetty :as jetty]))
(def route-map (ref {}))
(def ^:dynamic *params* nil)
@jcromartie
jcromartie / index.html
Created June 4, 2012 15:51 — forked from benjchristensen/index.html
Dynamic Stacked Bar Chart using d3.js
<html>
<head>
<title>Dynamic Stacked Bar Chart using d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
rect.a {
fill: green;
}
rect.b {
fill: orange;
@jcromartie
jcromartie / classpath.sh
Created November 6, 2009 02:47
classpath.sh -- build classpaths
#/bin/bash
# strings together all of its arguments into a Java classpath, useful for
# grabbing all of the jars in a directory like so:
# classpath.sh lib/*.jar
#
DELIM=
CLASSPATH=
for PATH_PART in "$@"
do
@jcromartie
jcromartie / pre-commit
Created June 6, 2017 16:40
pre-commit hook which fails when untracked files are present in working tree
#!/bin/sh
untrackedFiles=$(git ls-files --others --exclude-standard)
if [ ! -z "$untrackedFiles" ]
then
echo "There are untracked files in the working tree:"
echo "$untrackedFiles"
echo ""
echo "Are you sure you aren't forgetting something?"
@jcromartie
jcromartie / spark.rb
Created November 15, 2011 13:37
Sparklines in Ruby
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# prints a sparkline in the terminal using the supplied list of numbers
# examples:
# spark.rb 10 20 30 100 90 80
# spark.rb 1 2 0.4 0.1 1.3 0.7
@ticks = %w[▁ ▂ ▃ ▄ ▅ ▆ ▇]
values = ARGV.map { |x| x.to_f }
@jcromartie
jcromartie / markdown.clj
Created August 17, 2011 16:27
Markdown
(ns util.markdown
(import (java.io
BufferedReader
InputStreamReader)))
(defn markdown
[s]
(let [builder (java.lang.ProcessBuilder. ["Markdown.pl"])
proc (.start builder)
stdin (.getOutputStream proc)
(defn add-component
[system entity component data]
(-> system
(update-in [:identity entity] (comp set conj) component)
(assoc-in [component entity] data)))
(defn delete-component
[system entity component]
(-> system
(update-in [:identity entity] disj component)
- (NSIndexPath *)nextIndexPath:(NSIndexPath *)i
{
// apologies to any maintainer but this was some code golf going on in #iphonedev
id t=_tableView;
int s,r,n;s=i.section;r=(i.row+1)%[t numberOfRowsInSection:s];n=[t numberOfSections];
if(!r)for(;s<n&&![t numberOfRowsInSection:s+++1];);
return s==n?nil:[NSIndexPath indexPathForRow:r inSection:s];
}