Skip to content

Instantly share code, notes, and snippets.

View mitchellh's full-sized avatar
👻
Building.

Mitchell Hashimoto mitchellh

👻
Building.
View GitHub Profile
### Keybase proof
I hereby claim:
* I am mitchellh on github.
* I am mitchellh (https://keybase.io/mitchellh) on keybase.
* I have a public key whose fingerprint is 6607 CB95 C7C3 E98D F889 98CA 7508 59F2 E481 99B9
To claim this, I am signing this object:
int lastEmptyString(char **strings, int n) {
if (n == 0) return -1;
if (!strcmp(strings[0], "")) return 0;
return 1 + lastEmptyString(strings + 1, n - 1);
}
int lowest_alpha_string(char **strings, int n) {
if (n == 0) return -1;
int next = lowest_alpha_string(strings + 1, n - 1);
if (next == -1 || strings[0] < strings[next])
return 0;
else
return 1 + next;
}
// CODE FOR REFERENCE:
int lowest_alpha_string(char **strings, int n) {
if (n == 0) return -1;
int next = 1 + lowest_alpha_string(strings + 1, n - 1);
if (next == -1 || strings[0] < strings[next])
return 0;
else
return next;
}
# Allow the "type" field to be mass assigned. This is useful
# for, in my case, nested model forms. It IS dangerous but
# with proper form validation on this type field, it should be
# safe.
class Friend < ActiveRecord::Base
# Basic validation of the type field
validates_format_of inheritance_column, :with => /^Friend::([A-Z][a-zA-Z]+)$/
# More validation for the type field to be safe
def validate
Book.find_in_batches(:batch_size => 100) do |results|
# Do something with results
end
-- Startupper
-- By Mitchell Hashimoto
--
-- A startup script tailored for my own personal use
-- to startup all my applications and set their proper
-- size based on the screen dimension (which changes
-- depending on if my laptop is connected to my 24"
-- monitor or not)
set _scriptName to "AppleScript: Startupper"
-- ch14/Logger.hs
type Log = [String]
newtype Logger a = Logger { execLogger :: (a, Log) }
instance Monad Logger where
return a = Logger (a, [])
m >>= k = let (a, s) = execLogger m
mb = k a
(b, s') = execLogger mb
in Logger (b, s ++ s')
FB.Event.subscribe('auth.sessionChange', function(response) {
// The cookies we need to set for Facebooker, and the
// associated key into the Mu session object
var cookies = {
session_key: 'session_key',
user: 'uid',
expires: 'expires',
ss: 'secret'
};
#!/bin/bash
CLASSPATH=something.jar
for f in lib/*.jar; do
CLASSPATH=$CLASSPATH:$f
done
# Debugging: echo $CLASSPATH
rlwrap java -cp $CLASSPATH clojure.main