Skip to content

Instantly share code, notes, and snippets.

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

Nathan Marley nmarley

🦀
我想吃一點點東西。
View GitHub Profile
@nmarley
nmarley / static-gen.sh
Last active September 28, 2017 19:04
Generate a static site from a WordPress site using wget
#! /bin/bash
wget -mk http://kotblog.dash.org/
@nmarley
nmarley / x.sh
Created September 28, 2017 19:04
Generate a static site from a WordPress site using wget
zy
@nmarley
nmarley / curl-websocket.sh
Created September 8, 2017 09:50 — forked from htp/curl-websocket.sh
Test a WebSocket using curl.
curl --include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: example.com:80" \
--header "Origin: http://example.com:80" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
http://example.com:80/
@nmarley
nmarley / Dockerfile
Last active October 11, 2017 20:33
DigitalOcean API Query Script
FROM alpine:3.5
RUN /bin/echo 'set -o vi' >> /etc/profile
RUN /bin/echo 'gem: --no-document' > /etc/gemrc
RUN apk update && apk upgrade && apk add --no-cache ruby ruby-dev ruby-io-console ruby-bigdecimal ruby-json ca-certificates && rm -fr /var/cache/apk/*
WORKDIR /app
COPY Gemfile Gemfile.lock query-resources.rb /app/
RUN gem install bundler
@nmarley
nmarley / do-tagsplit.sh
Created August 7, 2017 03:58
DigitalOcean tag splitter
#! /bin/bash
# TAGLIST=$(curl -s 169.254.169.254/metadata/v1/tags/)
TAGLIST="ansible-role:02-openvpn ansible-role:01-common app:OpenVPN name:testtagger01"
ROLE_TAGS=()
for T in $TAGLIST; do
IFS=:
read -r Key Value <<< "$T"
if [ "ansible-role" = "${Key}" ]; then
ROLE_TAGS+=($Value)
@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'