Skip to content

Instantly share code, notes, and snippets.

View timruffles's full-sized avatar

Tim Ruffles timruffles

View GitHub Profile
@timruffles
timruffles / demo.js
Created May 25, 2011 16:26
for parks
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<h3 class="title">Picklive buzz</h3>
<script type="text/javascript">
var rotater = function(selector) {
@timruffles
timruffles / gitdowncase.rb
Created June 10, 2011 09:35
convert filenames in git to lowercase
#!/usr/bin/ruby
STDIN.read.split("\n").each do |file|
file.gsub!("\n","")
cmd = <<-CMD
git mv #{file} #{file}~
git mv #{file}~ #{file.downcase}
CMD
unless file == file.downcase
`#{cmd}`
end
@timruffles
timruffles / move.js
Created July 11, 2011 13:41
move lang notes
nice = {'^':"it looks like a lambda! Also, if you pick a random point in time, I'm probably typing 'functio...' (-> now", "foo, 'bar', baz":"it's nicer than #{} even, especially with implicit spaces (tho how do you disable that? eg with 'foo, 'string'')", "semantic whitespace":"newbies don't like typing line noise like. semantic whitespace is visually intuative"}
suggestions_for_improvements = {"not being able to escape quotes":"it's awkward", "cmr-r being broken":"If I type r's in the repl, with a syntax error, the cmd-r shortcut often fires and I can't type", "== and === ":"is and isnt are more comprehensible to non-nerds", "the lack of for comprehensions":"functional iterators are less friendly to non-nerds"}
explain = ^(explainer, list) { Object.keys(list).forEach ^(reason) { print explainer, reason, "because", list[reason] } }
explain "I like", nice
explain "I don't like", suggestions_for_improvements
bank_account = ^(balance) {
^(cmd,amount) {
amount || (amount = 0)
if(cmd == "withdraw") bank
@timruffles
timruffles / message.js
Created July 12, 2011 23:28
inadvisably late-night js message passing
function NoMethodError(method) {
this.name = "NoMethodError";
this.message = method + " is not defined";
}
NoMethodError.prototype = Error.prototype;
Object.prototype.methodMissing = function(method,args) {
throw new NoMethodError(method)
}
@timruffles
timruffles / date.coffee
Created July 12, 2011 23:33
coffeescript version of ActiveSupport::Date
define [], ->
periods =
second: second = 1000
minute: min = 60 * second
hour: hour = min * 60
day: day = hour * 24
week: week = day * 7
month: month = day * 29.6
year: day * 356
@timruffles
timruffles / watcher.rb
Created August 22, 2011 16:29
HP Touchpad watching made easy
puts "Watching #{ARGV[0]}"
changed = false
last = false
until changed
page = `curl #{ARGV[0]}`
unless last == false
changed = page != last
end
last = page
sleep 60
@timruffles
timruffles / touchpad_threadded.rb
Created August 23, 2011 08:07
Multi-threaded Touchpad watcher - taking it too seriously?
require "net/http"
require "csv"
require "addressable/uri"
require "pp"
unstable_urls = ARGV[0]
stable_urls = ARGV[1]
urls = {}
[[unstable_urls,:grep],[stable_urls,:change]].each do |urls_file,technique|
CSV.read(urls_file).map { |url|
@timruffles
timruffles / popup.html
Created August 23, 2011 14:42
Pure css3 popup element
<style>
.wrap {
-webkit-transition: all 1s;
position:absolute;
bottom: 0;
height: 0;
width: 0;
overflow: hidden;
-webkit-transition-delay: 1s;
}
@timruffles
timruffles / stats.rb
Created August 26, 2011 14:15
Quick stats
rgs =rgs.select {|rg| rg.scheduled_at > Date.parse("2011/08/15") }
ratios = rgs.map {|rg|
first_half, second_half = rg.entries.select {|e|e.big_game.game_type == "short"}
.partition{|e| /^(\d)/=~e.big_game.start_point; $1.to_i == 1 }
second_half.length / first_half.length.to_f
}
@timruffles
timruffles / twiter-grab.js
Created September 14, 2011 15:52
Quick twitter stream json-ifier
$(".stream-item").map(function() {
t = $(this);
return {
profile: t.find("img.user-content-image").attr("src"),
twitter: t.find("a.user-profile-link strong").html(),
fullName: t.find(".full-name").html(),
description: t.find(".user-description").html()
}
});