Skip to content

Instantly share code, notes, and snippets.

View fujimura's full-sized avatar

Daisuke Fujimura fujimura

View GitHub Profile
@fujimura
fujimura / fbg.rb
Created November 19, 2010 06:44
fbg.rb
module FBG
class Client
BASE_URI = 'https://graph.facebook.com/'
def initialize(token)
@token = token
end
def get(path)
params = {:access_token => URI.escape(@token)}
ActiveSupport::JSON.decode RestClient.get(BASE_URI + path, :params => params)
end
@fujimura
fujimura / fb_controller.rb
Created November 19, 2010 08:56
fb_controller.rb
class FbController < ApplicationController
def index
result = fbg_client.get params[:id]
render :text => result[params[:key]]
end
end
@fujimura
fujimura / fbg.js
Created November 19, 2010 08:57
fbg.js
function init() {
$('span[data-fb-uid] a').each(function(i){
$(this).one('ajax:success', function(ev, response){
$(this).replaceWith(response);
});
$(this).callRemote();
var a = this;
setInterval(function(){
var v = $(a).html();
$(a).html(v + '.');
@fujimura
fujimura / application_helper.rb
Created November 19, 2010 08:58
application_helper.rb
module ApplicationHelper
def fb_user_tag(user)
content_tag :span, 'data-fb-uid' => user.uid, 'data-fb-key' => 'name' do
link_to ".", fb_path(:id => user.uid, :key => 'name'), :remote => true
end
end
end
@fujimura
fujimura / seven-languages-in-seven-weeks_io_day-2_3.io
Created December 22, 2010 03:18
seven-languages-in-seven-weeks_io_day-2_3.io
List sumr := method(if((first type == "List"),
first sumr + rest sumr,
if((size == 0),
0,
if((size == 1),
first,
first + rest sumr
))))
@fujimura
fujimura / matcher_for_before_filter.rb
Created December 24, 2010 10:30
matcher_for_before_filter.rb
# original idea is by @a_matsuda.
# it { should filter(:update).by :require_session }
# => should filter update by require_session
RSpec::Matchers.define :filter do |action_name|
action_name = action_name.to_s
match do
callbacks = controller._process_action_callbacks.select { |c| c.kind == :before && @method_names.include?(c.filter.to_s)}
if callbacks.count != @method_names.count || callbacks.empty?
@fujimura
fujimura / my.erl
Created January 12, 2011 11:07
7L7W, erlang, day2.
-module(my).
-export([wordnum/1]).
-export([count_to_10/0]).
-export([value_at/2]).
-export([checkout/1]).
wordnum([]) -> 0;
wordnum(W) -> [_|Tail] = W, wordnum(Tail) + 1.
euc = -> a, b { a % b == 0 ? b : euc[b, a % b]}
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
def instrument
memory_before = `ps -o rss= #{$$}`
RubyProf.start
yield
result = RubyProf.stop
memory_after = `ps -o rss= #{$$}`
p "Memory before: #{memory_before.chomp}"
p "Memory after: #{memory_after.chomp}"
printer = RubyProf::FlatPrinter.new(result)
printer.print(STDOUT, 0)