Skip to content

Instantly share code, notes, and snippets.

Shohei Yamasaki shoyan

Block or report user

Report or block shoyan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@shoyan
shoyan / nihongo_validate.js
Created Dec 5, 2012
jsの日本語バリデーションサンプル
View nihongo_validate.js
var wPat = "[a-zA-Z0-9-]"; // 英数字・ハイフン
wPat += "|[\u3041-\u3093]"; // ひらがな
wPat += "|[\u30A1-\u30F6]"; // カタカナ
wPat += "|[・ヽヾゝゞ々ー]"; // 記号
wPat += "|[\u4E00-\u9FFF]"; //漢字
wPat = "^(" + wPat +")+$";
if (!str.match(wPat)) {
return false;
}
@shoyan
shoyan / wait_process.sh
Last active Nov 26, 2018
別プロセスの結果を取得するシェルスクリプトのサンプル
View wait_process.sh
#!/bin/bash
command1() {
echo "executing commnad1"
sleep 3
}
command2() {
echo "executing commnad2"
sleep 3
@shoyan
shoyan / 8hour45min.ruby
Last active Oct 16, 2018
今から8時間45分後を計算する
View 8hour45min.ruby
# 時刻を加算するにはRationalを足す。
# 1分後はRational(1, 24*60)
# 8時間45分は525分なのでRational(525, 24*60)を加算すればよい
DateTime.now + Rational(525,24*60)
@shoyan
shoyan / chat_postmessage_sample.rb
Created Oct 28, 2016
chat.postMessage sample for Slack
View chat_postmessage_sample.rb
require "faraday"
username = 'your name'
channel = 'your channel'
slack_token = 'your slack token'
icon_url = 'your icon url'
body = {
username: username,
channel: channel,
@shoyan
shoyan / wordpress.sh
Created Aug 18, 2016
WordPressのアーカイブを作成するスクリプト
View wordpress.sh
#!/bin/bash
#
# WordPressのアーカイブを作成するスクリプトです。
# 指定されたWordPressのバージョンにSiteGuardプラグインをいれて、アーカイブを作成します。
#
# Usage:
# ./wordpress.sh version
#
# Example:
# ./wordpress.sh 4.1.1
@shoyan
shoyan / entropy
Last active Jun 30, 2016
エントロピーを計算するツール
View entropy
#!/usr/bin/env ruby
# Usage
# ./entropy file
# echo "aaaaaaaabbbbbbbbbcc" | ./entropy
require 'optparse'
options = {}
@shoyan
shoyan / entropy.rb
Created Jun 24, 2016
雑なエントロピーの計算
View entropy.rb
str="abccddeeeeffffgggggggghhhhhhhh"
def entropy(str)
count = str.size
list={}
list.default=0
str.split("").each {|c| list[c]+=1}
sum = 0
list.each do |key, val|
@shoyan
shoyan / word_count.rb
Created Mar 22, 2016
単語数の出現回数をカウントする
View word_count.rb
text =<<TEXT
The example above works as intended because the five instances of the (anonymous) inner function refer to five different instances of variable j. Note that it does not work as intended if you replace let by var or if you remove the variable j and simply use the variable i in the inner function.
TEXT
result = {}
result.default = 0
text.split(" ").map { |a| a.gsub(/\.$/, '').gsub(/\(|\)/, '').downcase }.sort.each { |b| result[b.to_sym]+=1 }
p result.sort {|(k1, v1), (k2, v2)| v2 <=> v1 }
@shoyan
shoyan / Dockerfile
Created Mar 9, 2016
Dockerfile to build php5.2.
View Dockerfile
FROM ubuntu
MAINTAINER shoyan
USER root
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get -y install build-essential
RUN apt-get -y install libxml2-dev
RUN apt-get -y install wget
View sql_practice_20130928.sql
UPDATE class_A SET sex_code =1;
SELECT * FROM class_A;
UPDATE class_A SET sex_code = 2 WHERE id IN (3,4);
-- sex_codeをわかりやすく出力する
SELECT name,
CASE sex_code
WHEN 1 THEN 'Male'
You can’t perform that action at this time.