View json_ostruct.rb
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 'json' | |
require 'ostruct' | |
data = '{"a": {"b": 1}}' | |
result = JSON.parse(data, object_class: OpenStruct) | |
result.a.b # => 1 |
View compare_without_order.rb
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
# Check if two arrays have exactly the same elements (we don't care about order) | |
keys = [2,1] | |
1. keys.sort == [1, 2] | |
2. Set.new(keys) == [1,2].to_set | |
3. (keys - [1,2]).empty? | |
4. (keys - [1,2,]).size == 0 |
View delegate.rb
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 'delegate' | |
require 'benchmark' | |
class User | |
end | |
class UserPresenter < SimpleDelegator | |
end | |
N = 10_000 |
View client.rb
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 'dcell' | |
DCell.start :id => "client-node", :addr => "tcp://127.0.0.1:2032" | |
blog = DCell::Global[:blog] | |
post = blog.new_post | |
sleep 3 | |
post.title = "hello dcell" | |
blog.publish_post(post) |
View app.js
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
// Ember.js - some concerns | |
//a) tightly coupling | |
App.NewGameView = Em.View.extend({ | |
click: function() { | |
App.lobbyController.newGameClicked(); | |
} | |
}) |
View cpistrano_rvm.rb
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 'bundler/capistrano' | |
set :application, "multicomm" | |
set :repository, "git@XXXX" | |
set :scm, :git | |
set :user, 'multicomm' | |
set :deploy_to, '/var/lib/multicomm' | |
set :use_sudo, false | |
set :git_enable_submodules, 1 |
View gist:890485
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 pg = require('pg'); | |
var http = require('http'); | |
var conString = "tcp://node:node@127.0.0.1/postgres"; | |
var client = new pg.Client(conString); | |
client.connect(); | |
http.createServer(function(req, res) { |
View extend_and_method_call_bench.rb
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 'benchmark' | |
module Foo | |
def bar | |
end | |
def baz | |
end |
View include_vs_extend.rb
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 Foo | |
def bar | |
end | |
def baz | |
end |
View splat.rb
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
a = *"Hello" #=> ["Hello"] |
NewerOlder