Skip to content

Instantly share code, notes, and snippets.

<script type="text/javascript">
document.observe('dom:loaded', function() {
var li = new Element('li').update('li');
$('a').update(li);
var killIE = true;
if (killIE) {
li.update('new name');
} else {
$('a').update();
@visnup
visnup / drag events in mobile safari
Created February 22, 2009 05:10
minimal changes to detect touch/drag events in mobile safari
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -70,9 +70,15 @@
if (this.input && $F(this.input))
this.positionThumb(parseFloat($F(this.input)) * this.width / 100);
- this.div.observe('mousedown', this.onMouseDown.bindAsEventListener(this));
- this.div.observe('mouseup', this.onMouseUp.bindAsEventListener(this));
- this.div.observe('mousemove', this.onMouseMove.bindAsEventListener(this));
+ if (Prototype.Browser.MobileSafari) {
@visnup
visnup / say.rb
Created February 26, 2009 08:54
xmpp4r + say
# login to jabber/gtalk and have your computer say whatever people are saying to you
require 'rubygems'
require 'xmpp4r/client'
include Jabber
# settings
if ARGV.length != 2
puts "Run with ./echo_thread.rb user@server/resource password"
exit 1
require 'rubygems'
require 'scrubyt'
google_data = Scrubyt::Extractor.define do
fetch 'http://www.google.com/search?hl=en&q="guarded by a dragon"'
excerpt "//div[@class=s]"
next_page '//td/a', :limit => ARGV.shift.to_i || 3
end
@visnup
visnup / homework.rb
Created June 26, 2009 18:51 — forked from huned/homework
I took 15 minutes, but mine is 4 lines
require 'rubygems'
require 'open-uri'
require 'json'
url = 'http://twitter.com/statuses/user_timeline.json?id=visnup&count=3200'
dates = open(url) { |f| JSON.parse f.read }.map { |e| Date.parse e['created_at'] }
sum = dates.inject(Hash.new(0)) { |s, t| s[t] += 1; s }
sum.keys.sort.each { |k| puts "#{k} (#{sum[k]}) #{'=' * sum[k]}" }
@visnup
visnup / Show entries per day.rb
Created June 30, 2009 20:35 — forked from burnto/Show entries per day.rb
huned's homework problem
# Detect rss feed, parse it, and report number of posts per date.
require 'rubygems'
require 'hpricot'
require 'open-uri'
# First find the rss
url = ARGV[0] || "http://twitter.com/burnto"
doc = Hpricot(open(url))
require 'rubygems'
require 'activesupport'
class String
def emphasize substrings
highlight self, substrings
end
end
@visnup
visnup / uptime.rb
Created July 1, 2009 18:24
average uptime
#!/usr/bin/env ruby
# calculate average uptime of my machine
require 'rubygems'
require 'activesupport'
times = `last | grep ^shutdown`
times = times.map { |l| Time.parse l[/shutdown\s+~\s+(.*)/, 1] }
times = times.map { |t| t > Time.now ? t - 1.year : t }
diffs = times.zip(times[1 .. -1]).map { |(a, b)| a - b if b }.compact
@visnup
visnup / serverjuice.rb
Created August 21, 2009 23:37 — forked from gerad/serverjuice.rb
setup an ubuntu server quickly
#!/bin/sh
# Configure your desired options here
DESIRED_HOSTNAME="lazeroids.com"
# Ensure hostname is configured
if [ -z "$DESIRED_HOSTNAME" ]; then
echo DESIRED_HOSTNAME must be set.
exit 1
fi
@visnup
visnup / Google Chrome.icns
Created August 29, 2009 03:07
change my webkit icon