Skip to content

Instantly share code, notes, and snippets.

@libkazz
libkazz / bundle-update.sh
Last active October 18, 2019 07:29
bundle update をする shell
bundle update
for m in `git d Gemfile.lock | egrep '^\+ \w' | sed -e 's/^\+ //' -e 's/ (.*//' | sort -u`; do
git checkout Gemfile.lock
bundle update $m
git add -u Gemfile.lock
git commit -m ":up: $m"
git push origin HEAD
echo "============== $m ==============="
done
@libkazz
libkazz / stone_tori.rb
Created January 31, 2017 15:59
石取りゲーム
class StoneTori
class Stones
def initialize(count)
@count = count
end
def empty?
@count.zero?
end
@libkazz
libkazz / count_front_css_lines.rb
Last active November 5, 2016 07:07
CSS 行数推移チェック
since = '2016/3/22'
path = 'app/assets/stylesheets'
`git log --pretty="format:%ad %h" --date=short --since="#{since}" #{path}`.split("\n").reverse.each do |line|
date, rev = line.split
system("git checkout #{rev} 2> /dev/null")
count = `find #{path} -type f -exec wc -l {} \\; | awk '{n+=$1} END{print n}'`.chomp.to_i
puts [date, rev, count].join(',')
end
@libkazz
libkazz / out.sh
Created July 7, 2016 09:39
sitemap.xml の URL 一覧を出力する
gzcat tmp/sitemaps/sitemap.xml.gz | ruby -rnokogiri -e 'Nokogiri::XML($stdin.read).search("url/loc").each {|n| puts n.text }'
@libkazz
libkazz / hash_combination.rb
Created May 31, 2016 08:16
Hash#combination
vals = {
type: ['wood','iron','other'],
length: [1,2,3,4,5],
width: [1,2,3],
}
class Hash
def combination
keys.reduce([{}]) do |r, key|
r = _add_to_combination(r, key)
@libkazz
libkazz / fill with nil
Created August 10, 2014 03:04
fill with nil
# Fill with nil, until list will be the size.
#
# [:a].nilfil(4) #=> [:a, nil, nil, nil, nil]
# [:a,:b,:b,:d,:e].nilfil(4) #=> [:a, :b, :b, :d, :e]
class Array
def nilfil(size)
me = self.dup
me[size - 1] = me[size - 1]
me
@libkazz
libkazz / 0_reuse_code.js
Created March 29, 2014 07:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@libkazz
libkazz / gist:9523385
Created March 13, 2014 07:32
helper で HTML を書く時の性能比較
# 結論
#
# ContentTag >>>>> Inline Erb >> Inline HAML
#
# 可読性とパフォーマンスのどちらを取りたいか考えて選択しましょう
#
#
# Inline HAML
#
@libkazz
libkazz / gist:7113677
Created October 23, 2013 06:47
rails の migration で id(primary key) をつける。しかも、partitioning を設定してるテーブルに。
class AddColumnIdToLogs < ActiveRecord::Migration
def up
add_column :logs, :id, :integer, null: false # FIXME: Add column to head of columns
execute 'SET @rownum = 0'
execute 'UPDATE `access_logs` SET `id` = @rownum := @rownum + 1'
execute 'ALTER TABLE `logs` ADD PRIMARY KEY(`id`, `date`)' # Partitioning key () must be primary key.
execute 'ALTER TABLE `logs` CHANGE `id` id INT(11) AUTO_INCREMENT'
end
@libkazz
libkazz / gist:5433153
Created April 22, 2013 07:59
OpenOffice で作った表形式のデータを手軽に扱う
# Usage:
# Book.new('foo.ods').sheet('first sheet').each do |row|
# puts "first column => " + row["first column"]
# puts "second column => " + row["second column"]
# end
#
# Write gem 'roo' at Gemfile
module Foo
class Book
def initialize(file)