Skip to content

Instantly share code, notes, and snippets.

View gaishimo's full-sized avatar
🏠
Coding 💻

gaishimo gaishimo

🏠
Coding 💻
View GitHub Profile
@gaishimo
gaishimo / check_include_space
Created July 22, 2013 03:13
文字列がスペースを含んでいるかをチェックする
/\s+/.test('aaa bbb')
@gaishimo
gaishimo / shift_loop.js
Created July 22, 2013 04:32
shiftを使ったループ
while (arr = arr.shift()) {
}
@gaishimo
gaishimo / jsonp_sample_client.js
Created July 22, 2013 08:11
jsonpのサンプル (クライアント側)
var JSONP_API = {};
function loadJS(src){
var script = document.createElement('script');
script.src = src;
var body = document.body;
body.appendChild(script);
}
JSONP_API.callback1 = function(data){
@gaishimo
gaishimo / html5_fileapi.js
Created July 23, 2013 03:52
HTML5 FILE APIのテキストファイル読み込みサンプル
var onFileSelect = function(ev){
var file = ev.target.files[0];
var reader = new FileReader();
reader.readAsText(file, 'UTF-8');
reader.onload = function(ev){
var i, l;
var txt = ev.target.result;
var lines = txt.split(/\r\n/);
for( i = 0, l= lines.length; i < l; i++ ){
@gaishimo
gaishimo / num_check.rb
Created July 23, 2013 08:00
文字列の数値チェック
unless /\A-?\d+\Z/ =~ num
@gaishimo
gaishimo / random_text.rb
Created July 27, 2013 11:44
ランダム文字列を返す
('a'..'z').to_a.shuffle[0..7].join
@gaishimo
gaishimo / expand_path.rb
Created July 31, 2013 09:16
相対パスを絶対パスに変換
File.expand_path("../../config/environment", __FILE__)
@gaishimo
gaishimo / mysql_direct_sql.sh
Created August 2, 2013 07:22
MySQLでコマンドラインから直接SQLを実行
mysql -uroot -h127.0.0.1 dbname -e'show tables;'
@gaishimo
gaishimo / set_timezone.sql
Created August 3, 2013 01:37
My SQLのタイムゾーン設定
SHOW VARIABLES like '%time_zone%';
SET GLOBAL time_zone = '+9:00';
@gaishimo
gaishimo / render.rb
Created August 3, 2013 10:49
Controller : render
respond_to do |format|
if @magazine.save
format.html { redirect_to @magazine, notice: 'Magazine was successfully created.' }
format.json { render json: @magazine, status: :created, location: @magazine }
else
format.html { render action: "new" }
format.json { render json: @magazine.errors, status: :unprocessable_entity }
end
end