Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Ohkubo KOHEI kuboon

🏠
Working from home
View GitHub Profile
@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
@kuboon
kuboon / mtx.c
Last active Oct 29, 2020
f2 matrix
View mtx.c
#include <stdio.h>
#include <assert.h>
#define N 16
#define K 8
#include "global.h"
#include "chash.c"
#include "inv_mat.c"
typedef struct {
View keybase.md

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@kuboon
kuboon / install_gcloud.sh
Created Oct 6, 2020
install gcloud on Ubuntu
View install_gcloud.sh
#!/bin/env sh
sudo apt install apt-transport-https ca-certificates gnupg
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
sudo apt update && sudo apt install google-cloud-sdk
@kuboon
kuboon / getSelectionWithAlt.ts
Last active Oct 10, 2020
document.getSelection with img.alt text
View getSelectionWithAlt.ts
function isImg(node: Node):node is HTMLImageElement{
return node.nodeName==='IMG'
}
function selectionToFragment(){
const s = document.getSelection()
const r = s!.getRangeAt(0)
return r.cloneContents()
}
function getTextFromFragment(f: DocumentFragment) {
const walker = document.createTreeWalker(f, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
@kuboon
kuboon / main.py
Created Sep 17, 2020
HTML based GUI app with python flask
View main.py
from flask import Flask,request
app = Flask(__name__)
@app.route('/')
def index():
return "<form method='post' action='form'><input name='val'><button type='submit'>send</button></form>"
@app.route('/form', methods=['POST'])
def form():
View drive.ts
const res = await drive.permissions.create({
fileId,
requestBody: {
role: 'writer',
type: 'user',
emailAddress: 'ohkubo@heartrails.com'
}
})