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 / 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
@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,
const res = await drive.permissions.create({
fileId,
requestBody: {
role: 'writer',
type: 'user',
emailAddress: '[email protected]'
}
})
@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 / 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)
}
}
@kuboon
kuboon / index.html
Created April 3, 2020 12:35
aurelia
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber Gist uses dumber bundler, the default bundle file
import random
import struct
N=32
def rp(a) :
a=list(range(0,32))
x=0
for i in range(0,N-2) :
N=32
BYTE = false
x0=[0]*N
x1=[0]*N
x2=[0]*N
a=[0]*N
N=32
BYTE = false
x0=[0]*N
x1=[0]*N
x2=[0]*N
a=[0]*N