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 / aws_ses_mail.rb
Created May 25, 2015 06:59
Set AWS region for SES without global settings.
# Gemfile:
# gem 'aws-sdk-rails'
#
credentials = Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
Aws::Rails.add_action_mailer_delivery_method(
:aws_sdk,
credentials: credentials, region: 'us-west-2'
)
ActionMailer::Base.delivery_method = :aws_sdk
@chsh
chsh / gist:7adaf9824179bd02a8bf
Created May 25, 2015 06:59
Set SES region without global settings.
# Gemfile:
# gem 'aws-sdk-rails'
#
credentials = Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
Aws::Rails.add_action_mailer_delivery_method(
:aws_sdk,
credentials: credentials, region: 'us-west-2'
)
ActionMailer::Base.delivery_method = :aws_sdk
@chsh
chsh / git-clean-branch
Created March 17, 2015 02:16
git: remove merged branches with confirmation.
#!/bin/bash
read -p "Do you wish to remove merged branches? " yn
case $yn in
[Yy]* ) echo "Removing merged branches..."; break;;
* ) echo "Nothing to do."; exit;;
esac
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
@chsh
chsh / .pryrc
Last active August 29, 2015 14:15
Create pry history separated per current directory
# save pry history separated by current directory.
require 'digest/md5'
require 'fileutils'
history_base = File.join(ENV['HOME'], '.pry', 'histories')
FileUtils.mkdir_p history_base unless Dir.exist? history_base
pwd_hash = Digest::MD5.hexdigest(`pwd`.chomp)
Pry.config.history.file = File.join(history_base, pwd_hash)
@chsh
chsh / barcode_helper.rb
Created February 20, 2015 16:50
Generate barcode SVG for ruby
# include BarcodeHelper
# call svg_barcode method in view
# e.g. <p><%= svg_barcode('12345') %></p>
# You shouuld implement Barcode class whith returns barcode encoding from string.
module BarcodeHelper
def svg_barcode(token, options = {})
xdim = (options[:xdim] || 2).to_i
margin = pick_margin_from(options)
@chsh
chsh / draw_barcode.js
Created February 20, 2015 15:12
Draw barcode using d3.
//= require d3
var height = 500;
var width = 800;
var margin_left = 20;
var xdim = 2;
var svgContianer = d3.select("body")
.append("svg")
.attr("width", width)
@chsh
chsh / looper.js
Last active August 29, 2015 14:15
example
/* usage
if (!$.looper.is_running()) {
$.looper.initialize({
action: function() {
$('#notification-marker')
.animate({opacity: 1}, 800)
.animate({opacity: 0}, 800);
},
timeout: 1600
@chsh
chsh / git-release.sh
Created February 18, 2015 06:52
git release shell
#!/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 / 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
#
@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)