Skip to content

Instantly share code, notes, and snippets.

@miyucy
miyucy / timezone.md
Last active June 19, 2017 13:35
JST <=> UTC (GMT)
0900 0000
2016-03-01 00:00:00 +0900 2016-02-29 15:00:00 UTC
2016-03-01 01:00:00 +0900 2016-02-29 16:00:00 UTC
2016-03-01 02:00:00 +0900 2016-02-29 17:00:00 UTC
2016-03-01 03:00:00 +0900 2016-02-29 18:00:00 UTC
2016-03-01 04:00:00 +0900 2016-02-29 19:00:00 UTC
2016-03-01 05:00:00 +0900 2016-02-29 20:00:00 UTC
2016-03-01 06:00:00 +0900 2016-02-29 21:00:00 UTC
2016-03-01 07:00:00 +0900 2016-02-29 22:00:00 UTC
require 'find'
class Watchlog
class LogFile
def initialize(path)
@path = path
@pid = nil
@wth = nil
end
# -*- mode: ruby -*-
Vagrant.configure(2) do |config|
config.vm.box = 'ubuntu/xenial64'
config.vm.network 'forwarded_port', guest: 5432, host: 15432
config.vm.network 'forwarded_port', guest: 8000, host: 18000
config.vm.provider 'virtualbox' do |vb|
vb.cpus = 4
vb.memory = 4094
end
require 'web_push'
# Generate a keys and puts it to Rails.application.secrets.web_push_public_key
pkey = WebPush::Utils.generate_vapid_pkey
# Rails.application.secrets.web_push_private_key
vapid_private_key = Base64.urlsafe_encode64(pkey.private_key.to_bn.to_s(2)).delete('=')
puts "vapid_private_key = #{vapid_private_key}"
# Rails.application.secrets.web_push_public_key
require 'restclient'
require 'json'
namespace :sentry do
class SentryReleaseAPI
def initialize(organization_slug: nil, project_slug: nil, api_key: nil)
@organization_slug = organization_slug || ENV['SENTRY_ORGANIZATION_SLUG']
@project_slug = project_slug || ENV['SENTRY_PROJECT_SLUG']
@api_key = api_key || ENV['SENTRY_API_KEY']
end
const actionCreator = () => ({ type: 'SOME_ACTION' });
const noopReducer = (state, action) => state;
const noopEnhancer = (store) => store;
const noopMiddleware = store => next => action => next(action);
export function createStore(reducer = noopReducer, initialState = undefined, enhancer = noopEnhancer) {
let state = initialState;
let listeners = [];
const dispatch = (action) => {
@miyucy
miyucy / gist:1124401
Created August 4, 2011 02:49
git pre-receive hooks
#!/usr/bin/env ruby
old_sha, new_sha, ref = STDIN.read.split(' ')
diff = %x{ git diff --raw --name-only #{old_sha} #{new_sha} 2> /dev/null }
diff.each_line do |line|
file = line.chomp
next unless file =~ /\.rb\Z/i
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/hash/indifferent_access'
module Snaky
refine Hash do
def to_snake_case(value = self)
case value
when Hash
value.map { |k, v| [k.underscore, to_snake_case(v)] }.to_h.with_indifferent_access
when Array
@miyucy
miyucy / quwk.rb
Created May 25, 2016 17:09
Queue Worker
require 'thread'
class QuWk
NUM = 3
def initialize
@queue = Queue.new
@workers = []
@num = NUM
@block = proc {}
@miyucy
miyucy / rewinder.rb
Created January 15, 2014 03:50
database_rewinder like cleaner for mongo mapper.
class Rewinder
def self.repository
Thread.current[:rewinder]
end
def self.repository=(v)
Thread.current[:rewinder] = v
end
def self.start