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
RSpec.configure do |config|
config.before(:suite) { Coverage.start(oneshot_lines: true) }
config.after :suite do
coverage_data = Coverage.result(stop: true, clear: true)
uncovered_lines(coverage_data)
end
end
def parse_git_diff(base_branch)
diff_output, _stderr, _status = Open3.capture3("git diff #{base_branch} --unified=0")
@kuboon
kuboon / heroku.rb
Created January 24, 2025 05:10
rails initializer for heroku
# frozen_string_literal: true
run "heroku create #{@app_name}"
gem "pg"
file "config/database.yml", <<~CODE
development: &psql
adapter: postgresql
database: #{@app_name}
pool: 5
@kuboon
kuboon / perm_log.py
Last active September 20, 2024 18:55
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)]
@kuboon
kuboon / docker-rootful-vz.yaml
Last active April 5, 2024 02:02
lima docker-rootful-vz
# A template to run ubuntu using vmType: vz instead of qemu (Default)
# This template requires Lima v0.14.0 or later and macOS 13.
vmType: "vz"
rosetta:
# Enable Rosetta for Linux.
# Hint: try `softwareupdate --install-rosetta` if Lima gets stuck at `Installing rosetta...`
enabled: true
# Register rosetta to /proc/sys/fs/binfmt_misc
binfmt: true
@kuboon
kuboon / dive.fish
Last active March 21, 2024 06:41
fish dive into git repo
function dive
set repo $argv[1]
if test -z (echo $repo | cut -d '/' -f3)
set repo github.com/$repo
end
set path ~/repos/$repo
if test -d $path
cd $path
echo "Moved to existing directory $path"
@kuboon
kuboon / deserialize_bench.rb
Created January 25, 2024 09:10
deserialize_bench.rb
require 'benchmark'
require 'json'
require 'active_support/notifications'
require 'active_support/cache'
array = (1..1000).map { rand }
TIMES = 1000
Benchmark.bmbm do |x|
cache = ActiveSupport::Cache::FileStore.new("./tmp/cache")
@kuboon
kuboon / sample.ts
Created April 22, 2020 07:48
Typescript: constructor with named arguments
class ConstructorArgs {
namespace: string[] = ["default", "values"]
}
class Base extends ConstructorArgs {
constructor(opts: ConstructorArgs = new ConstructorArgs) {
super()
Object.assign(this, opts)
}
}
# 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>
@kuboon
kuboon / perm_rand.c
Last active September 6, 2023 04:46
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define N 16
#define M 16
#define NN 2
unsigned char x0[N]={0};
@kuboon
kuboon / perm_rand.c
Last active September 6, 2023 04:46
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define N 16
#define M 16
#define NN 2
unsigned char xx[N];