This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const get = (k, d = {}) => { | |
let v = localStorage.getItem(k) | |
try { | |
return JSON.parse(v || JSON.stringify(d)) | |
} catch (e) { | |
return v | |
} | |
} | |
export const set = (k, v) => localStorage.setItem(k, typeof v === 'string' ? v : JSON.stringify(v)) | |
export const del = (k) => localStorage.removeItem(k) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as nearlib from 'near-api-js' | |
const contractBytes = await fetch('./contract.wasm').then((r) => r.arrayBuffer()) | |
const hash = await crypto.subtle.digest('SHA-256', contractBytes) | |
const hash58 = nearlib.utils.serialize.base_encode(hash) | |
console.log(hash58) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useContext, useEffect } from 'react'; | |
import { store } from './state/store'; | |
import { onMount } from './state/test'; | |
const ExampleComponent = () => { | |
const { state, dispatch, update: updateStore } = useContext(store) | |
console.log(state) | |
const update = async () => { | |
// dispatch thunk wraps function with state, dispatch | |
const res = await dispatch(initNear()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { lock, unlock } from './mutex.js' | |
async function processCallsLikeQueue() { | |
// stop method calls here | |
await lock('processCallsLikeQueue()') | |
// ... | |
// code to protect from re-entry | |
// i.e. prevent multiple simultaneous calls to this part of the code | |
// ... | |
// let next method call in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start docker manually | |
sudo rm -rf /var/run/docker.pid; sudo dockerd & | |
# kill all docker ps | |
ps axf | grep docker | grep -v grep | awk '{print "kill -9 " $1}' | sudo sh | |
# restart as service | |
sudo systemctl restart docker | |
# build docker |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"key": "ctrl+]", | |
"command": "workbench.action.terminal.focusNext" | |
}, | |
{ | |
"key": "ctrl+[", | |
"command": "workbench.action.terminal.focusPrevious" | |
}, | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT con.* | |
FROM pg_catalog.pg_constraint con | |
INNER JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid | |
INNER JOIN pg_catalog.pg_namespace nsp ON nsp.oid = connamespace | |
WHERE | |
nsp.nspname = '<schema name>' | |
AND rel.relname = '<table name>'; | |
/* from: https://dba.stackexchange.com/a/214877/187757 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=1 | |
for i in *.jpg; do | |
new=$(printf "%04d.jpg" "$a") #04 pad to length of 4 | |
mv -i -- "$i" "$new" | |
let a=a+1 | |
done | |
# from https://stackoverflow.com/a/3211670/1060487 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cheerio = require('cheerio') | |
const request = require('request'); | |
let query = process.env.QUERY | |
if (!query) { | |
console.log('Please define an ENV var for QUERY="..."') | |
return -1 | |
} | |
query = encodeURIComponent(query) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AC": { | |
"unicode": "U+1F1E6 U+1F1E8", | |
"name": "Ascension Island", | |
"emoji": "🇦🇨" | |
}, | |
"AD": { | |
"unicode": "U+1F1E6 U+1F1E9", | |
"name": "Andorra", | |
"emoji": "🇦🇩" |