Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Hiroshi Saito hiroshi

🏠
Working from home
View GitHub Profile
View rack_encoding_binary_fix.rb
# -*- coding: utf-8 -*-
# config/initializers/rack_encoding_binary_fix.rb
# 2010-07-04: @hiroshi3110, hiroshi3110@gmail.com, 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/
View application_controller.rb
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
View gawker_redirect_workaround.pac.js
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";
}
View AutoRef.h
#ifndef _AutoRef_h_
#define _AutoRef_h_
/* Example
#include "AutoRef.h"
void AutoRefRelease(CGImageRef ref) { CGImageRelease(ref); }
void someFunction(void) {
AutoRef<CGImage> image = CGImageCreateCopy(src);
View NSObject+AliasMethodChain.h
// -*- 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
@hiroshi
hiroshi / gist:927683
Created Apr 19, 2011
goo.gl Automator Service
View gist:927683
#!/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)
View processing_png.html
<!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)
View gist:985457
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
@hiroshi
hiroshi / gist:1001866
Created Jun 1, 2011
Rails 3.0 app + Mongoid による MongoHQ へのアクセスの実験
View gist:1001866

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

Rails app への Mongoid 導入

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

  • Mongoid の方が後発、
  • Mongoid の方が 2011/6 の段階で rails 3 対応、ドキュメントなどが充実しているらしい などの理由により、 Mogoid を使います。 (あまり詳しく調べてませんが、問題が発生したら乗り換えることもそんなに難しくないはず)
@hiroshi
hiroshi / Gitの手順.md
Created Jun 24, 2011 — forked from anonymous/Gitの手順
デザイナー向けのGitの手順。詳しくは http://kuroigamen.com にいろいろあります。
View Gitの手順.md
  1. リモートリポジトリをローカルにクローン(複製)します。

    git clone #{リモートリポジトリのURL}

  2. クローンしたディレクトリへ移動(Change Directry)

    cd #{ローカルパス}

  3. 必要なGemを一気にインストール