Skip to content

Instantly share code, notes, and snippets.

View gist:64452
1_000_000.times do
String.new
c = ObjectSpace.each_object { }
puts c
end
View gist:64455
def num_stars(num, interval)
(num + (interval / 2)) / interval
end
1_000_000_000.times do |i|
String.new
if i % 100_000 == 0
c = ObjectSpace.each_object { }
puts '*' * num_stars(c, 10000)
View gist:65440
def all_false(enumerable)
enumerable.each { |e| return false if e }
true
end
View gist:66374
irb(main):010:0> h = { :a => 1, :b => 5, :c => 3 }
=> {:c=>3, :a=>1, :b=>5}
irb(main):011:0> h.values.max
=> 5
View gist:66565
class A
def initialize
@foo = 123
end
def method_missing(name)
instance_variable_get "@#{name}"
end
end
View gist:69690
def file_to_nums(filespec)
file_content = IO.read filespec
numbers_as_strings = file_content.split ','
numbers_as_strings.map { |s| s.to_f}
end
`echo 1, 123, 74, 1.234 > numbers.txt`
p file_to_nums('numbers.txt')
View gist:69732
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/**
* Simplifies the DocumentListener interface by having all three
* interface methods delegate to a single method.
*
* To use this abstract class, subclass it and implement the abstract
View gist:74451
(def clear-action (proxy [AbstractAction] ["Clear"]
actionPerformed [event]
(. fahr-text-field setText "")
(. cels-text-field setText "")
))
java.lang.UnsupportedOperationException: nth not supported on this type: Symbol (FrameInClojure.clj:71)
error:
java.lang.UnsupportedOperationException: nth not supported on this type: Symbol
View gist:74494
(defn create-converters-panel
"Creates panel containing the labels and text fields."
[]
(let [
create-an-inner-panel #(JPanel. (GridLayout. 0 1 5 5))
label-panel (create-an-inner-panel)
text-field-panel (create-an-inner-panel)
outer-panel (JPanel. (BorderLayout.))]
View gist:74602
(let [
create-an-inner-panel (fn [] (JPanel. (GridLayout. 0 1 5 5)))
label-panel (create-an-inner-panel)
Error:
Exception in thread "main" java.lang.ClassCastException: javax.swing.JPanel cannot be cast to clojure.lang.IFn (FrameInClojure.clj:0)
at clojure.lang.Compiler.eval(Compiler.java:4533)