Inspect a website like a string in Ruby
unset -f inspect_url function inspect_url() { /usr/bin/curl -L -s --max-time 10 "${@}" | ruby -n -e 'p $_.to_s' return 0 } inspect_url http://www.ruby-forum.com
12374 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
unset -f inspect_url function inspect_url() { /usr/bin/curl -L -s --max-time 10 "${@}" | ruby -n -e 'p $_.to_s' return 0 } inspect_url http://www.ruby-forum.com
y = 'testing'.scan(/./) y.each do |c| puts c end
?a # => 97 ?\n # => 10
'a'[0] # => 97 'hallo'[1] # => 97
97.chr # => "a" 10.chr # => "\n"
class Counter def initialize() @characters = Hash.new(0) end def read() @text = IO.read("text.txt") end def count_chars @text.each_byte do |ch| @characters[ch] +=1 end end def report @characters.each do |key, value| puts "#{key.chr} (#{key}) occurs #{value} times" end end end
count = Counter.new() count.read count.count_chars count.report
function map_char($num) { $int = $num; $int+=48; ($int > 57) ? $int += 7 : null; ($int > 90) ? $int += 6 : null; return chr($int); }
from appuifw import * def thai_input(): first_list = [' '.join(thai_char[i:i+11]) for i in range(0,77,11)] y = popup_menu(first_list, u'select Thai char') if y is not None: x = popup_menu(thai_char[11*y:11*(y+1)], u'select Thai char') if x is not None: t.add(thai_char[11*y + x]) thai_char = [unichr(0x0e01+i) for i in range(77)] # 77 thai characters app.body = t = Text() app.menu = [(u'thai', thai_input), (u'clear screen', t.clear)] # wait for user to exit program import e32 lock = e32.Ao_lock() app.exit_key_handler=lock.signal lock.wait()