Skip to content

Instantly share code, notes, and snippets.

# This code is based on the code at blow:
# https://github.com/fastruby/fast-ruby/tree/main/code/enumerable
require "benchmark/ips"
ARRAY = [*1..100]
def fast
ARRAY.each.with_index(1) do |number, index|
index
end
@libkazz
libkazz / Gemfile
Last active October 6, 2022 02:25
source "https://rubygems.org"
gem "activerecord", '~> 7.0'
gem "sqlite3"
@libkazz
libkazz / sakuma.js
Last active May 14, 2020 14:24
22種類のものが隣同士にならないように、縦におなじものがこないように縦6×横100にランダムに並べる
const randomArray = (w, h, v) => {
const a = Array.from(Array(v), (_,k) => k)
let t = []
for(let y=0; y<h; y++){
t.push([]);
for(let x=0; x<w; x++){
let g = t.map(r => r[x]).concat([t[y][x-1]]);
let f = a.filter(e => !g.includes(e));
t[y][x] = f[Math.floor(Math.random()*f.length)];
}
# コンテナにログインする
docker ps
docker exec -it {CONTAINER ID} bash
# コンテナ削除
docker ps -a -q | xargs docker rm
# イメージ削除(コンテナ削除後)
docker images -q | xargs docker rmi
@libkazz
libkazz / .env
Created August 13, 2019 03:51
wordpress docker-compose
WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_USER={input user name}
WORDPRESS_DB_PASSWORD={input password}
MYSQL_RANDOM_ROOT_PASSWORD=yes
MYSQL_DATABASE=wordpress
MYSQL_USER={input user name}
MYSQL_PASSWORD={input password}
@libkazz
libkazz / gist:9650817a454126f4e9bb0a725dac0b16
Last active August 3, 2019 09:59
RubyでExcel列文字列を列番号に変換する方法
def row_number(str)
str.bytes.reverse.each.with_index(0).reduce(0) do |n, (c, i)|
n += (26 ** i * (c.ord - 64))
end
end
('A'..'BZ').each do |str|
p [str, row_number(str)]
end
@libkazz
libkazz / simulation-sample.rb
Created August 19, 2018 05:34
proxy sample
require 'rack-proxy'
module SimulationSample
class Proxy < Rack::Proxy
def rewrite_env(env)
env
end
end
def self.call(env)
@libkazz
libkazz / orphaned_partial_check.rb
Created July 17, 2018 02:07
使われていない partial の簡易チェックスクリプト
def target_partial
Dir['app/views/front/{shared,sections,sidebar}/**/*'].each_with_object([]) do |f, list|
next unless File.file?(f)
list << [
File.dirname(f).sub('app/views/', ''),
File.basename(f).sub(/^_/, '').sub('.slim', '').sub('.html.erb', '')
].join('/')
end
end
@libkazz
libkazz / toggle_colspanned_column.js
Created December 9, 2017 11:04
colspan = 2 のカラムの toggle する
console.log('Loaded..');
class Togglable {
constructor(th) {
this.th = th;
this.table = th.parentNode.parentNode.parentNode;
this.tds = this.table.querySelectorAll('td:nth-child(' + this._getColumnIndex(th) + ')')
}
toggle() {
@libkazz
libkazz / gist:99e1d91a664d490d79ad85a25137094f
Created November 2, 2017 16:17 — forked from liamcurry/gist:2597326
Vanilla JS vs jQuery

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})