This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
center = [500,500] | |
radius = 500 | |
height = 100 | |
width = 100 | |
num_edge = 50 | |
num_hour = 10 | |
num_min = 10 | |
length_hour = 300 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def contents(path) | |
n_path = File.expand_path( path ) | |
Dir.chdir(n_path) | |
files = Dir.glob('*') | |
return files | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$DATE_FORMAT = "%I:%M%p %b %d %Y" | |
x = Time.now | |
puts x.strftime($date_format) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Sort by field / case insensitive | |
@tags = @tags.sort_by { |tag| tag.tag.downcase } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |