Skip to content

Instantly share code, notes, and snippets.

View brianonn's full-sized avatar

Brian Onn brianonn

  • Vancouver, Canada
View GitHub Profile
@brianonn
brianonn / set_fact.yml
Created March 23, 2018 00:33
ansible set_fact example
# from https://www.safaribooksonline.com/library/view/ansible-up-and/9781491915318/ch04.html
- name: get snapshot id
shell: >
aws ec2 describe-snapshots --filters
Name=tag:Name,Values=my-snapshot
| jq --raw-output ".Snapshots[].SnapshotId"
register: snap_result
- set_fact: snap={{ snap_result.stdout }}
@brianonn
brianonn / send_encrypted.sh
Created April 21, 2018 19:44
Octoblu/Meshblu sending encrypted data
# generate keypair for sending device
openssl genrsa -out send_device.key 2048
openssl rsa -in send_device.key -pubout > send_device.pub
# generate keypair for receiving device
openssl genrsa -out recv_device.key 2048
openssl rsa -in recv_device.key -pubout > recv_device.pub
# register the sending device
curl -X POST https://meshblu.octoblu.com/devices -H 'Content-Type: application/json' -d "{\"publicKey\": \"`cat send_device.pub | base64`\"}" > send_device.json
@brianonn
brianonn / my_ccc.sh
Created April 28, 2018 18:51
rsync script for cloning HD on OS X. The rsync flags are the same as Carbon Copy Cloner
#!/bin/bash
dest="/Volumes/Backup"
filter="${HOME}/.rsync-filter"
rsync="/usr/local/bin/rsync"
if [ -d "$dest" ]; then
sudo time nice -n19 ${rsync} -X -A -H -go --numeric-ids -D --protect-decmpfs -l -rtpx -N --fileflags --force-change --protect-args --delete-before --ignore-errors --filter="${filter}" // "${dest}"
sudo bless -folder "${dest}/System/Library/CoreServices"
else
@brianonn
brianonn / nginx.pig
Created May 6, 2018 23:02
Apache Pig script for nginx
register file:/home/hadoop/lib/pig/piggybank.jar
DEFINE EXTRACT org.apache.pig.piggybank.evaluation.string.EXTRACT;
RAW_LOGS = LOAD 's3://apiaxle-logs/*' USING TextLoader as (line:chararray);
LOGS_BASE = FOREACH RAW_LOGS GENERATE
FLATTEN(
EXTRACT(line, '^(\\S+) (\\S+) (\\S+) \\[([\\w:/]+\\s[+\\-]\\d{4})\\] "(.+?) (.+)&api_key=(.+?)(&.+)? (.+?)" (\\S+) (\\S+) "([^"]*)" "([^"]*)"')
)
as (
remoteAddr: chararray,
@brianonn
brianonn / moid.js
Created June 12, 2018 01:15
mongo objectid
var moid = function () {
var timestamp = (new Date().getTime() / 1000 | 0).toString(16);
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function() {
return (Math.random() * 16 | 0).toString(16);
}).toLowerCase();
};
console.log(moid())
@brianonn
brianonn / keybase.md
Created June 24, 2018 08:40
keybase.md

Keybase proof

I hereby claim:

  • I am brianonn on github.
  • I am brianonn (https://keybase.io/brianonn) on keybase.
  • I have a public key ASAAUGO9rSvZRo6AoFeFjpB4IOt1FrftRqeEqn42O9b2kAo

To claim this, I am signing this object:

@brianonn
brianonn / gist:66d7cb476f85d978a620461729925f29
Created July 30, 2018 16:33 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.

Using self-signed certificate.

Create a Certificate Authority root (which represents this server)

Organization & Common Name: Some human identifier for this server CA.

openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
@brianonn
brianonn / create_eth_wallet.py
Last active October 30, 2018 23:58
make an ethereum address
#!/usr/bin/env python3
import os
import gnupg
from pywallet import wallet
# OS X hack fixed in a newer release of gnupg
gnupg._parsers.Verify.TRUST_LEVELS["ENCRYPTION_COMPLIANCE_MODE"] = 23
seed=wallet.generate_mnemonic()
@brianonn
brianonn / Vagrantfile
Created November 4, 2018 01:20
vagrant with ansible
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cpus", "1"]
vb.customize ["modifyvm", :id, "--memory", "768"]
vb.name = "novoansible"
@brianonn
brianonn / new_git_repo.md
Created November 24, 2018 05:09
new git repo
touch README.md
git init
git add README.md
git commit -m "first commit"

## push to remote
# the remote repository must already exist 
git remote add origin https://github.com/brianonn/newrepo.git
git push -u origin master