Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Ohkubo KOHEI kuboon

🏠
Working from home
View GitHub Profile
View .gitconfig
[alias]
begin = "!f(){ c=`git branch --show-current`; git switch -c $1; git commit --allow-empty -m \"$2\"; git push --set-upstream origin $1; gh pr create -a @me -b \"\" --draft --base $c -t \"$2\"; }; f"
pushtag = "!f(){ git tag -a -f $1 -m \"$2\"; git push -f origin $1 ; }; f"
sync = "fetch --prune --tags -f"
@kuboon
kuboon / autoscroll_after_viewed.js
Created May 31, 2022
Tampermonkey: auto scroll after viewed
View autoscroll_after_viewed.js
// ==UserScript==
// @name Auto Scroll After Viewed
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Click 'Viewed' checkbox easier.
// @author kuboon
// @match https://github.com/*/files
// @icon https://www.google.com/s2/favicons?domain=github.com&sz=256
// @grant none
// ==/UserScript==
@kuboon
kuboon / Dockerfile
Created Feb 14, 2022
.devcontainer
View Dockerfile
# https://hub.docker.com/_/microsoft-vscode-devcontainers
FROM mcr.microsoft.com/vscode/devcontainers/base:0-ubuntu-21.04
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends fish
RUN chsh -s /usr/bin/fish vscode
USER vscode
SHELL ["/usr/bin/fish", "-l", "-c"]
# http://asdf-vm.com/guide/getting-started.html#_3-install-asdf
@kuboon
kuboon / matrix_encryption.rb
Created Apr 10, 2018
matrix encryption protocol (cayley hamilton safe!)
View matrix_encryption.rb
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 / Gemfile
Created Nov 20, 2015
acts_as_taggable_on + simple_form + select2
View Gemfile
gem 'acts-as-taggable-on'
gem 'simple_form'
gem 'select2-rails'
@kuboon
kuboon / perm_log.py
Last active May 22, 2021
Detect x from permutation p, p**x
View perm_log.py
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 / prepare_db.rb
Created Mar 18, 2021
RSpec prepare db
View prepare_db.rb
RSpec.shared_context 'prepare db' do
def records
raise 'caller should define'
end
before :all do
::ActiveRecord::Base.connection.begin_transaction(joinable: false)
records
end
after :all do
::ActiveRecord::Base.connection.rollback_transaction
View webrick_sample.rb
require 'webrick'
require 'cgi'
s = WEBrick::HTTPServer.new(
:Port => 8000,
:HTTPVersion => WEBrick::HTTPVersion.new('1.1'),
:AccessLog => [[open(IO::NULL, 'w'), '']] # アクセスログを出力しない
)
s.mount_proc('/') do |req, res|
View gcp_start_stop
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: light-gray; icon-glyph: magic;
async function accessToken(){
const env = {
CLIENT_ID: "000000000.apps.googleusercontent.com",
CLIENT_SECRET: "xxxxxxx",
REFRESH_TOKEN: "1//xxxxxxxx"
}
const project = "myproject"
@kuboon
kuboon / gsheetDate.ts
Created Nov 12, 2020
convert from/to google sheet date serial
View gsheetDate.ts
import { zonedTimeToUtc, utcToZonedTime } from "date-fns-tz";
const SheetDate = {
origin: Date.UTC(1899, 11, 30, 0, 0, 0, 0),
dayToMs: 24 * 60 * 60 * 1000
};
function serialToDate(d: number, sheetTimeZone: string): Date {
return zonedTimeToUtc(
new Date(d * SheetDate.dayToMs + SheetDate.origin),
sheetTimeZone