Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
set -e # all err
search_dir=$1
for entry in "$search_dir"/*
do
new=$(dirname "$entry")/$(basename "$entry").m4a
echo "${entry}"
new=${new/".flac"/}
echo $new
@tekton
tekton / get_url.py
Created January 9, 2019 06:22
concurrent url requests
import concurrent.futures
import urllib.request
import argparse
import json
import time
def make_call(data):
headers = data["headers"]
uri = data["uri"]
@tekton
tekton / get_git.py
Created December 8, 2018 04:35
download all repos for a user
import urllib.request
import subprocess
import argparse
import json
def call_github_repos(username, oauth=None, base_url="https://api.github.com"):
headers = {"Accept": "application/vnd.github.v3+json"}
if oauth:
headers["Authorization"] = "token {}".format(oauth)
@tekton
tekton / brackets.py
Created August 16, 2017 23:26
Randomized brackets of randomization
import random
import pprint
import copy
from collections import defaultdict
root_people = [
"P1",
"P2",
"P3",
"P4",
@tekton
tekton / process_ping.py
Created December 21, 2016 14:28
process ping output in python
import subprocess
import re
regex = "(?P<bytes>\d+) bytes from (?P<ip>\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}): icmp_seq=(?P<icmp>\d+) ttl=(?P<ttl>\d+) time=(?P<ms>\d+.\d+) ms"
r = re.compile(regex)
# compiling ahead of time speeds up other runs when more than one server is needed to be reached
def ping_server(ip="localhost", count=10, *args, **kwargs):
rtn_list = []
@tekton
tekton / logstash.assign.primary.py
Created February 25, 2016 17:56
Way to help elastichsearch assign primaries
import urllib2
import random
import json
import argparse
def get_primary(rotation):
return rotation[random.randint(0, len(rotation)-1)]
@tekton
tekton / yajpp.py
Created January 5, 2016 01:11
Yet Another JSON Pretty Print
import ujson as json
import argparse
import logging
logger = logging.getLogger(__name__)
def get_json(fn):
try:
with open(fn) as f:
@tekton
tekton / wait_for_redis.bash
Created November 8, 2015 07:45
Wait for a local redis slave, then start your app!
!/bin/bash
X="`/opt/redis/redis-3.0.3/src/redis-cli ping`"
echo ${X}
while [ "${X}" != "PONG" ]; do
echo "redis slave not yet ready"
echo "${X}"
sleep 30
X="`/opt/redis/redis-3.0.3/src/redis-cli ping`"
@tekton
tekton / iptables_update.bash
Last active September 23, 2015 16:30
Using the "standard" locations for openvpn settings this will create a self contained file for connecting
#!/bin/bash
sudo iptables -A INPUT -i tun+ -j ACCEPT
sudo iptables -A FORWARD -i tun+ -j ACCEPT
sudo iptables -A FORWARD -i tun+ -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
# be sure to replace 10.8.0.0/24 with whatever is in your settings, this example for default install
sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
sudo iptables -A OUTPUT -o tun+ -j ACCEPT
@tekton
tekton / gist:736ba476aa416e413d2d
Created May 22, 2015 02:44
operator_string_switch
"""
The goal here is to create a "switch" like environment to allow for using
strings and other representations for dynamic comparison of two values.
Uses the operator library: https://docs.python.org/2/library/operator.html
"""
import operator
OPS = {
'=': operator.eq,