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 / 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];
@kuboon
kuboon / matrix_encryption.rb
Created April 10, 2018 00:43
matrix encryption protocol (cayley hamilton safe!)
require 'matrix'
gem 'ruby-numtheory'
require 'numtheory'
def IntegerModRing(mod)
class_name = "IntegerModRing#{mod}"
return Kernel.const_get class_name rescue nil
cls = Class.new do |cls|
@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)]
@kuboon
kuboon / gist:c5b8f60044de747015fe8df446bb862e
Created May 8, 2023 06:40
xorshift32 for Excel / google sheets # replace "input" to A1 or anything
=LET(LX, LAMBDA(X, A, BITXOR(X, BITLSHIFT(BITAND(X, 2^(32-A)-1), A))), RX, LAMBDA(X, A, BITXOR(X, BITRSHIFT(X, A))), LX(RX(LX(input, 13), 17), 5))