Skip to content

Instantly share code, notes, and snippets.

View kuboon's full-sized avatar
🏠
Working from home

Ohkubo KOHEI kuboon

🏠
Working from home
View GitHub Profile
@kuboon
kuboon / Gemfile
Created November 20, 2015 06:30
acts_as_taggable_on + simple_form + select2
gem 'acts-as-taggable-on'
gem 'simple_form'
gem 'select2-rails'
@kuboon
kuboon / dispatch.rb.cgi
Last active October 31, 2016 09:41
run Rails app as DRb server and access it from CGI process
#!ruby
require 'drb/drb'
require 'logger'
require "rack"
require 'rack/rewindable_input'
module Dispatch
RAILS_ENV = 'staging'
DRUBY_URI = "druby://localhost:13141"
LOCKFILE = "../tmp/pids/dispatch.pid"
gem 'quiver_note'
class MyEvernote
NOTE_NAME = 'public'
USERNAME = 'kuboon'
def client
@client ||= EvernoteOAuth::Client.new(token: auth_token, sandbox: false)
end
@kuboon
kuboon / tenko.js
Last active April 8, 2020 01:44
Slack の channel で点呼をとる
// Description:
// Slack の channel で点呼をとる
// https://gist.github.com/kuboon/8c66bf61a170bc49f99e5fe91352bb6f
// Commands:
// hubot 点呼
// Dependencies:
// "aa": "^0.1.40"
// "slack-node": "^0.1.3"
// "hubot-redis-brain"
@kuboon
kuboon / db_fixtures_export.rake
Created May 12, 2017 15:58
Generate fixtures from db. Readable by rake db:fixtures:load
# lib/tasks/db_fixtures_export.rake
namespace 'db:fixtures' do
desc "generate fixtures from the current database"
task :export => :environment do
Rails.application.eager_load!
models = defined?(AppicationRecord) ? ApplicationRecord.decendants : ActiveRecord::Base.descendants
models.each do |model|
puts "exporting: #{model}"
# views/fields/belongs_to_scoped/_form.html.erb
<div class="field-unit__label">
<%= f.label field.permitted_attribute %>
</div>
<div class="field-unit__field">
<%= f.select(field.permitted_attribute) do %>
<%= options_for_select(field.associated_resource_options(f.object.send("#{field.name}_candidates")), field.selected_option) %>
<% end %>
</div>

Keybase proof

I hereby claim:

  • I am kuboon on github.
  • I am kuboon (https://keybase.io/kuboon) on keybase.
  • I have a public key ASCbNuTLzZAuy_vOaGq6vLnF2LjZ4xGSUjC-so2U8gV3swo

To claim this, I am signing this object:

Huge *n1 = huge_from_long(12);
Huge *n2 = huge_from_long(3);
Huge *result;
result = huge_add(n1, n2);
printf("%d", huge_as_long(result)); // 15
huge_free(result);
result = huge_sub(n1, n2);
require 'prime'
# backport ruby 2.4
class Array
def sum(identity = 0, &block)
if block_given?
map(&block).sum(identity)
else
inject { |sum, element| sum + element } || identity
end
@kuboon
kuboon / perm_log.py
Last active September 6, 2023 04:46
Detect x from permutation p, p**x
import functools, itertools, random, math
from sympy.combinatorics import Permutation
def cycle_rounds(p1, p2, verbose = False):
'''detect all cycles in p1 how many times rounded in p2
Usage:
>>> p = Permutation(10)(2,3,4,5)(6,7)
>>> cycle_rounds(p,p**3)
[(1, 2), (3, 4)]