Skip to content

Instantly share code, notes, and snippets.

@keitaj
keitaj / database.yml.sample
Created March 7, 2015 00:12
database.yml.sample
development:
adapter: mysql2
enccoding: utf8mb4
charset: utf8mb4
collation: utf8mb4_general_ci
reconnect: false
database: app_db
pool: 5
username: root
password: admin
@keitaj
keitaj / ar_innodb_row_format.rb
Created March 7, 2015 01:21
utf8mb4で動かすために必要。create_tableメソッドで'ROW_FORMAT=DYNAMIC'がデフォルトで指定されるようにしておく。http://qiita.com/kamipo/items/101aaf8159cf1470d823
ActiveSupport.on_load :active_record do
module ActiveRecord::ConnectionAdapters
class AbstractMysqlAdapter
def create_table_with_innodb_row_format(table_name, options = {})
table_options = options.merge(:options => 'ENGINE=InnoDB ROW_FORMAT=DYNAMIC')
create_table_without_innodb_row_format(table_name, table_options) do |td|
yield td if block_given?
end
end
alias_method_chain :create_table, :innodb_row_format
6018 Books
6000 Business
6022 Catalogs
6017 Education
6016 Entertainment
6015 Finance
6023 Food and Drink
6014 Games
6013 Health and Fitness
6012 Lifestyle
@keitaj
keitaj / schedule.rb
Created March 12, 2015 03:15
wheneverでのスケジュール設定サンプル。/config/schedule.rb。crontabを更新するコマンド。bundle exec whenever --update-crontab
every 1.day, at: '15:01 pm' do
runner 'Tasks::CreateSummaryReport.execute', output: 'log/cron.log'
end
every(1.day, at: '0:07 am') { runner 'Tasks::CreateDetailReports.new.execute', output: 'log/cron.log' }
every 1.hours do
runner 'Tasks::CreateSummaryReport.execute', output: 'log/cron.log'
end
# ユーザーの入力が1ならBarから、そうでなければBazから派生する
class Foo < (user_input == "1" ? Bar : Baz)
end
@keitaj
keitaj / gist:bb4f5278878e48f1dc35
Created April 12, 2015 05:19
apiで値取得
var json = (function () {
var json = null;
$.ajax({
'async': false,
'global': false,
'url': 'http://localhost:8888/indkrydsning/app/house/stats_json/',
'dataType': "json",
'success': function (data) {
json = data;
}
@keitaj
keitaj / file0.go
Last active October 6, 2017 06:24
Go言語でstructをmapに変換する ref: http://qiita.com/keitaj/items/440a50a53c8980ee338f
package main
import (
"fmt"
"reflect"
"encoding/json"
)
func StructToMap(data interface{}) map[string]interface{} {
@keitaj
keitaj / file0.txt
Created August 14, 2016 05:35
Elasticsearchを使って自分の周囲の位置情報を検索する ref: http://qiita.com/keitaj/items/5ab59387604801cb0532
{
"mappings": {
"shop": {
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
@keitaj
keitaj / main.go
Last active December 13, 2016 15:35
Goで書くはじめてのデジタル署名 ref: http://qiita.com/keitaj/items/00aede60e64e8eebbb8a
package main
import (
"bufio"
"bytes"
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/base64"
@keitaj
keitaj / howtogomod.md
Created January 17, 2020 08:39
howtogomod