Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'open-uri'
require 'hpricot'
doc = open('http://neohumanism.org/x/x1/x11_color_names.html') {|f| Hpricot(f)}
doc.search('tr').each do |tr|
c = tr.search('td').first
puts c.inner_html unless c.nil?
end
center = [500,500]
radius = 500
height = 100
width = 100
num_edge = 50
num_hour = 10
num_min = 10
length_hour = 300
def contents(path)
n_path = File.expand_path( path )
Dir.chdir(n_path)
files = Dir.glob('*')
return files
end
$DATE_FORMAT = "%I:%M%p %b %d %Y"
x = Time.now
puts x.strftime($date_format)
#Sort by field / case insensitive
@tags = @tags.sort_by { |tag| tag.tag.downcase }
@morganp
morganp / flatten.rb
Created September 2, 2010 02:14 — forked from Whoops/flatten.rb
require 'pp'
a=[1,[2,[3]],4,5,[6,7,[8,9]]]
pp a.inject([]){|b,x| if Array===x then x.each {|y| b << y } else b << x end;b;}
#Classy Sinatra
#Launch with ruby app.rb
require 'rubygems'
require 'sinatra/base'
#module MyModule
class MyApp < Sinatra::Base
#set :raise_errors, Proc.new { false }
#set :sessions, false
#set :static, true
#Ruby mixin Enumerable implement each:
# hey presto you have .map (but not .map!)
class Core
include Enumerable
attr_reader :name, :data
def initialize( name, data )
#!/usr/bin/env ruby
#List all file below this location
path = File.expand_path( $0 )
puts path
def list_files( files, spacer='', path='.')
path = File.expand_path( path )
files.each do |f|
#Better way to delete if it exists
if UnWatched::Node.exists?( :name=>file_name )
node = UnWatched::Node.find_by_name( file_name )
UnWatched::Node.destroy(node)
end