メモ - Mongoid による MongoHQ へのアクセスの実験
ruby/rails で MongoDB を使うときのメジャーな選択肢として MongoMapper, Mongoid がありますが、
- Mongoid の方が後発、
- Mongoid の方が 2011/6 の段階で rails 3 対応、ドキュメントなどが充実しているらしい などの理由により、 Mogoid を使います。 (あまり詳しく調べてませんが、問題が発生したら乗り換えることもそんなに難しくないはず)
| # -*- coding: utf-8 -*- | |
| # config/initializers/rack_encoding_binary_fix.rb | |
| # 2010-07-04: @hiroshi3110, [email protected], http://github.com/hiroshi | |
| # I wrote this for Rails 3 beta 4 / Ruby 1.9.2-pre3. | |
| # This is a VERY nasty patch for work arounding rack's Encoding::BINARY (ASCII-8BIT) rack.input issue. | |
| # I don't know the RIGHT solution about the issue, but I have to fix: | |
| # Encoding::UndefinedConversionError ("\xE3" from ASCII-8BIT to UTF-8) | |
| # Sometime in the future, I hope this is no use... | |
| # References: | |
| # wycats pointed at "Where it doesn’t work" in http://yehudakatz.com/2010/05/17/encodings-unabridged/ |
| class ApplicationController < ActionController::Base | |
| # FORCE to implement content_for in controller | |
| # I'm not sure that this works with rails < 3.0.0rc | |
| def view_context | |
| super.tap do |view| | |
| (@_content_for || {}).each do |name,content| | |
| view.content_for name, content | |
| end | |
| end | |
| end |
| function FindProxyForURL(url, host) { | |
| if (shExpMatch(url, "lifehacker.com/*")){ | |
| return "PROXY us.lifehacker.com"; | |
| } | |
| if (shExpMatch(url, "gizmodo.com/*")){ | |
| return "PROXY us.gizmodo.com"; | |
| } | |
| return "DIRECT"; | |
| } |
| #ifndef _AutoRef_h_ | |
| #define _AutoRef_h_ | |
| /* Example | |
| #include "AutoRef.h" | |
| void AutoRefRelease(CGImageRef ref) { CGImageRelease(ref); } | |
| void someFunction(void) { | |
| AutoRef<CGImage> image = CGImageCreateCopy(src); |
| // -*- ObjC -*- | |
| // Hiroshi Saito / Yakitara.com | |
| /* | |
| You know OCMock does great, but (If I'm not get wrong with it) | |
| - it will supposed to be used in tests not a production code | |
| - it can't mock class methods | |
| - it requires an instace to be mocked accessible in your tests | |
| If you not familiar with alias_method_chain, see: | |
| https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/module/aliasing.rb |
| #!/bin/sh | |
| # 0. Requires Mac OS X 10.6 (Snow Leopard) or later | |
| # 1. Open Automator.app | |
| # 2. Choose "Service" template | |
| # 3. Enter "shell" and drag & drop "Run Shell Script" | |
| # 4. Check "Replaces selected text" | |
| # 5. Ensure that Shell: "/bin/bash" and Pass input: "to stdin" | |
| # 6. Paste ***ENTIRE THIS SCRIPT*** to the textarea | |
| # 7. Save the service as "goo.gl" or what you like | |
| url=$(cat /dev/stdin) |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>processing png</title> | |
| <script src="http://processingjs.org/content/download/processing-js-1.1.0/processing-1.1.0.min.js"></script> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> | |
| </head> | |
| <body> | |
| <div> | |
| <canvas width="0" height="0"></canvas> (Canvas) |
| class ApplicationController < ActionController::Base | |
| ... | |
| # FORCE to implement content_for in controller | |
| def view_context | |
| super.tap do |view| | |
| (@_content_for || {}).each do |name,content| | |
| view.content_for name, content | |
| end | |
| end | |
| end |
リモートリポジトリをローカルにクローン(複製)します。
git clone #{リモートリポジトリのURL}
クローンしたディレクトリへ移動(Change Directry)
cd #{ローカルパス}
必要なGemを一気にインストール