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 / gsheetDate.ts
Created November 12, 2020 02:52
convert from/to google sheet date serial
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 October 29, 2020 03:54
f2 matrix
#include <stdio.h>
#include <assert.h>
#define N 16
#define K 8
#include "global.h"
#include "chash.c"
#include "inv_mat.c"
typedef struct {
@kuboon
kuboon / keybase.md
Created October 26, 2020 15:35
keybase id

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 / getSelectionWithAlt.ts
Last active October 10, 2020 02:58
document.getSelection with img.alt text
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 / install_gcloud.sh
Created October 6, 2020 01:26
install gcloud on Ubuntu
#!/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
const res = await drive.permissions.create({
fileId,
requestBody: {
role: 'writer',
type: 'user',
emailAddress: 'ohkubo@heartrails.com'
}
})
@kuboon
kuboon / jsonComp.ts
Created June 22, 2020 06:38
JSON compare
export function comp(x: any, y: any): boolean {
if (typeof x === 'object') {
const keys = Object.keys(x)
if (keys.length !== Object.keys(y).length) return false
return keys.every(k=>comp(x[k], y[k]))
}
return x === y
}
const a = {a:1,b:2,c:{a:1,b:3}}
@kuboon
kuboon / enc_dec.ts
Last active June 12, 2020 01:03
Typescript nodejs stdlib enc/dec sample
import * as crypto from 'crypto'
import assert from 'assert'
const ivKey = 'randomString1-fah3f;aklajr'
const initialVec = Buffer.alloc(16, 0)
crypto
.createHash('sha256')
.update(ivKey)
.digest().copy(initialVec)
@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}"
@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"