Skip to content

Instantly share code, notes, and snippets.

View chsh's full-sized avatar
👍
Love your code.

CHIKURA Shinsaku chsh

👍
Love your code.
View GitHub Profile
@chsh
chsh / app_delegate.rb
Created May 7, 2012 10:18
Example to use UIWebView for RubyMotion.
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
@window.rootViewController = GoogleViewController.alloc.init
@window.makeKeyAndVisible
true
end
end
@chsh
chsh / appapp_delegate.rb
Created May 10, 2012 08:41
RubyMotion Localization sample.
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
alert = UIAlertView.new
alert.message = t('start')
alert.show
true
end
def t(key)
NSBundle.mainBundle.localizedStringForKey(key, value:nil, table:nil)
@chsh
chsh / pdf_composer.rb
Created June 3, 2012 11:31
Compose multiple pdf files into one content or file.
require 'tempfile'
# usage:
# pc = PDFComposer.new(file_or_content1[, file_or_content2 ...])
# content = pc.compose # compose all into content
# pc.compose(to_file_path) # output to 'to_file_path' :-)
class PDFComposer
def initialize(*args)
@sources = args.flatten
@chsh
chsh / facebook-app-template.rb
Created June 17, 2012 04:44
Rails3 template to generate facebook app.
# facebootstrap: Rails3 template
app_h_name = app_name.gsub(/_/, '-')
app_c_name = app_name.classify
ruby_version = '1.9.3-p286'
repository_path = "[email protected]:chsh/#{app_h_name}.git"
target_branch = 'develop' # or master etc...
deploy_server = '[YOUR DEPLOY SERVER]'
target_mode = 'edge' # or 'live' or 'develop' etc...
# additional_path = '/usr/pgsql-9.1/bin'
@chsh
chsh / axlsx_example.rb
Created June 27, 2012 16:00
Example for Axslx (xlxs generator modudle)
require 'rubygems'
require 'axlsx'
rows = [
[1, "abc", Date.parse('2012/6/28')],
[2, "xyz"]
]
pkg = Axlsx::Package.new
pkg.workbook do |wb|
@chsh
chsh / geometry_support.rb
Created July 8, 2012 14:33
Add geometry calculation support for ActiveRecord using PostGIS.
# Add geometry calculation support.
# extend this module for ActiveRecord model.
module GeometrySupport
def by_distance_from_center(center, opts = {})
opts.reverse_merge! :meters => 500
cp = LatLng.from(center).to_point
sw_ne = boundary_from_meters(center,
opts[:meters]).map {|ll| ll.to_point}
cc = ComplexCondition.new
@chsh
chsh / git-release
Created August 7, 2012 03:36
Simplify git flow release command.
#!/bin/sh
pfx='rel'
d=`date +%Y%m%d%H%M%S`
git flow release start $pfx-$d
git flow release finish -m"Release:$d" $pfx-$d
@chsh
chsh / building-rails-env.txt
Created August 13, 2012 15:58
Note for preparing Rails env on Mac OS X.
* Install Xcode
App Store -> Search Xcode -> Download -> Install
* Install Command line tools
Launch Xcode -> Preferences -> Downloads -> Install command line tools
* Install Homebrew
$ ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
* Install rbenv ruby-build
@chsh
chsh / application_helper.rb
Created September 17, 2012 05:00
Use fragment cache in helper method.
module ApplicationHelper
def content_with_cache(key, content)
controller.read_fragment(key) ||
controller.write_fragment(key, content)
end
end
@chsh
chsh / nginx.conf
Created September 24, 2012 14:15
Partial nginx conf for php-fpm.
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fpm.www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SERVER_PORT 80;
fastcgi_param SERVER_NAME yourserver.com;
expires 2h;
}