One line summary (< 50c)
Longer description (wrap at 72c)
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
| #ruby | |
| [1,2,3,4].select{ |x| x.even? } | |
| #python | |
| [x for x in [1,2,3,4] if not x%2] | |
| #or, more norvingly | |
| filter(lambda x: not x%2, [1,2,3,4]) | |
| #clojure | |
| (filter #(even? % ) [1 2 3 4]) |
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
| /* | |
| * Fabrizio Calderan, twitter @fcalderan, 2010.11.02 | |
| * I had an idea: could Inception movie be explained by a few javascript closures | |
| * and variable resolution scope (just for fun)? | |
| * | |
| * Activate javascript console =) | |
| */ | |
| <script> | |
| console.group("inception movie"); |
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
| # 30 minutes Lisp in Ruby | |
| # Hong MinHee <http://dahlia.kr/> | |
| # | |
| # This Lisp implementation does not provide a s-expression reader. | |
| # Instead, it uses Ruby syntax like following code: | |
| # | |
| # [:def, :factorial, | |
| # [:lambda, [:n], | |
| # [:if, [:"=", :n, 1], | |
| # 1, |
If one was inclined to use the acts_as_yaffle pattern, they would probably use the second one, rather than the heavily cargo-culted first one.
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
| # Copyright 2010, Eric Burnett. All code released under the LGPL 2.1 except | |
| # where noted. | |
| # Uses matplotlib for charting. | |
| import math | |
| import random | |
| from matplotlib import pyplot | |
| # 'Array' is based on code taken from the demo file sortvisu.py from |
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
| /* | |
| Script: Array.Reduce.js | |
| MooTools implementation for Array.reduce() and Array.reduceRight() | |
| Acknowledgement: | |
| - Implementation code ported and reworked from Mozilla's Array.reduce() and Array.reduceRight() algorithms. | |
| cf: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce, | |
| https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight | |
| */ |
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
| /* This is when a refactoring really pays off. | |
| * | |
| * In order to make your code more modular, avoid hard-coding assumptions (or refactor them away). | |
| * The most fundamental, anti-modular assumption in Object-Oriented software is the concrete type of objects. | |
| * Any time you write "new MyClass" in your code (or in Ruby MyClass.new) you've hardcoded | |
| * an assumption about the concrete class of the object you're allocating. These makes it impossible, for example, | |
| * for someone to later add logging around method invocations of that object, or timeouts, or whatever. | |
| * | |
| * In a very dynamic language like Ruby, open classes and method aliasing mitigate this problem, but | |
| * they don't solve it. If you manipulate a class to add logging, all instances of that class will have |
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
| #Newbie programmer | |
| def factorial(x): | |
| if x == 0: | |
| return 1 | |
| else: | |
| return x * factorial(x - 1) | |
| print factorial(6) | |
| #First year programmer, studied Pascal |
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
| require 'open-uri' | |
| # url dsl -- the ultimate url dsl! | |
| # | |
| # You just can't beat this: | |
| # | |
| # $ irb -r url_dsl | |
| # >> include URLDSL | |
| # => Object | |
| # >> http://github.com/defunkt.json |