Skip to content

Instantly share code, notes, and snippets.

View junderw's full-sized avatar

Jonathan Underwood junderw

  • Tokyo, Japan
  • 06:31 (UTC +09:00)
View GitHub Profile
@junderw
junderw / prunegit.sh
Created April 9, 2019 09:20
Some commands for cleaning up my git folders... too many branches over time.
# Get rid of remotes
git fetch --prune --all
# Check branches for stuff you might want to keep
# This will show branches that are NOT on the remote for origin or upstream
git branch | grep -v "$(git branch --remote | grep -e "origin/\|upstream/" | grep -v "\->" | cut -d/ -f2)"
# Here's another one to check. checks your local master and gives any branches that are merged to master
git branch --merged=master | grep -v master
@junderw
junderw / nordvpnconnect.sh
Created December 29, 2018 16:11
NordVPN: JPN or USA to connect to the country you want.
#!/bin/bash
SELECTION=$1
if [ -z "$1" ]
then
SELECTION="JPN"
fi
# Default JPN
CODE=108
@junderw
junderw / create_dockers.sh
Created February 8, 2018 02:51
lndのDockerを利用して、A <> B <> C の2チャンネル構成を構築するためのスクリプト
#!/bin/bash
# docker, docker-compose, bash, jq, sed 必要。
# このスクリプトはLinuxで作られたので、各コマンドの細かい使い方が違ってたらすみません。
# OSXは使ったことないので。。。
#
# lndのgithubをクローンしないといけません。例えば:
#
# rm -rf /tmp/lndtest
# mkdir -p /tmp/lndtest
@junderw
junderw / createNewRegtestServer.sh
Last active November 19, 2018 09:33
Simple setup for Ubuntu 18.04 server
### new ubuntu 18.04 server
### Be sure to run
# sudo apt-get update && sudo apt-get -y upgrade && sudo reboot
### For security updates
### Then run this script with passwordless sudo account ubuntu (default for ubuntu AWS EC2):
# CERTDOMAIN=something.yourdomain.com CERTEMAIL=mailname@yourdomain.com ./thisScript.sh
# Install Bitcoin 0.17.0 etc.
sudo add-apt-repository -y ppa:bitcoin/bitcoin &>/dev/null
sudo apt-get update &>/dev/null
@junderw
junderw / lightning_handson_JP.sh
Last active September 25, 2018 09:04
Bitcoin TestnetのDockerを先ず始めてみましょう。
# これを実行して lnd を起動
LIST=(\
188.166.148.62:18333 \
159.203.125.125:18333 \
); \
INDEX=$((RANDOM % 2)); \
NODE=${LIST[$INDEX]}; \
docker run -d \
-v /tmp/lndock:/root/.lnd \
-v /tmp/lndockdata:/data \
@junderw
junderw / csp.js
Created July 6, 2018 06:27
An efficient way of writing CSP directives in NodeJS using template literals. (You can copy and paste URLs, domains, whatever from excel sheet columns and vice versa)
const CSP_DIRECTIVES = `
default-src
'self'
;
object-src
'none'
;
report-uri
someURL
@junderw
junderw / .bashrc
Created June 16, 2018 03:03
Function for adding keybase subteam
make_keybase_subteam(){
# usage:
# make_keybase_subteam myteam newsubteam
# creates the subteam, sets good defaults, then turns it into a big team.
# will automatically join subteam.
if [ -z "$1" ]; then
echo "need to specify team name"
return 1
else
@junderw
junderw / pbkdf2.js
Created May 6, 2018 07:07
pbkdf2 for modern browsers' JavaScript
async function pbkdf2(message, salt, iterations, keyLen, algorithm) {
const msgBuffer = new TextEncoder('utf-8').encode(message)
const msgUint8Array = new Uint8Array(msgBuffer)
const saltBuffer = new TextEncoder('utf-8').encode(salt)
const saltUint8Array = new Uint8Array(saltBuffer)
const key = await crypto.subtle.importKey('raw', msgUint8Array, { name: 'PBKDF2' }, false, ['deriveBits'])
const buffer = await crypto.subtle.deriveBits({ "name": 'PBKDF2', "salt": saltUint8Array, "iterations": iterations, "hash": algorithm }, key, keyLen * 8)
const hashArray = Array.from(new Uint8Array(buffer))
const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('')
return hashHex
@junderw
junderw / convertSegwit.js
Created September 6, 2017 06:41
Convert all your existing addresses from bitcoind to segwit P2SH addresses (multisig will not work)
'use strict';
// first, run sudo apt-get install jq nodejs npm
// second, run npm install bluebird co to install dependencies, and make sure bitcoin-cli can run these commands.
// third, run node thisScript.js and it will change all the addresses on your bitcoind into segwit addresses.
var Promise = require('bluebird');
var co = require('co');
var exec = Promise.promisify(require('child_process').exec);
var main = function() {
// npm install git://github.com/bitcoinjs/bitcoinjs-lib.git#56dfb873d3f05817e19befa976592bc0f371a6d3
// installing the above commit of bitcoinjslib will allow you to take the var redeemScript and
// create a bech32 raw segwit address with this function:
// var bech32address = bitcoin.address.fromOutputScript(redeemScript)
var bitcoin = require('bitcoinjs-lib')
var mnemonic = require('bip39')
// log output near bottom
function main() {
// mnemonic seed starts here
var seed = mnemonic.mnemonicToSeed('print common jewel hospital hip fish auction indicate depth ignore ship tissue')