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 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 |
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 FbController < ApplicationController | |
def index | |
result = fbg_client.get params[:id] | |
render :text => result[params[:key]] | |
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
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 + '.'); |
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 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 |
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
List sumr := method(if((first type == "List"), | |
first sumr + rest sumr, | |
if((size == 0), | |
0, | |
if((size == 1), | |
first, | |
first + rest sumr | |
)))) |
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
# 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? |
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(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. |
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
euc = -> a, b { a % b == 0 ? b : euc[b, a % b]} |
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
# 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| |
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 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) |