Skip to content

Instantly share code, notes, and snippets.

View horitaku1124's full-sized avatar

Horimatsu Takuya horitaku1124

  • Tokyo
View GitHub Profile
@horitaku1124
horitaku1124 / commands.sh
Created April 11, 2013 10:52
コマンドを配列にして実行
#!/bin/bash
array=()
array+=(date)
array+=(ls)
array+=(pwd)
for e in ${array[@]}
do
echo ${e} | bash
@horitaku1124
horitaku1124 / commands2.sh
Created April 11, 2013 11:58
複数のコマンドを配列にして実行
#!/bin/bash
list=()
list+=("date '+%Y/%m/%d %H:%M:%S'")
list+=("date '+%Y-%m-%d %H:%M:%S'")
list+=("date '+%Y-%m-%d'")
for((i = 0; i < ${#list[@]}; i++))
do
echo ${list[$i]} | bash
@horitaku1124
horitaku1124 / echoip.sh
Created April 16, 2013 16:13
eth0のIPアドレスを表示
#!/bin/bash
ip=`ifconfig eth0 | sed -n "s/ *inet addr:\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/g p"`
echo ${ip}
@horitaku1124
horitaku1124 / composer.js
Last active December 16, 2015 08:18
Formにデータを入れるためのjs
var list = document.getElementsByTagName("input");
var kv = {};
for(var i = 0;i < list.length;i++) {
var name = list[i].getAttribute("name")
kv[name] = "";
}
var json = JSON.stringify(kv).replace(/","/g,"\"\n ,\"").replace(/^\{/,"{\n ").replace(/\}$/, "\n}");
// データを入れる
@horitaku1124
horitaku1124 / tips.js
Created April 21, 2013 12:10
JavaScriptの技
console.log(Math.random() * 10 | 0); // => 0 .. 9 in Integer
@horitaku1124
horitaku1124 / chpasswd.sh
Last active December 16, 2015 16:59
$ ./chpasswd user newpassword でuserのパスワードを変更
#!/bin/bash
expect -c "
set timeout 10
spawn passwd $1
expect \"新しいパスワード:\" {
send \"$2\n\"
expect \"新しいパスワードを再入力してください:\"
send \"$2\n\"
} \"New password:\" {
@horitaku1124
horitaku1124 / wp_setup.sh
Created May 10, 2013 16:09
Wordpressの自動設定(失敗版)
#!/bin/bash
WP_ROOT=/var/www
WP_SITE=http://wp-local/
MYSQL_LOGIN='-u root -ptest '
MYSQL='mysql '$MYSQL_LOGIN
MYSQLDUMP='mysqldump '$MYSQL_LOGIN
WP_DB=wp_db
MYSQL_WP_USER=wp_user
@horitaku1124
horitaku1124 / js-dom.md
Last active December 18, 2015 02:39
DOMを操作するときのjQueryとかのやりかた

チェックボックスがチェックされているか。

DOM
document.getElementById('id').checked
jQuery
$('#id').is(":checked");
@horitaku1124
horitaku1124 / setting_idea.md
Last active December 19, 2015 06:59
IntelliJ IDEAの初期設定

行以降にカーソルが移動しないように

Settings -> Editor -> Allow placement of caret after end of line

改行コード

File -> Settings -> Code Style -> General Line separator

行番号

Editor -> Appearance -> Show line numbers

@horitaku1124
horitaku1124 / date_format.js
Created July 8, 2013 01:56
JavaScriptで日付フォーマット
Date.prototype.format = function(str) {
var y = this.getFullYear();
var m = this.getMonth() + 1;
var d = this.getDate();
m = (m < 10 ? "0" : "") + m;
d = (d < 10 ? "0" : "") + d;
return str.replace(/Y/g, y).replace(/m/g, m).replace(/d/g, d);
};
console.log(new Date().format("Y-m-d"));