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
#!/usr/bin/env ruby | |
# -*- encoding: utf-8 -*- | |
require 'benchmark' | |
require 'multi_json' | |
require 'json' | |
require 'yajl' | |
require 'oj' | |
N = 1000 | |
TEST = [1, 100, 10000] |
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
# api_responder.rb | |
class APIResponder < ActionController::Responder | |
protected | |
def api_behavior(error) | |
if resource.present? | |
if post? | |
display resource, status: :created, location: api_location | |
else | |
display resource |
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 Group | |
has_many :members | |
has_many :users, through: :members | |
validates :members, length: {minimum: 1} | |
end | |
class Member | |
belongs_to :group | |
belongs_to :user | |
# attribute: ordinal |
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
#!/usr/bin/env ruby | |
# -*- encoding: utf-8 -*- | |
require 'test/unit' | |
module URLRegexp | |
URL_REGEXP = {}.tap do |h| | |
h[:protocol] = /(?:https?)/ | |
h[:ipv4] = /(?:\d+(?:\.\d+){3})/ | |
h[:ipv6] = /(?:[a-f0-9:.]+)/i | |
h[:ip] = /(?:#{h[:ipv4]}|#{h[:ipv6]})/ |
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
module MyApp | |
module API | |
class Railtie < Rails::Railtie | |
class Command | |
def initialize(user = nil) | |
@user = user || User.first | |
end | |
%i(get post patch put delete head).each do |method| | |
define_method(method) do |path, parameters = {}, headers_or_env = {}| |
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 'spec_helper' | |
describe UsersController do | |
let(:valid_params) { {'name' => 'test name'} } | |
let(:invalid_params) { {'__dummy__' => 123} } | |
it_behaves_like 'a indexable action', User, role: :user | |
it_behaves_like 'a showable action', User, role: :user | |
it_behaves_like 'a creatable action', User, role: :admin | |
it_behaves_like 'a updatable action', User, role: :admin |
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
Index: OAuthBase.cs | |
=================================================================== | |
--- OAuthBase.cs (revision 751) | |
+++ OAuthBase.cs (working copy) | |
@@ -251,7 +251,11 @@ | |
{ | |
normalizedUrl += ":" + url.Port; | |
} | |
- normalizedUrl += url.AbsolutePath; | |
+ |
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
#!/usr/bin/env ruby | |
# -*- encoding: utf-8 -*- | |
require 'bundler' | |
Bundler.require | |
require 'celluloid/autostart' | |
require 'securerandom' | |
# class Timer# {{{ | |
# include Celluloid | |
# include Celluloid::Notifications |
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
#!/usr/bin/env ruby | |
# -*- encoding: utf-8 -*- | |
module Utility | |
class << self | |
def say | |
puts to_s | |
end | |
end | |
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
mashiro@ricotta ~% irb | |
irb(main):001:0> require 'openssl' | |
=> true | |
irb(main):002:0> OpenSSL::Digest::SHA1.hexdigest 'ruby' | |
=> "18e40e1401eef67e1ae69efab09afb71f87ffb81" | |
irb(main):003:0> require 'digest/rmd160' | |
=> true | |
irb(main):004:0> Digest::RMD160.hexdigest 'ruby' | |
=> "29d9b710bc50866fa2399c3061cd02c0c8ffa197" | |
irb(main):005:0> require 'digest/sha1' |