Skip to content

Instantly share code, notes, and snippets.

View moreta's full-sized avatar

JungJoo Seo moreta

  • Brakio
  • Japan
View GitHub Profile
@moreta
moreta / sssh
Created February 9, 2012 16:39
sssh(ssh自動ログイン)
#!/bin/sh
# 実行例1:sssh を実行すると ~/bin/server_list の一覧からserver選択して自動ssh接続
# 実行例2:sssh $server を実行すると ssh $ssh_user@$server を実行する
ssh_user="ssh user"
ssh_pass="ssh password"
ssh_login(){
if [ $# -ne 1 ]; then
@moreta
moreta / git-color
Created April 20, 2012 11:03
git color option
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.interactive auto
class CreatePdmRevisions < ActiveRecord::Migration
def self.up
create_table :pdm_revisions do |t|
t.column :commit_message, :string
t.column :attachment, :string
t.column :created_by, :string
t.column :created_date, :datetime
t.column :document_type, :string
t.column :pdm_document_id, :int
end
@moreta
moreta / known_ssh_hosts.sh
Created May 21, 2012 06:57
$HOME/.ssh/configに設定しているホストをリストアップ
$ cat known_ssh_hosts.sh
#!/bin/sh
# see : http://d.hatena.ne.jp/youhey/20110112/1294830362
SSH_CONFIG=$HOME/.ssh/config
echo "known hosts:"
if test -f $SSH_CONFIG; then
@moreta
moreta / init-nginx.sh
Created August 17, 2012 07:12
nginx source install init script
#!/bin/sh
#
# nginx – this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /opt/nginx/conf/nginx.conf
# pidfile: /opt/nginx/logs/nginx.pid
@moreta
moreta / ruby_nomalize.rb
Created October 23, 2012 15:16
ruby nomalize
# credit cart number
def normalize_credit_card_number
self.cc_number.gsub!(/[-\s]/, '')
end
@moreta
moreta / ruby_localization_jp.rb
Created October 23, 2012 15:17
ruby japaness helper
# encoding: utf-8
s = "こんにちは"
puts s.tr("あ-ん", "ア-ン")
@moreta
moreta / encrypt.rb
Created October 23, 2012 15:22
ActiveRecord Encrypter
class Encrypter
# We're passed a list of attributes that should # be stored encrypted in the database
def initialize(attrs_to_manage)
@attrs_to_manage = attrs_to_manage
end
# Before saving or updating, encrypt the fields using the NSA and # DHS approved Shift Cipher
def before_save(model)
@attrs_to_manage.each do |field| model[field].tr!("a-z", "b-za")
end end
# After saving, decrypt them back
#railsでsaveをするときにerrorをcountingしてredirectする。
def save
order = Order.new(params[:order]) if order.save
redirect_to action: "display" else
session[:error_count] ||= 0 session[:error_count] += 1 if session[:error_count] < 4
self.notice = "Please try again" else
# Give up -- user is clearly struggling
redirect_to("/help/order_entry.html") end
end end
@moreta
moreta / tableless.rb
Created October 29, 2012 12:22 — forked from matpowel/tableless.rb
An ActiveRecord emulating Tableless model which works with Rails 3.1
class Tableless < ActiveRecord::Base
def self.column(name, sql_type = nil, default = nil, null = true)
columns << ActiveRecord::ConnectionAdapters::Column.new( name.to_s, default, sql_type.to_s, null )
end
def self.columns()
@columns ||= [];
end