Skip to content

Instantly share code, notes, and snippets.

@pataiji
pataiji / README.md
Last active January 10, 2018 06:42
db_info.sh [-d database_name] [-t table_name] [-c column_name] でスキーマを参照できる。

Usage

$ db_info.sh -d test_db -c hoge_column%
+------------+--------------+-------------+-------------+----------------+
| TABLE_NAME | COLUMN_NAME  | COLUMN_TYPE | IS_NULLABLE | COLUMN_DEFAULT |
+------------+--------------+-------------+-------------+----------------+
| table_1    | hoge_column1 | int(11)     | NO          | NULL           |
| table_3    | hoge_column1 | int(11)     | NO          | NULL           |
| table_10   | hoge_column2 | int(11)     | NO          | NULL           |
+------------+--------------+-------------+-------------+----------------+
@pataiji
pataiji / s3_sync_iam_policy
Created May 2, 2014 01:36
aws s3 sync を叩くための IAM Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Action": [
"s3:DeleteObject",
"s3:GetObject",
"s3:PutObject"
@pataiji
pataiji / db_truncate_tables.sh
Created May 14, 2014 09:55
テーブルの一括削除のメモ
#!/bin/bash
function db_truncate_tables {
database=$1
/usr/local/bin/mysql -u root -D $database -e 'show tables;' | \
cut -f 2 | grep -v Tables_in_ | \
xargs -I "@@" mysql -u root -D $database -e "set foreign_key_checks=0; DROP TABLE \`@@\`; set foreign_key_checks = 1;"
}
@pataiji
pataiji / index.html.slim
Created July 11, 2014 10:30
monkeypatch of wice_grid for draper support ( Inspired from https://github.com/leikind/wice_grid/issues/120 )
== grid(@posts_grid) do |g|
- g.column attribute: 'title'
- g.column name: 'body' do |u|
- u.truncated_body
@pataiji
pataiji / 1.HOWTO.md
Last active February 29, 2020 22:46
S3 + CloudFront で特定のパスへのアクセスをリダイレクトさせる
  1. S3の'Static Website Hosting'を有効にする
  2. 'Edit Redirection Rules'を編集する
  3. 'bucket policy'を編集する
  4. CLoudFrontのOriginにS3の'Static Website Hosting'のEndpointを指定する
@pataiji
pataiji / get_latest_amazon_linux_ami_id.sh
Last active August 29, 2015 14:05
最新のAmzon LinuxのAMI ID一覧を取得する
#!/bin/bash
REGIONS=( \
"us-east-1" \
"us-west-1" \
"us-west-2" \
"eu-west-1" \
"sa-east-1" \
"ap-southeast-1" \
"ap-southeast-2" \
@pataiji
pataiji / get_az.sh
Created August 11, 2014 00:58
EC2のリージョン一覧を取得する
#!/bin/bash
REGIONS=( \
"us-east-1" \
"us-west-1" \
"us-west-2" \
"eu-west-1" \
"sa-east-1" \
"ap-southeast-1" \
"ap-southeast-2" \
@pataiji
pataiji / crontab
Last active August 29, 2015 14:14
Time Machineが外れています
*/10 * * * * /sbin/mount | grep 'Time Machine' | [ `wc -l` -eq 0 ] && osascript -e 'tell app "System Events" to display dialog "Time Machine のディスクが外れています"' > /dev/null 2>&1
#!/bin/bash
to_ref='00000000000000000000000000'
channel='private-group'
username='stash'
text="*branch name* has new commits by *user name*"
icon=':stash:'
attachments=''
@pataiji
pataiji / format_print.rb
Last active August 29, 2015 14:14
`Rake -T`のprintがキレイだったのでメモ
#!/usr/bin/env ruby
# https://github.com/ruby/rake/blob/master/lib/rake/application.rb#L291
values = %w(Our star is an enormous thermonuclear furnace more than a million times as big as Earth)
width = values.map(&:length).max || 10
values.each do |v|
printf("%-#{width}s # this is a pen.\n", v)