Skip to content

Instantly share code, notes, and snippets.

View avescodes's full-sized avatar

Avery Quinn avescodes

View GitHub Profile
@avescodes
avescodes / gist:14199
Created October 1, 2008 21:37
Simple logic parser I did for an assignment
#Here I add a two helper methods to the Fixnum class to aid in creating cases
class Fixnum
#returns T/F (actually F/T) if number is zero.
def bool
self.zero?
end
#Create a number of cases based on the calling number
#i.e. 2 returns [ [T,T], [T,F], [F,T], [F,F]]
def create_cases
def do_work
fltArray = [-361, -359, -44, -0.001, 0.0001, 1, 45, 89,
90, 91, 179, 180, 189, 360, 360001 ]
cosVals = []
sinVals = []
tempVar = -1.0
for (int i = 0; i < fltArray.length, i++)
{
if(fltArray[i] >= 360.0)
{
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.73 [en] (Windows NT 5.0; U) [Netscape]">
<meta name="Author" content="Web Creations - John Shotton - jasit@mts.net - (204) 882-2832">
<meta name="Description" content=" R. M. of Stanley, Gardenland of Manitoba.">
<meta name="KeyWords" content="rm of stanley, rural, municipality, of, stanley, Morden, Manitoba, MB, Canada, City of Winkler, Manitoba, Best in Country Living, Corn and Apple Festival, Minnewasta, south central, Winnipeg, Lake Minnewasta, Pembina Hills Art Gallery, Leo Mol statue, Canadian Fossil Discovery Centre, fossils, Morden Museum, Back Forty Folk Festival, Morden International Triathlon, Colert Beach, Agriculture Canada Research Station, Minnewasta Golf and Country Club, Manitoba Baseball Hall of Fame, Pembina Thresherman's Museum, Cripple Creek Music Festival, Morden Mighty Man Competition, Thresherman's Reunion, Bound
require 'benchmark'
str = "1 2 3 4-5 6 7 8-9"
Benchmark.bm do |bm|
bm.report("split: ") {10000.times do hash = Hash.new(0); str.split.each { |m| hash[m] += 1}; end }
bm.report("scan: (\\w+) ") { 10000.times do hash = Hash.new(0); str.scan(/\w+/m) { |m| hash[m] += 1} end }
bm.report("scan: (\w+(-\w+)?) ") { 10000.times do hash = Hash.new(0); str.scan(/(\w+(-\w+)?)/m) { |m| hash[m] += 1} end }
end
## Native environment tests - 1.8.7
(defn count-atoms [L]
(cond
(not (coll? L)) 1
(empty? L) 0
(list? L) (apply + (map count-atoms L))))
@avescodes
avescodes / git-update.rb
Created January 12, 2009 01:53
Quick little git repo editor
#!/opt/local/bin/ruby -w
require 'YAML'
# Example ~/.git_repos :
# repos:
# - "~/dev/gh/joust"
# - "~/dev/gh/joust/meta"
config = YAML.load_file(ENV['HOME'] + "/.git_repos")
config['repos'].each do |f|
f.gsub!('~',ENV['HOME'])
#!/opt/local/bin/zsh
for f in *.erb; html2haml $f > `basename $f .erb`.haml%
require 'set'
all = Set.new
`which -a vi`.each_line {|line| all << line.strip }
`which -a vim`.each_line {|line| all << line.strip }
emacs = `which emacs`.strip
all.each do |vi|
puts "Please enter your password when prompted; we are fixing things"
`sudo rm #{vi}`
`sudo ln -s #{emacs} #{vi}`
end
Delivered-To: twtbot@gmail.com
Received: by 10.114.155.8 with SMTP id c8cs261037wae;
Thu, 22 Jan 2009 18:13:17 -0800 (PST)
MIME-Version: 1.0
Sender: neufelry@gmail.com
Received: by 10.114.92.14 with SMTP id p14mr4207993wab.140.1232676797484; Thu,
22 Jan 2009 18:13:17 -0800 (PST)
Date: Thu, 22 Jan 2009 20:13:17 -0600
X-Google-Sender-Auth: ac619f32b7c737b4
Message-ID: <70fc96270901221813w5e7e8946td90f532cdc57d8c3@mail.gmail.com>
email =~ /(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()@,;:\\".\[\] 00-31]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()@,;:\\".\[\]]))|”(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*”(?:(?:
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()@,;:\\".\[\] 00-31]+(?:(?:(
?:\r\n)?[ \t])+|\Z|(?=[\["()@,;:\\".\[\]]))|”(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*”(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()@,;:\\".\[\] 00-
31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()@,;:\\".\[\] 00-31]+
(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:
(?:\r\n)?[ \t])*))*|(?:[^()@,;:\\".\[\] 00-31]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()@,;:\\".\[\]]))|”(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*”(?:(?:\r\n)