Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'activesupport'
class String
def emphasize substrings
highlight self, substrings
end
end
@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))
@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
@visnup
visnup / gist:224711
Created November 3, 2009 02:17
just get the time zone from javascript, don't deal with asking
# in application.js
document.cookie = '_swivel_time_zone=' + new Date().getTimezoneOffset()*-60;
# in application_controller.rb:
before_filter { |controller| Time.zone = ActiveSupport::TimeZone[controller.cookies[:_swivel_time_zone].to_i] if controller.cookies[:_swivel_time_zone] }
@visnup
visnup / CutyCapt.rb
Created December 3, 2009 01:47
using pinkyurl
#!/usr/bin/env ruby
require 'open-uri'
require 'rubygems'
require 'rack'
out = nil
query = ARGV.map do |o|
k, v = o.split '='
out = v if k == '--out'
"#{k.sub /^--/, ''}=#{Rack::Utils.escape v}"
@visnup
visnup / sass-color-fix.rb
Created December 5, 2009 02:28
fix sass color math for the very special case of !color + #fff (or any gray)
require 'rubygems'
require 'sass'
#
# fix sass color math
#
class Sass::Script::Color
def hsl
rgb = @value.map { |c| c / 255.0 }
min_rgb = rgb.min
$ dig @8.8.8.8 visnup.com
; <<>> DiG 9.6.0-APPLE-P2 <<>> @8.8.8.8 visnup.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23373
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
@visnup
visnup / your.js
Created January 22, 2010 18:28
bookmarklet function to change people's "your" into "you're"
(function your(node) {
if (node.nodeType == 3) { // text-node
node.nodeValue = node.nodeValue.replace(/\b(you)(r)\b/ig, "$1'$2e");
} else {
var c = node.childNodes;
for (var i = 0; i < c.length; i++)
your(c[i]);
}
})(document.body);