Skip to content

Instantly share code, notes, and snippets.

View jballanc's full-sized avatar

Joshua Ballanco jballanc

View GitHub Profile
@adder = 0
@adder_queue = Dispatch::Queue.new('adder_queue')
@nums = (0..9).to_a
@nums.p_each do |n|
val = n ** 2
@adder_queue.sync do
@adder += val
end
end
@jballanc
jballanc / fun.rb
Created December 21, 2011 17:54
Count Objects across GC's
$h = {}
$s = ""
$f = proc do
ObjectSpace.count_objects($h)
$c += $h[:TOTAL] - $h[:FREE]
$s = ""
ObjectSpace.define_finalizer($s, $f)
$s = nil
puts "Total objects allocated: #{$c}, GC Cycles: #{GC.count}"
end
@jballanc
jballanc / uh-oh-scope.rb
Created October 31, 2011 21:17
Different behavior of class_eval between Ruby 1.9.2 and Ruby 1.9.3
# Compare the results running under Ruby 1.9.2 and Ruby 1.9.3
class Foo
def initialize
@@value = "Set from Foo initialize"
end
def report
@@value
end
end
# Both examples work under Ruby 1.9.2, but not under Ruby 1.9.3 (and yes, I
# realize both are bad practice anyway...):
# 1.
def test(foo, &block)
end
test 'hello', do; end
# 2.
class Foo; end
#!/usr/local/bin/macruby
server = Dispatch::Queue.new('my-server')
in_progress = Dispatch::Group.new
server.async(in_progress) do
puts "Server running"
server.suspend!
STATE README TEMPLATE
=====================
Metadata
--------
Name:
Abbreviation:
Legislature Name:
Upper Chamber Name:
Lower Chamber Name:
@jballanc
jballanc / bench.rb
Created September 5, 2011 20:54
Set#include? vs Hash#include? vs Hash#[]
require 'benchmark'
require 'set'
[10000, 100000, 1000000].each do |length|
Benchmark.bmbm do |x|
a = (1..length).to_a
s = Set.new(a)
h = Hash[a.zip([true]*a.length)]
puts "\n\nSearching through #{length} elements"
diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml
index 8c98f41..81d5e87 100644
--- a/app/views/comments/_comment.html.haml
+++ b/app/views/comments/_comment.html.haml
@@ -10,10 +10,10 @@
- editor_or_above ||= false
- too_many_comments_for_photos ||= false
-.clearfix.less-headroom.less-legroom.comment{:class => "#{comment.reply_to_id ? 'prepend-2' : ''}"}
+.clearfix.less-headroom.less-legroom.comment{:class => "#{comment.reply_to_id ? 'prepend-2' : ''}", :id => "comment_#{comment.id}"}
ping-audit-10-167-180-181-20101108: ~ > macirb
Awesome Print gem not installed
irb(main):001:0> Time.ancestors
=> [Time, Comparable, NSDate, NSObject, Kernel]
irb(main):002:0> Date.ancestors
=> [Date, #<Class:0x20023c900>, Comparable, #<Class:0x200036460>, NSObject, Kernel]
irb(main):003:0> DateTime.ancestors
=> [DateTime, Date, #<Class:0x20023c900>, Comparable, #<Class:0x200036460>, NSObject, Kernel]
require 'rubygems'
require 'sqlite3'
require 'sequel'
queue = Dispatch::Queue.new('bug')
queue.async do # this crashes
3.times do
Sequel.sqlite.transaction {}
end