Skip to content

Instantly share code, notes, and snippets.

View tadyjp's full-sized avatar

tady (GitHub) tadyjp

View GitHub Profile
@tadyjp
tadyjp / normalize_string
Created November 27, 2013 00:39
改行、全角半角変換
require 'nkf'
# 文字列の正規化
def clean_string(str)
str = str.encode("UTF-8")
.gsub(/\r|\n/, '')
.gsub(/ /, ' ')
.gsub(/\s+/, ' ')
puts str
NKF.nkf('-WwXm0Z0', str)
@tadyjp
tadyjp / sk2ch.rb
Last active December 28, 2015 18:59
SkypeのチャットをリアルタイムにChatworkに転送するRubyスクリプト(更新:API利用版) ref: http://qiita.com/tady/items/b8ab289e315f2d08ffe0
require 'fileutils'
require 'sequel'
require 'faraday'
# Skypeのアカウント
SKYPE_NAME = 'skype.id'
# ChatworkのAPIトークン
CHATWORK_API_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
@tadyjp
tadyjp / crawl.rb
Last active December 28, 2015 08:09
Anemone gem (ruby) で指定したURLだけクロールする方法 ref: http://qiita.com/tady/items/8a954dfcd03521f8a200
require 'anemone'
Anemone.crawl('http://example.com/start_page.html') do |anemone|
# クロールするごとに呼び出される
anemone.focus_crawl do |page|
# 条件に一致するリンクだけ残す
# この `links` はanemoneが次にクロールする候補リスト
page.links.keep_if { |link|
@tadyjp
tadyjp / japanese-able-on-rails-c.sh
Created November 9, 2013 14:13
Rails c で日本語を入力可能にする.
install_name_tool -change /usr/lib/libedit.3.dylib /usr/local/Cellar/readline/6.2.4/lib/libreadline.dylib ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin12.4.0/readline.bundle
@tadyjp
tadyjp / git-clean.rake
Created November 3, 2013 02:43
gitのブランチを整理するrakeタスク
namespace :git do
desc 'remoteのmerge済みのbranchをすべて削除'
task clear_remote: :environment do
STDOUT.puts '[警告] remoteのmerge済みのbranchをすべて削除します [y/n]:'
input = STDIN.gets.chomp.downcase
if input == 'y'
system %q(git branch -a --merged | grep -v master | grep -v staging | grep -v develop | grep remotes/github| sed -e 's% *remotes/github/%%' | xargs -I% git push github :%)
else
@tadyjp
tadyjp / kuromoji.rb
Last active December 24, 2015 05:09
kuromojiを使いやすくるするruby. 同じフォルダにkuromoji-xxx.jarが必要.
require 'rjb'
class Kuromoji
Rjb::load(File.expand_path('../kuromoji-0.8-SNAPSHOT.jar', __FILE__))
module JavaIterator
def each
i = self.iterator
while i.has_next
@tadyjp
tadyjp / php_install.sh
Created January 8, 2013 12:40
php 5.3
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --disable-all --enable-libxml --with-libxml-dir=/usr/local --enable-zend-multibyte --with-regex=php --enable-filter --with-pcre-regex=yes --with-mysql=/usr/local/mysql --with-gd --with-jpeg-dir --enable-session --enable-mbstring --enable-xml --enable-json --enable-sockets --with-zlib --with-zlib-dir=/usr/lib --with-curl
@tadyjp
tadyjp / Preferences.sublime-settings.json
Last active December 21, 2015 02:34
SublimeText3 config file
{
"auto_indent": true,
"bold_folder_labels": true,
"color_scheme": "Packages/User/SublimeLinter/Monokai (SL).tmTheme",
"caret_style": "phase",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"fade_fold_buttons": false,
"font_face": "Ricty",
"font_size": 11,
@tadyjp
tadyjp / init_db.sh
Created October 14, 2012 22:43
Init script for mysql with RoR3 (Rails用Mysql初期化スクリプト)
#! /bin/sh
echo "データベースを初期化します"
echo "この操作は取り消せません"
echo "mysqlを起動してください"
echo "mysqlのrootパスワードを入力してください"
APP_NAME="appname"
SQL_FILE=`dirname ${0}`/../db/sql/${APP_NAME}_development.sql # <= DBの初期化SQLを用意
@tadyjp
tadyjp / ruby.py
Created October 12, 2012 12:14
Sublime Text2のSublimeLinterでruby1.9のハッシュリテラル("key: value"形式)をSyntax Errorを回避方法 ref: http://qiita.com/items/a2d18686343cb1881031
CONFIG = {
'language': 'Ruby',
# 'executable': 'ruby',
'executable': '/Users/<ユーザー名>/.rvm/rubies/ruby-1.9.3-p194/bin/ruby',
'lint_args': '-wc'
}
```
以上で、煩わしい偽Syntax Errorを回避できる。