Skip to content

Instantly share code, notes, and snippets.

View dynamical.rb
class Dynamical
define_method :works_fine do |&block|
5.times { |n| block.call(n) }
end
def self.defn name
define_method name do |&block|
5.times { |n| yield n }
end
end
View google_analytics.rb
module Rack
class GoogleAnalytics
TRACKING_CODE = <<-EOCODE
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("{{ID}}");
View example_init_d_script.sh
#!/bin/sh
# Author: Carl Youngblood, 2010
# Based on http://www.novell.com/coolsolutions/feature/15380.html
### BEGIN INIT INFO
# Provides: bluepill
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
View ring_server.rb
#start this first
require 'rinda/ring'
require 'rinda/tuplespace'
DRb.start_service
# Create a TupleSpace to hold named services, and start running
Rinda::RingServer.new Rinda::TupleSpace.new
# Wait until the user explicitly kills the server.
View a_good_place_to_start.rb
# http://gist.github.com/636681
# http://tinyurl.com/learn-ruby-processing
require 'rinda/ring'
DRb.start_service
ring_server = Rinda::RingFinger.primary
o = ring_server.read([:name,:processing,nil,nil])[2]
o.stroke 255, 0, 0 #Red outline
View gist:721909

Stuff in Ruby that is/isn't supported, or is different

Block Comments

###=begin / =end

Rib Rdb writes: "The new parser doesn't support this". Use single line comments instead.

/* --- */ format is also supported.

View element.mirah
/*
with selected true as a param.
Element.select.
option("1", "one").
option("2", "two", true).
option("3", "three").to_s
produces:
View kingdom-assignmentbin.rb
require 'rubygems'
require 'kingdom-assignment'
if CSV.const_defined? :Reader
# require 'fastercsv'
INSTALLED_CSV = FasterCSV
else
INSTALLED_CSV = CSV
end
View map.mirah
6: Cannot find instance method set(int, int) on java.util.List
Mirah::InternalCompilerError: Cannot find instance method set(int, int) on java.util.List
infer at ~/hacking/fresh_mirah/lib/mirah/typer/simple.rb:280
infer at ~/hacking/fresh_mirah/lib/mirah/ast/structure.rb:34
each at org/jruby/RubyArray.java:1603
infer at ~/hacking/fresh_mirah/lib/mirah/ast/structure.rb:33
infer at ~/hacking/fresh_mirah/lib/mirah/typer/simple.rb:275
infer at ~/hacking/fresh_mirah/lib/mirah/ast/flow.rb:125
collect at org/jruby/RubyArray.java:2336
View output.txt
~/hacking/fresh_mirah]$ bundle exec mirahc -V test.mirah
Parsing...
test.mirah
Inferring types...
* [Mirah::Typer] New type defined: 'Test' < ''
* [Mirah::Typer] Learned local type under #<Mirah::AST::StaticScope:0x39e2ee3f> : test = Type(boolean)
* [AST] [RequiredArgument] RequiredArgument(test) resolved!
...