Skip to content

Instantly share code, notes, and snippets.

View hiroshi's full-sized avatar
🏠
Working from home

Hiroshi Saito hiroshi

🏠
Working from home
View GitHub Profile
// 1. Containing app - Store token url in the group user defaults.
DBAccount *account = [[DBAccountManager sharedManager] handleOpenURL:url];
if (account) {
NSUserDefaults *groupDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.example.app"];
[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:@"group.com.example.app"];
# http://tmont.com/blargh/2014/1/uploading-to-s3-in-bash
# file=xxxx
# bucket=xxxx
# s3Key=xxxx
# s3Secret=xxxx
resource=/${bucket}/${file}
contentType=binary/octet-stream
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}\
# -*- 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/
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";
}
@hiroshi
hiroshi / AutoRef.h
Created February 28, 2011 12:38
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);
// -*- 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 April 19, 2011 13:27
goo.gl Automator Service
#!/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)
@hiroshi
hiroshi / gist:1001866
Created June 1, 2011 06:16
Rails 3.0 app + Mongoid による MongoHQ へのアクセスの実験

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

Rails app への Mongoid 導入

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

  • Mongoid の方が後発、
  • Mongoid の方が 2011/6 の段階で rails 3 対応、ドキュメントなどが充実しているらしい などの理由により、 Mogoid を使います。 (あまり詳しく調べてませんが、問題が発生したら乗り換えることもそんなに難しくないはず)