Skip to content

Instantly share code, notes, and snippets.

View gaustin's full-sized avatar

Grant Austin gaustin

  • Minneapolis, MN
View GitHub Profile
#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])
/*
* 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");
@gaustin
gaustin / lisp.rb
Created September 2, 2010 18:51 — forked from dahlia/lisp.rb
# 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,

Writing Commit Messages

One line summary (< 50c)

Longer description (wrap at 72c)

Summary

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.

# 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
/*
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 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
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@gaustin
gaustin / url_dsl.rb
Created January 24, 2010 15:51 — forked from defunkt/url_dsl.rb
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