Skip to content

Instantly share code, notes, and snippets.

@manos
manos / foo.sh
Created June 21, 2020 00:18
local dev grafana/influx setup script
### dev_setup.sh:
#/bin/bash
#
# Sets up your environment!
# Adds all necessary services and automates a few things..
##
## prerequisites
if [ ! -d /usr/local/Homebrew ]; then
@manos
manos / gist:dd482006890a4845a3fd09205eb00f32
Created April 9, 2020 15:06
unzip files dropped in a directory, move them, delete the zip file (an inotify-based service). perfect for templates downloaded from thingiverse.
charlie@barrel(~)% cat /usr/local/bin/inotify_unzip_things.sh 10.03
#!/bin/bash
dir='/stash/stash/3D Printing'
cd "$dir"
while [ 1 ]; do
inotifywait -m "$dir" -e create --format '%f'|
while read -r file; do
sleep 1
if [[ "$file" =~ ^.*\.zip$ ]]; then
name=`basename "$file" .zip`
@manos
manos / gist:1d9c19af2ae1881964b09fefc1547148
Created February 27, 2020 07:30
pull from prometheus, insert into influxdb
import requests
from influxdb import InfluxDBClient
URL="http://localhost:9090/api/v1/query?query={metric}[{range}]"
client = InfluxDBClient(host='localhost', port=8086)
client.switch_database('lendy')
measurements = ["account_balance", "account_balance_available", "active_offer_amount", "active_offer_count", "alltime_earnings_apr", "assets_under_management", "bot_errors", "bot_last_ran_seconds_ago", "bot_run_times", "bot_runs", "capital_working", "daily_earning", "days_for_current_rate", "exchange_rate", "exchange_volume", "frr_amount", "frr_rate", "lend_buckets", "lend_depth_minutes", "lend_rate", "lend_rate_max", "lend_rate_min", "lend_volume", "lendbook_total", "loan_average_length", "loan_average_seconds_left", "loan_count", "loan_days_bucket", "loan_days_count", "loan_days_sum", "loan_hourly_earnings", "loan_weighted_rate", "offers_cancelled", "offers_filled", "percentile_days", "percentile_hours", "rate_floor_apr", "total_bot_runs", "total_loan_earnings", "total_loans", "total_loans_amount", ]
for me
@manos
manos / gist:8359450
Last active September 20, 2019 14:59
Script to fetch SPOT url and: 1) save lat,lon coordinates to a file, 2) save all spot messages as JSON, 3) and xml as well. Files get re-written on every run, if there's new data.
#!/usr/bin/python
"""
Script to fetch SPOT url and: 1) save lat,lon coordinates to a file, 2) save all spot messages as JSON, 3) and xml as well.
Files get re-written on every run, if there's new data. Oh, it writes to stderr if batteryState isn't GOOD - so if you run from cron, you'll get email when your spot batteries need to be changed.
"""
import urllib2
import json
import sys
""" Edit these items: """
@manos
manos / gist:6922476
Created October 10, 2013 17:42
bashwrap.sh, to print full 'bash -x' output of the run, iff there was stderr. When run from cron, now you get *context* if something errors out.
#!/bin/bash
#
# runs the provided script/arguments with bash -x, and prints ALL stderr/stdout
# (bash -x output) if any stderr is present. Otherwise, it silently exits.
#
output=/tmp/output-$$
# send stdout + stderr to the logfile, in order, and let stderr flow through.
# run in a sub-process, so the re-mapped stdout/stderr file descriptors are
#!/usr/bin/env kpython
import time
import boto.dynamodb
conn = boto.dynamodb.connect_to_region('us-east-1')
table = conn.get_table('test_rtb_user_data')
start_time = time.time()
table.update_throughput(read_units=50, write_units=10)
waiting for dynamodb to update provisioned capacity...
ACTIVE 50 80 took: 45.4535069466
ops-dev005(~)% !vi
vi dynamo.py
ops-dev005(~)% ./dynamo.py
waiting for dynamodb to update provisioned capacity...
ACTIVE 50 100 took: 65.5947580338
ops-dev005(~)% !vi
vi dynamo.py
ops-dev005(~)% ./dynamo.py
:!/usr/local/share/python/pep8 --ignore=E501 handlers.py
handlers.py:24:1: E302 expected 2 blank lines, found 1
handlers.py:27:12: E221 multiple spaces before operator
handlers.py:30:64: E502 the backslash is redundant between brackets
handlers.py:31:29: E127 continuation line over-indented for visual indent
handlers.py:34:36: E201 whitespace after '('
handlers.py:34:46: E202 whitespace before ')'
handlers.py:47:21: E127 continuation line over-indented for visual indent
handlers.py:53:44: E502 the backslash is redundant between brackets
handlers.py:57:73: E502 the backslash is redundant between brackets
import boto.vpc
def get_subnet_id(vpc_conn, vpc_id, zone):
subnets = vpc_conn.get_all_subnets(filters={'availabilityZone': zone})
return subnets
az = 'us-east-1a'
cc001(...dules/kconsole/manifests)% pssh.py --timeout=9999 --query '--region=us-east-1 Name:apiservices-a01' 'grep Finished /var/log/syslog'
matched the following hosts: apiservices-a017.krxd.net, apiservices-a014.krxd.net, apiservices-a018.krxd.net, apiservices-a015.krxd.net, apiservices-a013.krxd.net, apiservices-a016.krxd.net, apiservices-a010.krxd.net, apiservices-a012.krxd.net, apiservices-a011.krxd.net
[apiservices-a017.krxd.net]
STDOUT:
Apr 19 15:49:43 apiservices-a017 puppet-agent[4058]: Finished catalog run in 545.79 seconds
[apiservices-a018.krxd.net]
STDOUT:
Apr 19 15:53:28 apiservices-a018 puppet-agent[4047]: Finished catalog run in 564.96 seconds