This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1_000_000.times do | |
| String.new | |
| c = ObjectSpace.each_object { } | |
| puts c | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def all_false(enumerable) | |
| enumerable.each { |e| return false if e } | |
| true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class A | |
| def initialize | |
| @foo = 123 | |
| end | |
| def method_missing(name) | |
| instance_variable_get "@#{name}" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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.))] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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) |
OlderNewer