Skip to content

Instantly share code, notes, and snippets.

1_000_000.times do
String.new
c = ObjectSpace.each_object { }
puts c
end
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)
def all_false(enumerable)
enumerable.each { |e| return false if e }
true
end
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
class A
def initialize
@foo = 123
end
def method_missing(name)
instance_variable_get "@#{name}"
end
end
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')
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
(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
(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.))]
(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)