Skip to content

Instantly share code, notes, and snippets.

require 'sinatra'
require 'net/https'
client_id = '2044a7773387915a7a2a'
client_secret = 'secret'
get '/' do
html = <<-EOS
<html>
<head>
@Epictetus
Epictetus / gist:2079615
Created March 18, 2012 18:45 — forked from hiroshi/gist:1001866
Rails 3.0 app + Mongoid による MongoHQ へのアクセスの実験

メモ - Mongoid による MongoHQ へのアクセスの実験

Rails app への Mongoid 導入

ruby/rails で MongoDB を使うときのメジャーな選択肢として MongoMapper, Mongoid がありますが、

  • Mongoid の方が後発、
  • Mongoid の方が 2011/6 の段階で rails 3 対応、ドキュメントなどが充実しているらしい などの理由により、 Mogoid を使います。 (あまり詳しく調べてませんが、問題が発生したら乗り換えることもそんなに難しくないはず)
@Epictetus
Epictetus / install.sh
Created March 18, 2012 01:56 — forked from keikubo/install.sh
Rails 3.2.2 Scaffolding on Rackhub.
# use node v0.7.4
nvm 0.7.4
# create a gemset for a sample application.
rvm gemset create scaffold_test
rvm gemset use scaffold_test
# install rails
gem install rails
@Epictetus
Epictetus / parallel_with_retry-handler.rb
Created March 15, 2012 18:44 — forked from kimoto/parallel_with_retry-handler.rb
parallel + retry-handlerのサンプルコード
Parallel.each(last_infos, :in_threads => 4){ |last_info|
begin
Proc.new do
timeout(20) do
Peercast::Screenshot.new(last_info.url).download_to(download_path)
end
last_info.capture = download_path
last_info.save
end.retry(:max => 3, :accept_exception => Timeout::Error, :logger => Logger.new(STDERR))
@Epictetus
Epictetus / gist:2045897
Created March 15, 2012 18:34 — forked from aereal/gist:2045252
rails g model とかで自動生成したあとにコミットをつくる
git add -A && git commit -m "Generate with: $ $(fc -ln -1)"

Proposal for Improving Mass Assignment

For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.

Sign Allowed Fields

When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.

To allow new known fields to be added via JS, we could add:

@Epictetus
Epictetus / 0-readme.md
Created March 8, 2012 06:32 — forked from burke/0-readme.md
ruby-1.9.3-p125 cumulative performance patch.

Patched ruby 1.9.3-p125 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p125 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Huge thanks to funny-falcon for the performance patches.

require 'eventmachine'
# most of code is from [thin-glazed](https://github.com/freelancing-god/thin-glazed)
class HttpClient < EventMachine::Connection
attr_reader :proxy
def initialize(proxy)
@proxy = proxy
@connected = EventMachine::DefaultDeferrable.new
@Epictetus
Epictetus / Action Mailer
Created March 6, 2012 12:05 — forked from holysugar/Action Mailer
Ruby on Rails v3.2.1 CHANGELOGs (in ja-JP)
## Rails 3.2.1 (January 26, 2012) ##
* 変更なし
javax.servlet.ServletContext log: unable to create shared application instance
org.jruby.rack.RackInitializationException: load error: ./config/boot -- java.lang.SecurityException: Google App Engine does not support Runtime.exec
from ./config/environment.rb:7
from ./config/environment.rb:13:in `require'
from config.ru:13