Skip to content

Instantly share code, notes, and snippets.

@vikhyat
vikhyat / dice2.rb
Created December 2, 2008 06:57
Roll 2 dice several times (v2)
# Rolling a dice is equivalent to generating a random number from 1 to 6.
def dice_roll
sum = 0
2.times {
sum += 1 + rand(6)
}
sum
end
# tiny shoes app that tells the length of some text
Shoes.app :title => 'strlen', :width => 300, :height => 125 do
background "#CFC".."AFA"
stack :margin => 10 do
para "Enter some text here"
@text = edit_line
every 0.1 do
@len.replace "The length of the text entered is " + @text.text.length.to_s + "."
end
a:link,a:visited,a:hover{color:#476c8e}a:link,a:visited,.nav:visited,.nav:link,.nav,.codeheader,.quoteheader,.catbg3 a:visited,.catbg3 a:link,tr.catbg3 td,.catbg3,.catbg2 a:visited,.catbg2 a:link,.catbg a:visited,.catbg a:link,.maintab_active_back,.maintab_back,.maintab_back a:visited,.maintab_back a:link,.maintab_active_back a:visited,.maintab_active_back a:link,.maintab_active_back a:hover,.maintab_back a:hover,.mirrortab_back,.mirrortab_active_back,.mirrortab_active_back a:visited,.mirrortab_active_back a:link,.mirrortab_back a:visited,.mirrortab_back a:link,.mirrortab_active_back a:hover,.mirrortab_back a:hover,div.navigation ul li a{text-decoration:none}a:hover,a.nav:hover,.titlebg2 a:visited,.titlebg2 a:link,.titlebg2 a:hover{text-decoration:underline}.nav:visited,.nav:link,.nav,button,textarea,input,textarea,select,.quote,.code,.codeheader,.quoteheader,.windowbg,.windowbg2,.windowbg3,.mirrortab_active_back a:hover,.mirrortab_back a:hover{color:#000}a.nav:hover{color:#c33}table{empty-cells:show}tr,th,td
body
{
margin: auto;
width: 78%;
color: #666;
font-family: GillSans, Calibri, Trebchet, sans-serif;
}
/* Deal with the links */
var jConsole = {
init: function() {
holder = document.createElement("div")
holder.setAttribute("style", "height: 250px; background: #000000; color: #ffffff; opacity: 0.4; position: static;")
document.body.appendChild(holder)
}
}
jConsole.init()
class MyAwesomeClass
attr_accessor :awesome_instance_variable
def initialize(var)
@awesome_instance_variable = var
end
def reverse!
@awesome_instance_variable = @awesome_instance_variable.reverse
end
end
@vikhyat
vikhyat / metronome.rb
Created April 22, 2009 05:32
Very simple metronome
#!/usr/bin/env ruby
def every(delay)
loop do
sleep(delay)
yield
end
end
def beep
%w[
rubygems
sinatra
dm-core
dm-timestamps
].each { |lib| require lib }
get '/' do
"You aren't supposed to be viewing this."
end
var Rufus = {
Mnemo: {
/** CONSTANTS **/
V: [ 'a', 'e', 'i', 'o', 'u' ],
C: [ 'b', 'd', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'z' ],
SYL: [], // This is populated later on. [1]
SPECIAL: [