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 -KU | |
TIMES = 100000 | |
require 'rubygems' | |
gem 'addressable', '~>2.0' | |
gem 'faker', '~>0.3.1' | |
gem 'rbench', '~>0.2.3' | |
require 'addressable/uri' |
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 'socket' | |
require 'rubygems' | |
require 'nokogiri' | |
PORT = rand(65535 - 1024) + 1024 | |
sthread = Thread.new { | |
s = TCPServer.new(PORT).accept | |
s.write('<foo>') |
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
def foo1 | |
yield | |
end | |
m = lambda { |&block| foo1(&block) } | |
m.call do | |
puts "i rock" | |
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 "intercession" | |
require "myapp" | |
require "myapp/session_extras" | |
use Rack::Session::Cookie, :secret => "I'll punchasize your face for FREE!" | |
use Intercession, MyApp::SessionExtras | |
run MyApp |
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 "intercession" | |
require "myapp" | |
require "myapp/session_extras" | |
use Rack::Session::Cookie, :secret => "I'll punchasize your face for FREE!" | |
use Intercession, MyApp::SessionExtras | |
run MyApp |
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 "intercession" | |
require "myapp" | |
require "myapp/session_extras" | |
use Rack::Session::Cookie, :secret => "I'll punchasize your face for FREE!" | |
use Intercession, MyApp::SessionExtras | |
run MyApp |
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 'nokogiri' | |
html = 'CA<br/>Sr Technical Architect' | |
fragment = Nokogiri::HTML::DocumentFragment.parse(html) | |
fragment.traverse do |child| | |
next unless 'br' == child.name | |
child.replace Nokogiri::XML::Text.new(' ', child.document) | |
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 'nokogiri' | |
doc = Nokogiri::XML(open("news.rss")) | |
content_tag = Nokogiri::XML::Node.new "content", doc | |
content_tag << doc.create_cdata("<<<<") | |
doc.at("//item/description").add_next_sibling(content_tag) |
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
if !defined?(JSON) | |
require 'yajl' | |
else | |
require 'json' | |
module Yajl | |
LOOKUP = Hash[%w[null boolean string bytes int long float double].map { |x| [x.inspect, x] }] | |
def self.dump obj | |
JSON.dump obj | |
end | |
def self.load string |
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
View: | |
- if favorite_comment.text.length < 45 | |
%p= favorite_comment.text | |
- else | |
= sample_with_more(favorite_comment.text, favorite_comment.id) | |
Helper: | |
def sample_with_more(body, comment_id, html_options = {}) | |
more_link = link_to(" »", :class => "show-more") |