Skip to content

Instantly share code, notes, and snippets.

View yuki24's full-sized avatar
🔢
NaN :trollface:

Yuki Nishijima yuki24

🔢
NaN :trollface:
View GitHub Profile
@yuki24
yuki24 / duplex.rb
Created July 20, 2012 05:37
a snipept for something
require 'em-proxy'
Proxy.start(host: "127.0.0.1", port: 8000, debug: false) do |conn|
conn.server :server1, host: "127.0.0.1", port: 3000
conn.server :server2, host: "127.0.0.1", port: 3001
conn.on_data do |data|
data
end
@yuki24
yuki24 / moped_examples.rb
Created July 24, 2012 10:54
moped examples
session = Moped::Session.new(["127.0.0.1:27017"], database: "mongodb")
session[:collection].find.one
# => {
# "_id"=>"500b7c0d1d41c81647000016",
# "name"=>"a photo",
# "updated_at"=>2012-07-22 04:05:33 UTC,
# "created_at"=>2012-07-22 04:05:33 UTC
# }
session[:collection].find.select(name: false).one
@yuki24
yuki24 / ab.txt
Created August 14, 2012 16:59
benchmark for a wordpress-based website
yuki@ubuntu:~$ ab -n 1000 -c 100 http://randb2012.misscon.net/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking randb2012.misscon.net (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
@yuki24
yuki24 / like_check.rb
Created October 11, 2012 14:07
how to check if the user likes the given url/id of the page or not.
@client = Koala::Facebook::API.new(access_token)
# Check if the user likes the given url or not.
url = "http://example.com"
@client.fql_query("SELECT url FROM url_like WHERE user_id=me()").map do |like|
like["url"]
end.include?(url)
# Get how many likes the url got.
@client.fql_query("SELECT like_count FROM link_stat WHERE url=\"#{url}\"")["like_count"]
@yuki24
yuki24 / better_tap.rb
Created October 11, 2012 15:01
Better Object#tap
class Object
def tap(method = nil, *args, &block)
return super() if method.nil? && args.empty? && block_given?
public_send(method, *args)
self
end
end
@yuki24
yuki24 / jbuilder_extension.rb
Created October 11, 2012 17:15
a patch to get jbuilder to work with active_decorator on Rails.
# lib/jbuilder_ext/object_methods.rb
module JbuilderExt
module ObjectMethods
def __class__
(class << self; self; end).superclass
end
def is_a?(klass)
klass == __class__
end
@yuki24
yuki24 / Gemfile.diff
Created October 16, 2012 18:04
upgrade sprockets
source 'https://rubygems.org'
ruby '1.9.3'
-gem 'rails', '3.2.8'
+gem 'rails', git: "git://github.com/rails/rails.git", branch: "3-2-stable"
gem 'thin'
gem 'pg'
...
@yuki24
yuki24 / Gemfile
Created October 23, 2012 12:41
How to get kaminari work with twitter bootstrap nicely
gem "kaminari"
gem "twitter-bootstrap-rails", :group => :assets
@yuki24
yuki24 / Gemfile
Last active April 16, 2016 20:05
Jbuilder is faster than Ralb.
source 'https://rubygems.org'
gem 'benchmark-ips'
gem 'activesupport'
gem 'jbuilder'
gem 'rabl'
gem 'oj'
@yuki24
yuki24 / depends
Created February 7, 2013 13:32
ruby 2.0.0dev fails to compile an extension.
nothing.o: nothing.c