Skip to content

Instantly share code, notes, and snippets.

View miyamae's full-sized avatar

Tatsuya Miyamae miyamae

View GitHub Profile
@miyamae
miyamae / mergeLineChartData.js
Created April 13, 2020 09:11
Google Charts用に配列を合成
const mergeLineChartData = (head, dst, src) => {
dst[0].push(head)
let existed = false
for (const s of src) {
existed = false
for (const d of dst) {
if (d[0] === s[0]) {
d.push(s[1])
existed = true
}
@miyamae
miyamae / randomopen.rb
Created February 18, 2016 08:21
下層ディレクトリ内のファイルをランダムに選択して開く(Mac)
#!/usr/bin/env ruby
Dir.chdir(File.expand_path('..', __FILE__)) do
files = Dir.glob('**/*.{mp3,wma}')
file = files[rand(files.size)]
puts file
system "open \"#{file}\""
end
@miyamae
miyamae / apartment.rb
Created January 15, 2016 18:08
gem apartmentを使った時のRails.cacheの追加設定
# テナント間でキャッシュキーが同じになってしまいデータが混線するのを防ぐため
# config/initializersでnamespaceの設定を追加します。
Rails.cache.options[:namespace] = proc { "#{Apartment::Tenant.current}-#{I18n.locale}" }
@miyamae
miyamae / navbar-active.js
Last active October 3, 2015 18:47
Iimplement the bootstrap navbar active class with JS
$(function() {
$('a').each(function() {
if (window.location.pathname.indexOf($(this).attr('href')) === 0) {
$(this).parent().addClass('active');
}
});
});
@miyamae
miyamae / schedule.rb
Created November 29, 2014 17:41
大量のファイルを夜中にひっそり消すwhenever
every 1.day, at: '3:00 am' do
command 'if [ -e /tmp/flushed_cache.* ]; then ionice -c 2 -n 7 nice -n 19 rm -rf /tmp/flushed_cache.*; fi'
end
@miyamae
miyamae / custom_breadcrumbs_builder.rb
Created November 28, 2014 18:34
microdata markup for weppos/breadcrumbs_on_rails
class CustomBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::SimpleBuilder
def initialize(context, elements, options = {})
super
@options[:separator] = ''
end
def render_element(element)
# truncate page title
if element.name !~ /^</ && element.name.to_s.length > 20
@miyamae
miyamae / crontab
Created November 27, 2014 17:52
大量のファイルを夜中にひっそり消すcrontab
0 3 * * * if [ -e /tmp/flushed_cache.* ]; then ionice -c 2 -n 7 nice -n 19 rm -rf /tmp/flushed_cache.*; fi
@miyamae
miyamae / tmp_cache_flush.rake
Last active August 29, 2015 14:10
rake tmp:cache:clearが遅いからファイルを消すかわりに/tmpへ移動
namespace :tmp do
namespace :cache do
# desc "Move all files and directories in tmp/cache to /tmp"
task :flush do
FileUtils.mv('tmp/cache', "/tmp/flushed_cache.#{Time.now.to_i}")
FileUtils.mkdir('tmp/cache')
end
end
end
@miyamae
miyamae / ban_reserved_validator.rb
Created February 16, 2014 06:52
登録されるとつらいユーザー名を禁止するRails Validator
class BanReservedValidator < ActiveModel::EachValidator
WORDS = %w{
index home top help about security contact support faq form mail
update mobile tour plan price business company store shop term
privacy rule inquiry legal policy image css stylesheet src js
javascript asset account user item entry article event doc word
product download video community blog site popular i my me topic
news info status search explore share feature upload rss widget
api wiki auth session register login logout signup signin signout
@miyamae
miyamae / gist:8554551
Created January 22, 2014 06:57
RailsのmigrationでDBの種類を判定して、PostgreSQLでstring→integerへchange_columnする方法。
def change
adapter = ActiveRecord::Base.connection.instance_values['config'][:adapter]
if adapter == 'postgresql'
change_column :table_name, :field_name, 'integer USING CAST(field_name AS integer)'
else
change_column :table_name, :field_name, :integer
end
end