This file contains 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
module B64 | |
extend self | |
ENCODING_TABLE = [ | |
('A'..'Z').to_a, | |
('a'..'z').to_a, | |
('0'..'9').to_a, | |
['+', '/'] | |
].flatten |
This file contains 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
var obj = {}; | |
// null and 'null' | |
obj[null] = 1; | |
obj['null'] = 2; | |
console.log(obj[null]); // 2 | |
// Numbers | |
obj[3] = 3; | |
obj['3'] = 4; |
This file contains 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
obj.should ... | |
expect(obj).to ... | |
obj.should_not ... | |
expect(obj).not_to ... | |
obj.should =~ // | |
expect(obj).to match(//) | |
[1, 2, 3].should =~ [3, 2, 1] |
This file contains 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
Konacha::SpecsController.class_eval do | |
def paper_trail_enabled_for_controller | |
false | |
end | |
end if defined?(Konacha) |
This file contains 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
#!/usr/bin/env node | |
var filename = process.argv[2]; | |
if (filename) { | |
var json = require('fs').readFileSync(filename).toString('utf-8'); | |
printPretty(json); | |
} else { | |
var json = ''; | |
process.stdin.setEncoding('utf-8'); | |
process.stdin.on('data', function (chunk) { |
This file contains 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
# My local time offset is +0900. | |
require 'date' | |
require 'time' | |
Time.new(2013, 9, 3, 10) > Date.new(2013, 9, 3) # ArgumentError: comparison of Time with Date failed | |
require 'active_support/time' |
This file contains 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
# Bad | |
expect(all('.something').size).to eq(5) | |
# Good | |
expect(page).to have_css('.something', count: 5) |
This file contains 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 'nokogiri' | |
xml = File.read('./wordpress.2013-07-10.xml') | |
doc = Nokogiri::XML.parse(xml) | |
items = doc.xpath('/rss/channel/item') | |
puts "#{items.size} items" | |
items.each do |item| | |
date = item.at('./wp:post_date').text |
This file contains 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
package controller | |
import akka.actor.ActorSystem | |
import scala.concurrent.{Promise, ExecutionContext} | |
import org.scalatra.{AsyncResult, FutureSupport} | |
import dispatch._ | |
import skinny.controller.SkinnyServlet | |
object DispatchAkka { | |
def retrievePage()(implicit cxt: ExecutionContext): Future[String] = { |
This file contains 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
package main | |
import ( | |
"code.google.com/p/go-tour/tree" | |
"fmt" | |
) | |
// Walk walks the tree t sending all values | |
// from the tree to the channel ch. | |
func Walk(t *tree.Tree, ch chan int) { |