Skip to content

Instantly share code, notes, and snippets.

ids = [1,2,3]
#=> [1, 2, 3]
#書き込み
recommendation = Recommendation.create(uid: 1, recommended_id_list: ids.pack('Q<*'))
#=> #<Recommendation uid: 1, recommended_id_list: "\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00", updated_at: "2020-01-15 09:56:20">
#読み込み
recommendation.recommended_id_list.unpack('Q<*')
#=> [1, 2, 3]
@RNDcpp
RNDcpp / .diff
Last active January 24, 2020 02:58
class CreateRecommendations < ActiveRecord::Migration[5.2]
def change
- create_table :recommendations do |t|
+ create_table :recommendations, id: false do |t| # idの代わりにuidを使う
- t.bigint :uid
+ t.bigint :uid, null: false, unique: true
- t.blob :recommended_id_list
+ t.blob :recommended_id_list, null: false
- t.timestamps
+ t.datetime :updated_at, null: false # created_atは不要
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# 初期値の定義
# 初期配置
x=[
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
@RNDcpp
RNDcpp / life.py
Last active October 10, 2019 18:00
ライフゲーム
import numpy as np
# 初期値の定義
x=[
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,0,0,0,0],
[0,0,0,0,0,1,0,0,0],
[0,0,0,1,1,1,0,0,0],
[0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0],
@RNDcpp
RNDcpp / fetch_table_worker.rb
Last active September 9, 2019 10:21
google cloud bigquery with large table
records = Google::Cloud::Bigquery.dataset(dataset_id).table(table_id).data()
@RNDcpp
RNDcpp / conv.sh
Last active October 9, 2019 15:17
写真をイラスト背景風にするフィルタ.sh
# USAGE conv.sh [input] [output] [width] [height]
# widthとheightは大きめ(2000以上)の方がいい感じになる
# リサイズします
convert $1 -resize ${3}x${4}! target.png
# 油彩フィルタを重ねがけします
convert target.png -modulate 160,180 -colors 400 -paint 2 -paint 2 -paint 2 -blur 3x4 paint.png
# ぼかした後の画像からエッジ画像を取り出します