Skip to content

Instantly share code, notes, and snippets.

Avatar
👾
Building.

Mitchell Hashimoto mitchellh

👾
Building.
View GitHub Profile
View gist:60088
int lastEmptyString(char **strings, int n) {
if (n == 0) return -1;
if (!strcmp(strings[0], "")) return 0;
return 1 + lastEmptyString(strings + 1, n - 1);
}
View lowest alpha string in array.c
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;
}
View gist:60130
// 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;
}
View STI and nested model forms
# 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
View gist:178369
Book.find_in_batches(:batch_size => 100) do |results|
# Do something with results
end
View gist:190859
-- 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"
View gist:194018
-- 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')
View Mu + Facebooker
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'
};
View gist:280295
#!/bin/bash
CLASSPATH=something.jar
for f in lib/*.jar; do
CLASSPATH=$CLASSPATH:$f
done
# Debugging: echo $CLASSPATH
rlwrap java -cp $CLASSPATH clojure.main
View VirtualBox 3.1 => 3.2 API Changes
948a949
> struct INATEngine;
997a999
> typedef struct INATEngine INATEngine;
1019c1021,1022
< SettingsVersion_Future = 12
---
> SettingsVersion_v1_10 = 12,
> SettingsVersion_Future = 13
1039c1042