Skip to content

Instantly share code, notes, and snippets.

View nmarley's full-sized avatar
🦀
我想吃一點點東西。

Nathan Marley nmarley

🦀
我想吃一點點東西。
View GitHub Profile
@nmarley
nmarley / do-network.sh
Created July 27, 2017 20:57
DigitalOcean cloud-init metadata IP address helper script
#! /bin/bash
# DigitalOcean cloud-init metadata IP address helper script
METADATA_URL="http://169.254.169.254/metadata"
PUBLIC_IPV4="$(curl -fs -m 2 $METADATA_URL/v1/interfaces/public/0/ipv4/address)"
ANCHOR_IPV4="$(curl -fs -m 2 $METADATA_URL/v1/interfaces/public/0/anchor_ipv4/address)"
FLOATING_ACTIVE="$(curl -fs -m 2 $METADATA_URL/v1/floating_ip/ipv4/active)"
FLOATING_IPV4="$(curl -fs -m 2 $METADATA_URL/v1/floating_ip/ipv4/ip_address)"
@nmarley
nmarley / pstat.pl
Created July 10, 2017 06:16
"Perl stat" -- really old, saving here, but removing from hard drive
#! /usr/bin/perl
use strict;
use warnings;
use feature qw(say);
use Data::Dumper;
use File::Slurp;
use Carp;
use Fcntl ':mode';
use DateTime;
@nmarley
nmarley / tags.py
Last active June 17, 2017 22:57
quick/dirty Python script to use Docker for legacy Perl code to manage MP3/Id3 tags
import sys
import os
from pprint import pprint
import re
with open('list.txt', 'r') as f:
data = f.read()
filenames = [line for line in data.split('\n') if line]
@nmarley
nmarley / filter.sh
Created May 15, 2017 14:12
CloudTrail log parsing/event selection with jq
# `aws s3 sync` the cloudtrail files you want into a dir, then...
cat * | jq '.Records[] | select(.eventSource == "kms.amazonaws.com")' | jq '.userIdentity.arn'
@nmarley
nmarley / query-images.sh
Created April 16, 2017 02:54
Query AWS for specific Ubuntu image (AMI-ID), can be run against any region
#! /bin/bash
# get Ubuntu 16.04 AMI for default region
aws ec2 describe-images --filters Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170221 | jq -r '.Images[].ImageId'
# get same image AMI for ca-central-1
aws --region ca-central-1 ec2 describe-images --filters Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170221 | jq -r '.Images[].ImageId'
@nmarley
nmarley / date-range.py
Created March 21, 2017 15:36
Python date range from a starting date to today
import datetime
import sys
from pprint import pprint
today = datetime.datetime.today().date()
start = datetime.datetime(2011, 2, 12, 0, 0, 0, tzinfo=None)
next_day = start
while next_day.date() <= today:
pprint(next_day.date())
@nmarley
nmarley / README.md
Last active February 8, 2023 15:31
JSON Schema validation example in Node.JS

test json schema validation in Node.JS

Setup Package

$ npm i jsonschema --save

Test/Play:

$ node ./v.js
@nmarley
nmarley / README.md
Last active May 13, 2020 21:46
Python JSON Schema validation example

test json schema validation

Setup Virtualenv

$ virtualenv ./venv
$ ./venv/bin/pip install -r requirements.txt

Test/Play:

$ ./venv/bin/python ./v.py

@nmarley
nmarley / bitcoin_spv_wallet_overview.md
Created March 14, 2017 16:46 — forked from TOMOAKI12345/bitcoin_spv_wallet_overview.md
Bitcoin SPV Wallet Flow Overview

@nmarley
nmarley / mcsentinel.py
Last active February 8, 2018 02:24 — forked from tgflynn/mcsentinel.py
mcsentinel.py - Sentinel scheduler by Tim Flynn
#!/usr/bin/env python
import os
import sys
import math
import random
NSECONDS = 5*3600
NNODES = 4000