Skip to content

Instantly share code, notes, and snippets.

View tcrowe's full-sized avatar
💭
Account archived | See link

Tony Crowe tcrowe

💭
Account archived | See link
View GitHub Profile
@tcrowe
tcrowe / binary-command-exists.zsh
Created June 2, 2019 16:19
Bash or ZSH: Check if a binary or command exists
# which goes into dev null
# $? is the magic that tells us if it worked 0 = exists
if [[ `which nvm &>/dev/null && $?` != 0 ]]; then
source ~/.nvm/nvm.sh
fi
@tcrowe
tcrowe / ethersjs-abi-encode-decode.js
Last active April 20, 2022 16:38
ethersjs abi encode and decode
let ethers = require('ethers')
let abi = new ethers.utils.AbiCoder()
let types = ['address[][]', 'address[][]', 'address[][]']
let params = [[
[
'0x407d73d8a49eeb85d32cf465507dd71d507100c1',
'0x407d73d8a49eeb85d32cf465507dd71d507100c2',
@tcrowe
tcrowe / src-middleware-authenticated.js
Created September 13, 2019 20:45
express, sapper, polka authentication idea
/*
+ assuming you're using cookie-session or similar session
usage:
import authenticated from "./middleware/authenticated.js"
server.use(authenticated)
*/
@tcrowe
tcrowe / polka-express-http-proxy.js
Created August 23, 2019 01:49
polka sapper api proxy example
/*
they usually use ES Modules but i used CommonJS here
you can port it to suite your need
*/
const sirv = require("sirv");
const polka = require("polka");
const compression = require("compression");
@tcrowe
tcrowe / install-and-configure-mumble-server.zsh
Last active April 26, 2020 00:26
install and configure mumble server - set variables, run it, talk 👍
#!/bin/zsh
password=CHANGE1
serverpassword=CHANGE2
welcometext=CHANGE3
ssh my-server << EOF
# install
apt install -y mumble-server
@tcrowe
tcrowe / npm-auth-token.js
Last active February 2, 2020 18:55
npm auth token with zsh or bash and curl or node
// npm install superagent
const superagent = require("superagent");
// this is verdaccio's url ↓ but you could use like registry.npmjs.com if that is allowed in their TOS
const registryUrl = "http://127.0.0.1:4873";
const username = "myusername2";
const password = "mypassword2";
const frm ={
name: username,
@tcrowe
tcrowe / object-ification-of-promise.js
Created February 1, 2020 20:20
Turn async await promise into object result
/**
* Object-ification of a promise result
* @method to
* @param {promise} p
* @returns {array}
*/
const to = p =>
p.then(res => ({ err: null, res }))
.catch(err => ({ err }));
@tcrowe
tcrowe / tuple-ification-of-promise.js
Created February 1, 2020 20:12
Turn async await into tuple output
/**
* Tuple-ification of a promise result
* @method to
* @param {promise} p
* @returns {array}
*/
const to = p => p.then(res => [null, res]).catch(err => [err]);
/**
@tcrowe
tcrowe / clickable-svg-path-note.md
Created September 24, 2019 20:39
Reminer about clickable SVG path

A pal discovered a trick with SVG paths. It was not clickable by default!

He found that you must customize it with CSS:

figured it out, for future reference you need to set 
the "pointer-events" property on a path to make it
clickable. There are various options available.

Found a handy little reference here... 
@tcrowe
tcrowe / sapper-preload-example.svelte
Created September 25, 2019 21:17
Sapper preload instead of using stores for dynamic data
<script context="module">
/*
Preload runs on the client AND server
*/
export async function preload({ path, query, params, session }) {
console.log('path', path)
console.log('query', query)
console.log('params', params)