Skip to content

Instantly share code, notes, and snippets.

export const swapObjKeyValue = (json: any) => {
const ret: any = {}
for (const key in json) {
ret[json[key]] = key
}
return ret
}
@wildskyf
wildskyf / memoMachine.js
Last active September 24, 2019 07:29
Generated by XState Viz: https://xstate.js.org/viz, machine for memo
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@wildskyf
wildskyf / loadPreference.js
Last active July 28, 2019 09:20
Web extension: use for updating storage version. credit to @ettoolong
const loadPreference = async defaultPreference => {
let results = await browser.storage.sync.get()
if ((typeof results.length === 'number') && (results.length > 0)) {
results = results[0]
}
if (!results.version) {
await browser.storage.sync.set(defaultPreference)
return defaultPreference
@wildskyf
wildskyf / confirm.js
Created May 19, 2019 06:48
Useful script for pixelfederation
// https://portal.pixelfederation.com/en/profile/friendPlayers/me#
$('a').toArray().filter( a => $(a).text().trim().includes('Confirm') ).forEach(a => a.click())
var map = {}
function fibonacci(n) {
if (n <= 1) return n
map[n-2] = map[n-2] || fibonacci(n-2)
map[n-1] = map[n-1] || fibonacci(n-1)
return map[n-2] + map[n-1]
}
cloneJson = (a) -> JSON.parse JSON.stringify(a)
@wildskyf
wildskyf / tw_id_number_validator.js
Created January 15, 2019 07:19
Taiwan National Identification Number Validator 台灣身分證驗證
function isValidIdNumber(str) {
if(!/^[A-Z]\d{9}$/.test(str)) return false;
var multiplier = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1];
var map = {
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16, 'H': 17, 'I': 34,
'J': 18, 'K': 19, 'L': 20, 'M': 21, 'N': 22, 'O': 35, 'P': 23, 'Q': 24, 'R': 25,
'S': 26, 'T': 27, 'U': 28, 'V': 29, 'W': 32, 'X': 30, 'Y': 31, 'Z': 33
};
var decoder = function(id_number){
// Kaohsiung 100 - 103 Popularity Parser
// fetch data from http://cabu.kcg.gov.tw/Stat/StatRpts/StatRpt1.aspx?yq=103&mq=1&dq=64000030
//
// LICENSE: MIT by Geng Zhi Fann
//
var fetch = require('node-fetch')
var cheerio = require('cheerio')
var fs = require('fs')
const iconv = require('iconv-lite');
.
├── config.json
├── index.bin
├── output
│   ├── d18955
│   │   ├── d18955.cif
│   │   └── d18955.tex
│   ├── d18955a
│   │   ├── d18955a.cif