Skip to content

Instantly share code, notes, and snippets.

@lloesche
lloesche / test.rb
Last active May 9, 2018 14:26
Just a test
#!/usr/bin/env ruby
require 'logger'
STDOUT.sync = true
log = Logger.new(STDOUT)
log.level = Logger::DEBUG
loop do
log.info "Hello World"
puts "Hello puts"
STDERR.puts "Hello stderr"
sleep 30
@lloesche
lloesche / zkdump.py
Created May 16, 2018 16:40
dump DC/OS pre-cockroachdb IAM data
#!/usr/bin/env python3
import logging
logging.basicConfig()
from kazoo.client import KazooClient
zk = KazooClient(hosts='10.0.28.160:2181', auth_data=[("digest", "super:xxxxxxxxxx")])
zk.start()
data, stat = zk.get("/bouncer/datastore/data.json")
text_file = open("data.json", "w")
text_file.write(data.decode("utf-8"))
@lloesche
lloesche / tox265.sh
Created March 13, 2016 22:07
encode input file to hevc
#!/bin/bash
set -euo pipefail
infile="$1"
preset=veryfast
audiobitrateperchannel=64
ffmpeg_docker='lloesche/nginx-fatpack'
originfile=$infile
[ ! -f "$infile" ] && \
echo "file $infile not found" && \
@lloesche
lloesche / pullall.sh
Last active February 7, 2019 15:13
Checkout/Pull all repos of a Github organization
#!/bin/bash
set -o errexit -o pipefail
org=dcos-terraform
parallel=10
function main {
local num_repos=-1
local page=1
local i
local x
@lloesche
lloesche / migrate.sh
Last active June 3, 2019 18:51
Backup/Restore DC/OS Services and Jobs from one cluster to another in a suspended state
CLUSTER_A=olddcos
CLUSTER_B=newdcos
# BACKUP SERVICES
dcos cluster attach $CLUSTER_A
curl -H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/service/marathon/v2/apps | \
jq '.[] | del(.[].version) | del(.[].uri) | del(.[].versionInfo) | del(.[].tasksStaged) | del(.[].tasksRunning) | del(.[].tasksHealthy) | del(.[].tasksUnhealthy) | del(.[].deployments)' > apps.json
for id in $(jq -r '.[] | "\(.id)"' apps.json); do cleanid="${id//\//_}"; jq ".[] | select(.id==\"$id\") | .instances=0" apps.json > service.${cleanid:1}.json; done
# BACKUP JOBS
#!/usr/bin/env python
import base64
import os
from cryptography.fernet import Fernet, MultiFernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
psk = "superSecretPreSharedKey"
salt = os.urandom(16)
content = "Super secret data"
#!/usr/bin/env python
import os
import json
import cherrypy
import time
import threading
from cklib.graph import Graph
from cklib.graph.export import node_from_dict
from prometheus_client import Summary
from prometheus_client.exposition import generate_latest, CONTENT_TYPE_LATEST
@lloesche
lloesche / short2long_regions.py
Last active January 10, 2022 22:14
boto short to long region names for use with AWS pricing API
# Get the long region names used by the AWS Pricing API
#
# There's currently no proper API to do this
#
# Example:
# print(SHORT_TO_LONG_REGIONS['us-west-2'])
# > US West (Oregon)
from pkg_resources import resource_filename
@lloesche
lloesche / process.py
Created August 22, 2019 13:33
Python coding challenge
#!/usr/bin/env python3
from pprint import pprint
document_uri = 'https://gist.githubusercontent.com/demersdesigns/4442cd84c1cc6c5ccda9b19eac1ba52b/raw/cf06109a805b661dd12133f9aa4473435e478569/craft-popular-urls'
def process(document, num_threads=10):
"""Processes a document either found on the local disk or a remote http/https URI
The function reads the document (either from a local file or remote URL) and finds all the http and https URLs in it.
@lloesche
lloesche / git-cleanout.sh
Created October 6, 2021 14:17
Switch to main branch and delete all local git branches
git checkout $(git branch | grep -E "(main|master)" | sed -e 's/*\s\+//') && git branch | grep -vE "(main|master)" | xargs git branch -D