Skip to content

Instantly share code, notes, and snippets.

View samthomson's full-sized avatar

Sam Thomson samthomson

View GitHub Profile
@samthomson
samthomson / Faucet.sol
Created April 17, 2022 11:10
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.7;
contract Faucet {
function withdraw(uint withdraw_amount) public {
require(withdraw_amount <= 100000000000000000);
payable(msg.sender).transfer(withdraw_amount);
}
run to edit git config: `git config -e --global`
```
[alias]
cleanup = "!git branch --merged | grep -v '\\*\\|master\\|develop' | xargs -n 1 -r git branch -d"
```
@samthomson
samthomson / gist:7adc9458669a69fae36ccf6bd9f5eeca
Created April 27, 2021 11:43
delta to array index ensuring within bounds
const newIndex = (items.length + currentIndex + delta) % items.length
import moment from 'moment'
const startTime = moment()
// thing to time
const endTime = moment()
const milliseconds = endTime.diff(startTime)
Logger.info(`time spent: ${milliseconds.toLocaleString()} ms`)
const boolInt = ((): number => {
if (true) {
return 1
} else {
return 0
}
})()
@samthomson
samthomson / gist:29fd10ab507129cc82b7dbcf446470bc
Created February 27, 2021 09:47
js deep log nested objects
import * as util from 'util'
console.log(util.inspect(returnData, false, null, true /* enable colors */))
@samthomson
samthomson / blocking sync promises
Created January 27, 2021 16:17
convert colleciton in to promises so that they can be awaited reliably
await Promise.all(
collection.map(async (item) => {
await doSomethingWith(item)
}),
)
@samthomson
samthomson / sleep
Created January 27, 2021 15:53
returns a promise that delays a certain number of milliseconds based on provided parameter
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
@samthomson
samthomson / gist:bbafca1a5caaececf043d751a6b610c1
Created November 18, 2020 13:17
node: write object to local json file
import * as fs from 'fs'
fs.writeFileSync('response.json', JSON.stringify(result))
@samthomson
samthomson / Bittrex_API_V3_Postman_Pre-request_script.md
Last active September 27, 2020 14:10
Bittrex API V3 Postman Pre request script

Assumes a BITTREX_API_KEY and BITTREX_API_SECRET is set on the collections variables.

// set up vars
let timestamp = new Date().getTime()
let url = request['url']
let method = request['method']
let contentHash = CryptoJS.SHA512(request['data']).toString(CryptoJS.enc.Hex);

var preSign = [timestamp, url, method, contentHash, ''].join('');
var signature = CryptoJS.HmacSHA512(preSign, pm.collectionVariables.get("BITTREX_API_SECRET")).toString(CryptoJS.enc.Hex);