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 / iconic_font_helper.rb
Created March 5, 2012 16:52
Iconic font helper for rails.
module IconicFontHelper
ICONIC_FONT_NAMES = {
hash: '#',
question_mark: '?',
at: '@',
pilcrow: '¶',
info: 'ℹ',
arrow_left: '←',
arrow_up: '↑',
arrow_right: '→',
@chsh
chsh / audio_tag_fix.rb
Created March 10, 2012 14:43
audio_tag does not generate correct path to assets in production. (Rails 3.2.2)
module ApplicationHelper
def audio_tag(source, options = {})
options.symbolize_keys!
# originally defined as audio_path(source) but it doesn't work...
options[:src] = path_to_asset(source)
tag("audio", options)
end
end
@chsh
chsh / unicorn.rb
Created March 25, 2012 04:41
unicorn.rb for Rails application template.
# unicorn_rails -c /srv/myapp/current/config/unicorn.rb -E production -D
#
shared_dir = "#{ENV['DEPLOY_ROOT']}/shared"
deploy_name = ENV['DEPLOY_ROOT'].gsub(/^.+\//, '')
working_directory ENV['RAILS_ROOT']
# worker_processes (rails_env == 'production' ? 10 : 4)
preload_app true
timeout 30
@chsh
chsh / omniauth_callbacks_controller.rb
Created March 25, 2012 04:56
OmniauthCallbacksController for Facebook.
class Users::OmniauthCallbacksController < ApplicationController
def facebook
# You need to implement the method below in your model
@user = User.find_for_facebook_oauth(env["omniauth.auth"])
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.facebook_data"] = env["omniauth.auth"]
@chsh
chsh / sessions_controller.rb
Created March 25, 2012 04:57
Omniauth SessionsController supports only facebook.
class Users::SessionsController < Devise::SessionsController
def new
redirect_to '/users/auth/facebook'
end
end
@chsh
chsh / git-release.sh
Created March 29, 2012 14:40
Shorten git flow's release operations. ;-)
#!/bin/sh
prefix=''
d=`date +%Y%m%d%H%M%S`
git flow release start $prefix-$d
git flow release finish -m"Release:$d" $prefix-$d
@chsh
chsh / hash_pathable.rb
Created April 1, 2012 16:04
Add Hash#path method to traverse like xpath
# GenericUtils
module GenericSupport
module Pathable
module ClassMethods
def path(hash, *pathes)
target = hash
pathes.map! do |p|
p.to_s.split(/[\/\.]+/)
end
pathes.flatten.each do |element|
@chsh
chsh / fa-icon-external-link.css
Created April 9, 2012 05:32
Show icon after external link using Font Awesome
@chsh
chsh / non_active_record_model.rb
Last active October 3, 2015 02:28
It's my reminder. I always forget this. ;-)
class NonActiveRecordModel
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
def persisted?; false end
def initialize(hash = {})
hash.each do |key, value|
m = "#{key}="
@chsh
chsh / image_ext_map.rb
Created May 4, 2012 03:03
Image content-type to file extension.
{
'image/bmp' => '.bmp',
'image/cgm' => '.cgm',
'image/gif' => '.gif',
'image/ief' => '.ief',
'image/jpeg' => '.jpg',
'image/png' => '.png',
'image/svg+xml' => '.svg',
'image/tiff' => '.tif',