Skip to content

Instantly share code, notes, and snippets.

View mattlockyer's full-sized avatar
💭
🥳

Matt Lockyer mattlockyer

💭
🥳
View GitHub Profile
@mattlockyer
mattlockyer / get-fields.js
Last active January 23, 2020 16:20
Turn JSON / POJO into Firestore Fields for REST API
//only handles integerValue, doubleValue, stringValue and booleanValue
const getType = (val) => {
if (val === null) return 'nullValue'
const t = typeof val
switch (t) {
case 'number': return n % 1 === 0 ? 'integerValue' : 'doubleValue'
case 'string':
case 'boolean':
return t + 'Value'
}
@mattlockyer
mattlockyer / hmy_estimateGas_tests.txt
Created February 10, 2020 03:52
Harmony RPC endpoint hmy_estimateGas tests and results
curl -X GET http://localhost:9500 -H 'Content-Type: application/json' -d '{
"jsonrpc":"2.0",
"method":"hmy_estimateGas",
"params":[{
"from": "0x7c41e0668b551f4f902cfaec05b5bdca68b124ce",
"to": "0x7c41e0668b551f4f902cfaec05b5bdca68b124ce",
"value": "0x1"
}],
"id": 1
}'
@mattlockyer
mattlockyer / app.js
Last active April 25, 2020 15:30
A waaay simpler redux, redux-thunk friendly setup for reducer, state and actions
import { getReducer, getState } from '../util/redux-util'
//default state
const defaultState = {
toggle: false
}
//reducer
const type = 'appReducer'
export const appReducer = getReducer(type, defaultState)
export const appState = getState(type)
//actions
@mattlockyer
mattlockyer / countries.json
Created February 24, 2020 17:58
Country Code to Country Name, Unicode and Flag Emoji
{
"AC": {
"unicode": "U+1F1E6 U+1F1E8",
"name": "Ascension Island",
"emoji": "🇦🇨"
},
"AD": {
"unicode": "U+1F1E6 U+1F1E9",
"name": "Andorra",
"emoji": "🇦🇩"
@mattlockyer
mattlockyer / ebay-scrape.js
Created April 9, 2020 22:18
Scrapes Ebay Prices
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)
@mattlockyer
mattlockyer / rename.sh
Created April 30, 2020 23:40
Rename all files of a type in a folder with a sequential number scheme
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
@mattlockyer
mattlockyer / contraints.sql
Created May 11, 2020 18:56
Postgres - get constraints from table
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 */
@mattlockyer
mattlockyer / keybindings.json
Created May 13, 2020 00:57
Keyboard shortcuts for vs code
[
{
"key": "ctrl+]",
"command": "workbench.action.terminal.focusNext"
},
{
"key": "ctrl+[",
"command": "workbench.action.terminal.focusPrevious"
},
{
@mattlockyer
mattlockyer / docker.txt
Last active May 21, 2020 20:09
Docker notes if having trouble starting, manual, killing, etc...
# 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
@mattlockyer
mattlockyer / app.js
Last active May 26, 2020 15:52
Javascript Mutex to prevent re-entry from multiple method calls. Protect methods that modify app, localStorage or IndexedDB.
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