Skip to content

Instantly share code, notes, and snippets.

View gabmontes's full-sized avatar

Gabriel Montes gabmontes

View GitHub Profile
@gabmontes
gabmontes / create-bitcoin-tx.js
Created December 7, 2017 01:36
Create bitcoin transaction from BIP38 private key
const { Transaction } = require('bitcore-lib')
const { decrypt } = require('bip38')
const encryptedKey = '<private key beginning with 6>'
const password = '<private key password>'
const privateKey = decrypt(encryptedKey, password).privateKey
// Check UTXO info at https://insight.bitpay.com/api/addr/<origin address>/utxo
const utxo = {
@gabmontes
gabmontes / erc20EventsListener.js
Last active July 18, 2021 09:10
Very simple example of an ERC20 token events listener
const Web3 = require('web3')
const erc20Abi = abi = require('human-standard-token-abi')
const config = {
node: 'localhost:8546',
address: '0x0000000000000000000000000000000000000000' // set to contract address
}
const provider = new Web3.providers.WebsocketProvider(`ws://${config.node}`)
const web3 = new Web3(provider)
@gabmontes
gabmontes / env-status.sh
Created August 7, 2017 17:57
Gather information about the runtime environment
#!/usr/bin/env bash
date > env.log
lsb_release -a >> env.log
echo "node: $(node --version)" >> env.log
echo "nodejs: $(nodejs --version)" >> env.log
echo "npm: $(npm --version)" >> env.log
echo "git HEAD: $(git rev-parse --short HEAD)" >> env.log
git status >> env.log
@gabmontes
gabmontes / netParams.js
Last active May 8, 2017 04:10
Brute force approach to find desired bitcoin network params
'use strict'
const bitcore = require('bitcore-lib')
const ROUNDS = 15
const targetStrings = {
networkMagic: 'mYnT',
pubkeyhash: 'G',
scripthash: '2',
@gabmontes
gabmontes / .eslintrc.json
Created March 23, 2017 18:15
ESLint configuration template
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "script",
"ecmaFeatures": {
"globalReturn": false,
"impliedStrict": false,
"jsx": true,
"experimentalObjectRestSpread": false
}
const mapFields = (obj, map) =>
Object.keys(map)
.map(key => ({ key, value: obj[map[key]] }))
.reduce((res, { key, value }) => Object.assign(res, { [key]: value }), {})
const waterfall = promises => init => promises.reduce((chain, promise) => chain.then(promise), Promise.resolve(init))
@gabmontes
gabmontes / prune-branches.sh
Last active September 1, 2022 17:24
Prune repo and remove local branches deleted in origin
#!/bin/bash
if [ ! -d .git ]; then
echo Not a git repo
exit
fi
if ! (git remote | grep -q origin); then
echo No origin remote
exit
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFhqXdYBCADLd6j3IgA+ziom/ZLPkX1niDZ6EiDkA98rP3q+T7nSuQKpIooq
Kt0mTRpqxdroCp9O+IOizvJDpK6pb1kefDvTfren5xvVU3O/X4ihm9/W8VHCjgaF
zKzsIL3vH+Q61yTOxyfmq6nHbuoYPsyWcRoYOShCQTz/4XmUB9HHe/+Y46qEERcp
sbkJci0yDYCEtPk/Dri21NvNcRf8dJkYud36sRVesvWziXvY+eJCsP8+LgsP7wLA
5V4rhpV5eyWzFdxhX3q8qhKzOJlJeoudIAH0WmeDvWVHlWcOCp1WVoCdT4IVLduf
drEd1uO5vjv3y22H2KRaaibSFdYRO6T408IHABEBAAG0IUdhYnJpZWwgTW9udGVz
IDxnYWJyaWVsQGJsb3EuY29tPokBNwQTAQgAIQUCWGpd1gIbAwULCQgHAgYVCAkK
CwIEFgIDAQIeAQIXgAAKCRCYoLLoABE9pT5jB/0aoRG9AxqzanQydh+zB8QlWuXA
@gabmontes
gabmontes / main.js
Created December 6, 2016 17:37
JsonParser coding exercise solution. 50 minutes to complete the exercise. Room for improvement? Definitely!
function JsonParser() {}
function convert(token, type) {
if (type === "number") {
return Number(token);
} else if (type === "string") {
return String(token);
}
}