Skip to content

Instantly share code, notes, and snippets.

ippei ippeiukai

Block or report user

Report or block ippeiukai

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ippeiukai / subset-of.ts
Created Nov 14, 2017
`SubsetOf` meta type
View subset-of.ts
export type SubsetOf<T> = {
[P in keyof T]?: T[P];
ippeiukai / cron.conf
Last active Apr 30, 2019
Running cron in AWS ElasticBeanstalk web tier.
View cron.conf
mode: "000777"
owner: 'ec2-user'
group: 'ec2-user'
content: |
30 02 * * * sudo /usr/sbin/execute-in-eb-node-app 'node bin/is-eb-master.js' && sudo /usr/sbin/execute-in-eb-node-app 'npm run daily-maintenance'
encoding: plain
ippeiukai / check-whether-eb-master-instance.js
Created Oct 5, 2016
For running something only on one instance in an ElasticBeanstalk environment. Inspired by
View check-whether-eb-master-instance.js
"use strict";
const AWS = require('aws-sdk');
const bluebird = require('bluebird');
* @returns {Promise.<boolean>} - is on 'master' instance or not
module.exports = bluebird.coroutine(function* (opts) {
if (opts == null) {
View sequelize-find-each.js
"use strict";
const Sequelize = require('sequelize');
const Promise = Sequelize.Promise;
const DEFAULT_BATCH_SIZE = 3000;
* Port of ActiveRecord::Base.find_each of Rails.
ippeiukai / singleton_with_class_delegator.rb
Created Jun 17, 2016
Singleton but as convenient as class methods; it's both.
View singleton_with_class_delegator.rb
module SingletonWithClassDelegator
extend ActiveSupport::Concern
included do
include Singleton
original_delegate_method = method(:delegate).unbind if self.respond_to?(:delegate)
extend SingleForwardable
if original_delegate_method.present?
# restore the delegate of ActiveSupport that has been overshadowed by SingleForwardable
define_singleton_method :delegate, original_delegate_method
View Rubinius 3.33 two_plus_two_is_five backtrace.txt
$ irb
irb(main):001:0> class Fixnum
irb(main):002:1> def plus_with_two_plus_two_is_five(other)
irb(main):003:2> other += 1 if self == 2 && other == 2
irb(main):004:2> plus_without_two_plus_two_is_five(other)
irb(main):005:2> end
irb(main):006:1> alias_method :plus_without_two_plus_two_is_five, :+
irb(main):007:1> alias_method :+, :plus_with_two_plus_two_is_five
irb(main):008:1> end
Rubinius::InvalidBytecode: instruction argument is not a Fixnum: code: call, ip: 13
View config.rb
module Rubinius
config = {}
config[:config_file] = "/Users/ippei/src/rubinius-3.33/config.rb"
config[:command_line] = ["--prefix=/Users/ippei/.rvm/rubies/rbx-3.33", "--with-opt-dir=/usr/local/opt/openssl:/usr/local/opt/readline:/usr/local/opt/libyaml:/usr/local/opt/gdbm", "--llvm-path=/usr/local/Cellar/llvm/3.6.2"]
config[:build_make] = "make"
config[:build_rake] = "rake"
config[:build_perl] = "perl"
config[:llvm_path] = "/usr/local/Cellar/llvm/3.6.2"
config[:llvm_system_name] = nil
config[:llvm_configure] = "/usr/local/opt/llvm/bin/llvm-config"
ippeiukai / enumerable_product.rb
Created Feb 23, 2016
Monkey patch to provide Cartesian product of enumerables in ruby.
View enumerable_product.rb
module Enumerable
def self.product(first, *rest)
return enum_for(__method__, first, *rest) unless block_given?
if rest.empty?
first.each do |v0|
yield [v0]
enum_for_rest = product(*rest)
ippeiukai / association_exists.rb
Created Feb 14, 2016
association_exists model plugin for Sequel. Like association_join, allows you to filter dataset with association.
View association_exists.rb
module Sequel
module Plugins
module AssociationExists
module DatasetMethods
def association_exists(association, &block)
_association_exists(association, &block)
ippeiukai / string_to_json_escape_outside_bmp.rb
Created Dec 8, 2015
monkey patch to ruby's JSON that escapes chars bigger than 3 bytes in UTF-8
View string_to_json_escape_outside_bmp.rb
require 'active_support'
require 'active_support/concern'
require 'active_support/core_ext'
require 'active_support/json'
# String#to_json to escape any string outside BMP
module StringToJsonWithEscape4byteUtf8
extend ActiveSupport::Concern
included do
You can’t perform that action at this time.