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
| String.prototype.times = function(n) { | |
| // join checks its first argument for a length property, so we supply it with one. | |
| // what normally happens is something like this: | |
| // | |
| // [1, 2, 3].length //=> 3 | |
| // [1, 2, 3].join(", ") //=> "1, 2, 3" | |
| // | |
| // so the following is equivalent ... | |
| // | |
| // Array.prototype.join.call([1, 2, 3], ", ") //=> "1, 2, 3" |
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 SqlQuery; end | |
| query = SqlQuery.new | |
| puts "String === query is #{String === query}" | |
| #=> String === query is false | |
| String.extend Module.new { | |
| def ===(obj) | |
| obj.instance_of?(SqlQuery) or super |
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
| // via https://gist.github.com/4080907 | |
| Object.defineProperty(window, 'log', { | |
| set: function(args) { | |
| console.log.apply(console, Array.isArray(args) ? args : [args]); | |
| this.value = args | |
| }, | |
| get: function() { | |
| return this.value + " from .get"; | |
| } | |
| }); |
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
| some_guy = 'Fred' | |
| first_names = [] | |
| first_names.append(some_guy) | |
| another_list_of_names = first_names | |
| another_list_of_names.append('George') | |
| some_guy = 'Bill' |
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
| # fun with the new lambda syntax | |
| adder = ->(a, b) { a + b } | |
| subtr = ->(a, b) { a - b } | |
| divdr = ->(a, b) { a / b } | |
| multr = ->(a, b) { a * b } | |
| puts "adder.(4, 2) = #{adder.(4, 2)}" | |
| puts "subtr.(4, 2) = #{subtr.(4, 2)}" | |
| puts "divdr.(4, 2) = #{divdr.(4, 2)}" | |
| puts "multr.(4, 2) = #{multr.(4, 2)}" |
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
| # Date.new will be the beginning of time | |
| # Date::Infinity.new will be the end of time | |
| require 'date' | |
| case Date.parse(ARGV[0]) | |
| when Date.new..Date.new(1983, 1, 15) | |
| puts "pre-Iacono" | |
| when Date.new(1983, 1, 15)..Date::Infinity.new | |
| puts "post-Iacono" | |
| 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
| # encoding: UTF-8 | |
| class Weather | |
| def ☃ | |
| "I'm a snowman!" | |
| end | |
| def ☁ | |
| "Looking like a cloudy day" | |
| 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
| require 'net/http' | |
| require 'uri' | |
| require 'io/console' | |
| puts "Enter in a github username:" | |
| gh_username = gets.chomp | |
| puts "Enter in the github user password (hidden):" | |
| gh_password = STDIN.noecho(&:gets).chomp | |
| uri = URI.parse('https://api.github.com/user') |
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
| #!/bin/sh | |
| echo "you passed me $# args" | |
| echo "pid = $$" | |
| echo "and I am $0" | |
| for a in $@ | |
| do | |
| echo $a | |
| done |
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
| # round 1! => nonblocking example | |
| [process a] $ flock -en sleeper.lock ./sleeper.sh | |
| time to sleep ... | |
| [process b] $ flock -en sleeper.lock ./sleeper.sh | |
| # ^ will exit b/c of n switch: "Fail (with an exit code of 1) | |
| # rather than wait if the lock cannot be immediately acquired. | |
| ... waking up # <= process a returning | |
| # round 2! => blocking example |