This file contains 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
# To demo in irb: | |
# load 'spinner.rb' ; include Spinner ; spinner_demo | |
# | |
# To use, include this module in a class and then wrap something in with_spinner | |
# It has two params, both optional. See spinner_demo for usage examples. | |
module Spinner | |
def with_spinner total=nil, message="Working...", &blk | |
current=0 | |
shown=buildstr(message,current,total) |
This file contains 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
importClass(Packages.java.sql.DriverManager); | |
importClass(Packages.java.sql.ResultSet); | |
// Let the classloader see it. | |
new Packages.com.mysql.jdbc.Driver(); | |
var DB_BASE='kingdom'; | |
var DB_USER='root'; | |
var DB_PASS=''; | |
var DB_HOST='localhost'; |
This file contains 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
function monkeyRow(diff,max,op){ | |
var a=1; | |
var b=a+diff; | |
var ret=[]; | |
while(b<=max){ | |
ret.push(op(a,b)); | |
a++; | |
b++; | |
} |
This file contains 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
importClass(Packages.javax.swing.JComponent); | |
importClass(Packages.javax.swing.JFrame); | |
importClass(Packages.javax.swing.JLabel); | |
importClass(Packages.java.awt.Color); | |
var frame=new JFrame('Foo!'); | |
var comp=new JComponent(){ | |
paintComponent:function(g){ | |
print('painted'); | |
g.setColor(Color.RED); |
This file contains 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
(defun matching-char (find other delta &optional start level) | |
(save-excursion | |
(let ((level (if level level 0)) | |
(start (if start start (point)))) | |
(if (and | |
start | |
(>= start (point-min)) | |
(<= start (point-max))) | |
(goto-char start) | |
(error "Not within block")) |
This file contains 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/ruby | |
# The original thing required rubygems and json_pure for some reason, even though it defines its own json parser. | |
# I think I had some trouble getting gems to work, which is why I wrote my own in the first place. | |
# --RBA 2009-08-22 | |
# require 'rubygems' | |
# require 'json_pure' | |
def readWord (stream=STDIN,first=nil) |
This file contains 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 "sqlite3" | |
require "sequel" | |
database = Sequel.sqlite() | |
database << <<-SQL | |
create table people ( | |
id integer primary key, | |
created_at timestamp, |
This file contains 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
-- Summing the sequence 1..n in as many ways as I can think of! | |
-- With the closed form | |
function sum(n) | |
return ((n+1) * n) / 2 | |
end | |
print(sum(6)) -- Had better be 21 | |
-- With tail recursion |
This file contains 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 "active_support" | |
{"a" => [1]}.to_json # <== Raises CircularReferenceError. Why?! |
This file contains 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 algorithm_p n | |
a = ")" + "()"*n | |
m = 2*n - 1 | |
loop do | |
yield a[1..-1] | |
a[m] = ")" | |
if a[m-1].chr == ")" | |
a[m-1] = "(" | |
m -= 1 |
OlderNewer