Skip to content

Instantly share code, notes, and snippets.

def main
count = 0
uniq_list = []
f = open('write', 'w')
open_each_ss('parsed_mobamasu_kai') do |row|
array = row.strip.split(' ')
array.uniq.each do |word|
if !uniq_list.include?(word)
uniq_list << word
end
@EastResident
EastResident / gist:221b15f3a0dd3d7c3726f9be210e428c
Created November 23, 2016 08:32
migrate -> ridgepole移行スクリプト
Dir::foreach('db/migrate/.') do |file|
next if file == '.' || file == '..'
state = 0
table = ''
table_name = ''
open("db\/migrate\/#{file}") do |f|
file_name = file.match(/.+_create_(\w+)\.rb/)[1]
wf = open("db\/schemas\/#{file_name}\.rb", 'w')
f.each do |line|
if line.include?('create_table')
@EastResident
EastResident / customer.rb
Created March 12, 2017 16:44
モデル間のリレーションSpecを書きたくないので自動生成してみる ref: http://qiita.com/EastResident/items/e97632074f50d2541547
class Customer < ApplicationRecord
has_many :orders, dependent: :destroy
end
@EastResident
EastResident / file0.txt
Last active April 4, 2017 11:35
OpenURIで10KB以下のファイルが開けないよ ref: http://qiita.com/EastResident/items/a9f753fe0983e915e99f
OpenURI.open_uri('ファイルのURL')
# 性・名・電話番号でのAND検索
User.search('田中 太郎 08012345678')
# メールアドレスに"gmail"が含まれており、登録が2015年あるいは2016年
User.search('email: gmail AND (created_at:2015 OR created_at:2016)')
@EastResident
EastResident / file0.txt
Created August 7, 2017 17:02
ARオブジェクトをURI化する`ActiveJob::Arguments#serialize`が色々と使えそう ref: http://qiita.com/EastResident/items/41a016ac97b8691a2aa3
user = User.find(5)
SampleJob.perform_later(user)
{ '<' => [-1], '>' => [1], '<=' => [-1, 0], '>= ' => [1, 0]}.each do |ope, v|
[TrueClass, FalseClass].each do |klass|
klass.class_eval("def #{ope}(num); self ? value #{ope} num : false;end")
end
[Integer, Float].each do |klass|
klass.class_eval do
define_method(ope) do |n|
return false unless v.include? (self <=> n)
TrueClass.class_eval("def value; #{n};end")
true
@EastResident
EastResident / inside-locust-01
Last active October 17, 2018 07:46
inside-locust
git clone https://github.com/EastResident/locusts
cd locusts
@EastResident
EastResident / inside-locust-02.py
Created October 17, 2018 07:40
inside-locust-02
import uuid
from datetime import datetime
from locust import HttpLocust, TaskSet, task
class MetricsTaskSet(TaskSet):
@task
def index(self):
self.client.get("/index")
@EastResident
EastResident / inside-locust-03.py
Created October 17, 2018 07:40
inside-locust-03
from locust import HttpLocust, TaskSet
def login(l):
l.client.post("/login", {"username":"ellen_key", "password":"education"})
def logout(l):
l.client.post("/logout", {"username":"ellen_key", "password":"education"})
def index(l):
l.client.get("/")