Skip to content

Instantly share code, notes, and snippets.

# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)
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;}
Benchmark
CSV (Ruby 1.9, not 1.8!)
DRb
Delegator ## aguids
FileUtils ## tehviking
Fiber ## afcapel
JSON (The Ruby 1.9 stdlib, NOT the gems) ## sweetmango
Matrix ## morgy
MiniTest
OptionParser ## jazzu
@JEG2
JEG2 / board_spec.rb
Created September 23, 2010 04:02
I wish all of these satisfy calls weren't needed to pass warnings
require "go/gtp/board"
describe Go::GTP::Board do
before :all do
@string = <<-END_BOARD.gsub(/^ {4}/, "")
A B C D E F G H J
9 . . . . . . . . . 9
8 . . . . . . . . . 8
7 . . X . . . + . . 7
6 . . . . . . . . . 6

Object Oriented Programming explained to 10 year olds

By Morgan Prior & Ashish Dixit

Objects are things that you can see around you. The chair is an object. The toys you have are objects. Robots are objects. Objects can be defined based on how they look and what they can do. For example, you can define a car as a red car or a fast car. When you say red, you are talking about physical features and when you say fast, you are talking about their abilities.

Objects form different groups based on their similarities & differences. Car is one kind of object while Robots are another. Within Robots there are household robots like the roomba that vaccums your carpet then there are cooler robots like the transformers. However, both transformers and the roomba in your house share certain similarities. So you can say that both roomba & Transformers inherit certain characteristics that are common to all robots and have additional features that separate them apart.

N

@funny-falcon
funny-falcon / patch-1.9.2-gc.patch
Created March 5, 2011 11:11
GC tunning simple patch ruby 1.9.2 p180
diff --git a/gc.c b/gc.c
--- a/gc.c
+++ b/gc.c
@@ -77,6 +77,41 @@ void *alloca ();
#ifndef GC_MALLOC_LIMIT
#define GC_MALLOC_LIMIT 8000000
#endif
+#define HEAP_MIN_SLOTS 10000
+#define FREE_MIN 4096
+
#!/usr/bin/env ruby
require 'slop'
opts = Slop.parse do
banner "Usage: ruby foo.rb [options]\n"
on :n, :name, 'Your username', true
on :a, :age, 'Your age (optional)', :optional => true
on :V, :verbose, 'Run in verbose mode', :default => false
configuration = configure do |config|
config.tail_logs = true
config.max_connections = 55
config.admin_password = 'secret'
config.app_server do |app_server_config|
app_server_config.port = 8808
app_server_config.admin_password = config.admin_password
end
end
@latentflip
latentflip / macspoof.sh
Created June 3, 2011 20:10
MAC Spoof on OSX
### Do these once
ifconfig en1|grep ether > .macaddress #Save your real mac address somewhere
#Alias the airport adapter
sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport
###Then each time you want to change MAC address:
airport -z #disconnect but don't turn off the airport
sudo ifconfig en1 ether 00:00:00:00:00:00 #set new mac address (perhaps just increment your old one)
ifconfig en1|grep ether #check it's actually changed
<script type="text/javascript">
var a_function = function() {
var a_number = 2;
document.write('Within a_function, a_number = '+a_number+'<br>');
return function(a) {
document.write('Within the callback, a_number = '+a_number+'<br>');
document.write('Within the callback, I was passed = '+a+'<br>');
document.write('Within the callback, a * a_number = '+a*a_number+'<br>');