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 / add-carrierwave.md
Created November 30, 2014 04:18
Add carrierwave integration.

open Gemfile

add gem ‘carrierwave’

bundle
rails g uploader Image
rails g migration add_image_to_product image:string
rake db:migrate
@chsh
chsh / koala.rb
Created December 10, 2014 03:04
Koala configuration to support Facebook API 2.0
Koala.config.api_version = 'v2.0'
@chsh
chsh / link_string.swift
Created December 28, 2014 17:16
Show link text on NSTextField for OS X by swift.
@chsh
chsh / run_bg.swift
Created December 31, 2014 08:34
Run NSTask in background for Swift
var taskQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)
dispatch_async(taskQueue, { () -> Void in
let task = NSTask()
task.launchPath = "/bin/ls"
task.arguments = []
let pipe = NSPipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
var dataString = NSString(data: data, encoding: NSUTF8StringEncoding)
@chsh
chsh / pg_pub_sub.rb
Last active June 6, 2025 20:51
PostgreSQL LISTEN/NOTIFY example for ruby
#
# A:
# pubsub = PgPubSub.new('channelname')
# pubsub.subscribe do |data|
# puts "data: #{data} is coming!"
# end
#
# B:
# pubsub = PgPubSub.new('channelname')
# pubsub.publish("hello world")
@chsh
chsh / paas.rb
Created January 23, 2015 03:44
Convert "PaaS" to "paas", "paas" to "PaaS" well.
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym 'PaaS'
end
@chsh
chsh / simple-jquery-example.js
Created January 23, 2015 14:31
Simple JavaScript module definition using jQuery.
// usage: call $.foobaa.initialize();
(function($) {
var hoge;
var moge;
var register_click_actions = function() {
$(hoge).show();
};
@chsh
chsh / ean.swift
Created January 29, 2015 14:45
Calc EAN for Swift
//
// EAN.swift
//
import Foundation
class EAN {
class func isValid(ean: String) -> Bool {
return EAN().isValid(ean)
}
@chsh
chsh / webpay.rb
Created February 12, 2015 04:06
Extend WebPay class to hold default configuration and apply to initialize a object.
class WebPay
alias_method :original_initialize, :initialize
Configuration = Struct.new :public_key, :secret_key
@@default_configuration = Configuration.new
def self.configuration; @@default_configuration end
def self.configure(&block)
block.call(@@default_configuration)
end
def initialize(options = {})
original_initialize(@@default_configuration.secret_key, options)
@chsh
chsh / text_extractor.rb
Last active August 29, 2015 14:15
Extract text from image using Google Drive API.
# gem 'google-api-client'
# gem 'mime-types'
#
# prepare config/ocr.yml
# default: &default
# google:
# auth_passphrase: <passphrase>
# auth_email: <email>
# permission: e.g. https://www.googleapis.com/auth/drive
#