Skip to content

Instantly share code, notes, and snippets.

View tessro's full-sized avatar

Tess Rosania tessro

View GitHub Profile
#!/usr/bin/env ruby
# usage: ./family.rb [trials]
# Family problem, 1000000 trials:
#
# 997496 girls, 1000000 boys
# 1.997496 children per family
# 0.997496 girls per boy
#
# Ran in 15.508096s
#!/usr/bin/env ruby
# http://www.facebook.com/careers/puzzles.php?puzzle_id=7
# Memory-heavy but low-computation solution
LOOP = [nil, nil, "Hoppity", nil, "Hophop", "Hoppity", nil, nil, "Hoppity", "Hophop", nil, "Hoppity", nil, nil, "Hop"]
File.open(ARGV[0], 'r') do |f|
f.readline.to_i.times do |i|
puts LOOP[i] unless LOOP[i].nil?
@tessro
tessro / jquery.selection.js
Created September 18, 2009 15:42
A quick cross-browser jQuery plugin to select the contents of a node.
jQuery.fn.selectAll = function() {
return this.each(function() {
if (document.body.createTextRange) { // MSIE
var r = document.body.createTextRange();
r.moveToElementText(this);
r.select();
} else if (window.getSelection) { // W3C
var r = document.createRange();
r.selectNodeContents(this);
@tessro
tessro / gist:171195
Created August 20, 2009 16:56
Triangle Problem
#!/usr/bin/ruby
numOfTrials = 10000
numTriangles = 0
numOfTrials.times do
# generate two random breaks, in order
breaks = [ rand, rand ].sort
# load the length calculations via the breaks into an "lengths" array
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE grammar PUBLIC "-//W3C//DTD GRAMMAR 1.0//EN" "http://www.w3.org/TR/speech-grammar/grammar.dtd">
<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/06/grammar
http://www.w3.org/TR/speech-grammar/grammar.xsd"
xml:lang="en-US"
version="1.0"
root="command"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Speech.Recognition;
using System.Net;