Skip to content

Instantly share code, notes, and snippets.

View wjlafrance's full-sized avatar
🐶
Wondering if Github is becoming a social network.

William LaFrance wjlafrance

🐶
Wondering if Github is becoming a social network.
View GitHub Profile
class CreateBookmarksAndUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :username
t.string :password
t.string :email_address
t.timestamps
end
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
printf("i have %i args\n",argc);
int i;
for (i = 0; i < argc; i++) {
if (i != argc - 1)
memset(argv[i] + strlen(argv[i]), ' ', 1);
@wjlafrance
wjlafrance / gist:1552132
Created January 2, 2012 21:08
Card shuffle
/*
*
* Your tasks are to:
* - Create a data representation for the cards (this may require some form of
* data structure and suitable constant definitions).
* - Create a data representation to keep track of the positions of the cards in
* the deck.
* - Implement procedures for cutting and shuffling the deck. Each operation
* (cut and merge) should include a random perturbation:
* - The initial cut might deviate from a perfect cut in half by, say, one to
(defn pfilter [pred coll]
"perform filter in parallel"
(map second
(filter first
(pmap (fn [item] [(pred item) item]) coll)
)
)
)
(defn is-divisible [x y]
require "inline"
class Time
inline(:C) do |builder|
# c_singleton creates class method
builder.c_singleton "long epoch_sec() { return time(NULL); }"
end
end
require 'benchmark'
// Java sorts numbers before letters, so if one is a letter and one is a number,
// flip their sort ordering
if (Character.isDigit(ourName.charAt(0)) ^ Character.isDigit(theirName.charAt(0)))
return ourName.compareTo(theirName) * -1;
5.times.each do |i|
puts i
next
puts "please don't see this"
end
// fast-fail boolean checking makes me do horrible things
var valid = true;
valid = validate_username(form.txtUsername) && valid;
valid = validate_email(form.txtEmail) && valid;
valid = validate_phone(form.txtPhone) && valid;
valid = validate_address(form.txtAddress) && valid;
valid = validate_city(form.txtCity) && valid;
valid = validate_state(form.optState) && valid;
valid = validate_zip(form.txtZip) && valid;
valid = validate_gender(form.radGender) && valid;
#! /bin/bash
git checkout -b $1 && mv $3 /tmp/superdiffr1-$3
git checkout -b $2 && mv $3 /tmp/supprdiffr2-$3
git checkout HEAD
opendiff /tmp/superdiffr1-$3 /tmp/supprdiffr2-$3
@wjlafrance
wjlafrance / gist:1886309
Created February 22, 2012 17:55
Reading RECT from SWF file
/* read signed bit */
/* flush = YES to clear remaining bits */
uint8 readSB(FILE *file, BOOL flush)
{
static uint8 bits = 0;
static uint8 bitpos = 8;
if (bitpos > 7) {
bits = readUI8(file);
bitpos = 0;