Skip to content

Instantly share code, notes, and snippets.

View yoshitsugu's full-sized avatar
🐐
bleat

Kota Yoshitsugu yoshitsugu

🐐
bleat
View GitHub Profile
@yoshitsugu
yoshitsugu / rsync_exclude_svn.sh
Last active December 15, 2015 05:29
rsync recursive
rsync -t -r --exclude='*.svn*' FROM_DIR/* TO_DIR/
@yoshitsugu
yoshitsugu / add_user_and_set_authrozed_keys.sh
Created June 6, 2013 05:51
add user and set authorized_keys
#! /bin/sh
USERNAME=<username>
ADMINGROUP='wheel'
AUTHKEYS=<authkeys>
useradd -m $USERNAME
usermod -G $ADMINGROUP $USERNAME
mkdir -p /home/$USERNAME/.ssh
echo $AUTHKEYS > /home/$USERNAME/.ssh/authorized_keys
chown -R $USERNAME:$USERNAME /home/$USERNAME
chmod 700 /home/$USERNAME/.ssh
@yoshitsugu
yoshitsugu / Gemfile
Created June 6, 2013 13:09
rspec + capybara で 非RailsのWebアプリをテスト ref: http://qiita.com/yoshitsugu/items/76e62ebff2ac244020a1
source "https://rubygems.org"
gem "rspec"
gem "capybara-mechanize" , "1.0.1"
page.driver.browser.agent.add_auth("https://example.com/" ,"usename","password")
@yoshitsugu
yoshitsugu / file.rb
Last active December 19, 2015 04:39
ファイルに含まれる日本語文字数をカウント ref: http://qiita.com/yoshitsugu@github/items/24b29384539af4ad69e8
count = 0
japanese_char = /(?:\p{Hiragana}|\p{Katakana}|[一-龠々])/
# ファイルの指定
targets = Dir.glob(TARGET_FILES)
# このエンコーディング以外はとばす
target_encodings = %w(UTF-8 Shift_JIS CP932)
targets.each{|t|
encoding = %x(nkf -g #{t}).chomp
if target_encodings.include? encoding
Spork.prefork do
...
RSpec.configure do |config|
....
# for database_clener
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation,{:except => %w{except_tables}})
DatabaseCleaner.strategy = :transaction
end
@yoshitsugu
yoshitsugu / gist:6068754
Created July 24, 2013 07:52
install後に編集された/etc以下のファイル一覧を表示
find /etc -type f -newer /root/install.log | xargs ls -alrt
@yoshitsugu
yoshitsugu / application_controller.rb
Last active December 20, 2015 06:39
rails application_controller set_locale
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_locale
protected
def set_locale
logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}"
I18n.locale = params[:locale] ||
extract_locale_from_accept_language_header ||
@yoshitsugu
yoshitsugu / reset_root_password.sql
Created July 29, 2013 06:23
reset root password on MySQL5.6
-- safeモードでmysql起動してから /usr/bin/mysqld_safe --user=root --skip-grant-tables
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
@yoshitsugu
yoshitsugu / zshrc
Created July 30, 2013 06:34
tramp+zshでうまく動かないときのzshrcの設定
# tramp+zshではうまく動かないときの設定
case "$TERM" in
dumb | emacs)
PROMPT="%m:%~> "
unsetopt zle
;;
esac