Skip to content

Instantly share code, notes, and snippets.

Working from home

Hiroshi Saito hiroshi

Working from home
View GitHub Profile
View gist:463cc08705c61f92d2c9
// 1. Containing app - Store token url in the group user defaults.
DBAccount *account = [[DBAccountManager sharedManager] handleOpenURL:url];
if (account) {
NSUserDefaults *groupDefaults = [[NSUserDefaults alloc] initWithSuiteName:@""];
[groupDefaults setObject:url.absoluteString forKey:@"dropbox.token.url"];
[groupDefaults synchronize];
// 2. An Extension - Retrieve the token url from group user defaults, then give it to -[DBAccountManager handleOpenURL:] after setting "nonce".
NSUserDefaults *groupDefaults = [[NSUserDefaults alloc] initWithSuiteName:@""];
View Makefile
# file=xxxx
# bucket=xxxx
# s3Key=xxxx
# s3Secret=xxxx
dateValue := $(shell date "+%a, %d %b %Y %H:%M:%S %z")
SHELL=bash # Enable echo -ne option
signature:=$(shell echo -ne "PUT\n\n${contentType}\
View rack_encoding_binary_fix.rb
# -*- coding: utf-8 -*-
# config/initializers/rack_encoding_binary_fix.rb
# 2010-07-04: @hiroshi3110,,
# 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
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
View gawker_redirect_workaround.pac.js
function FindProxyForURL(url, host) {
if (shExpMatch(url, "*")){
return "PROXY";
if (shExpMatch(url, "*")){
return "PROXY";
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 /
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:
hiroshi / gist:927683
Created Apr 19, 2011 Automator Service
View gist:927683
# 0. Requires Mac OS X 10.6 (Snow Leopard) or later
# 1. Open
# 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 "" or what you like
url=$(cat /dev/stdin)
View processing_png.html
<!DOCTYPE html>
<title>processing png</title>
<script src=""></script>
<script src=""></script>
<canvas width="0" height="0"></canvas> (Canvas)
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 を使います。 (あまり詳しく調べてませんが、問題が発生したら乗り換えることもそんなに難しくないはず)