Skip to content

Instantly share code, notes, and snippets.

@gronnbeck
gronnbeck / restartafter.py
Created August 30, 2021 09:41
Restart a program after x seconds
import subprocess
import time
def start_program(program):
proc = subprocess.Popen([program], stdout=subprocess.PIPE)
return proc
def run(program, time_seconds):
while True:
@gronnbeck
gronnbeck / monitor.py
Created August 29, 2021 17:46
Simple script for monitoring a subprocess and restart it based on string match
import subprocess
import sys
def start_program(program):
proc = subprocess.Popen([program], stdout=subprocess.PIPE)
return proc
def monitor_program(proc, match):
for line in iter(proc.stdout.readline, ''): # replace '' with b'' for Python 3
sys.stdout.write(line)
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: scalingredis-example
spec:
replicas: 3
selector:
matchLabels:
name: scalingredis-example-api
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: scalingredis-example
spec:
replicas: 3
selector:
matchLabels:
name: scalingredis-example-api
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
redisResp := redisClient.Cmd("GET", "known-key")
if redisResp.Err != nil {
panic(err)
}
str, err := redisResp.Str()
// window = [index, length] same for minWin
S = A D O B E C O D E C B F A N E T S
window = [0,0]
minWin = [0,0]
minlen = 0
S = [A] D O B E C O D E C B F A N E T S
window = [0,1]
minWin = [0,0]
function factory(value) {
return function callback(error) {
// handle error
}
}
a.on("error", factory(value));
@gronnbeck
gronnbeck / pinglog.sh
Created October 7, 2015 07:07
Log all the pings
ping $PING_IP | perl -nle 'BEGIN {$|++} print scalar(localtime), " ", $_' > $PING_OUT &
@gronnbeck
gronnbeck / gist:10971577
Last active August 29, 2015 13:59
Testing the node VM module
var vm = require('vm')
try {
vm.runInThisContext('var hello = "world"; console.log("Hello " + hello);');
} catch(e) {
console.log('Failed unexpectedly')
}
from flask import Flask
import couchdb as couch
from uuid import uuid4
# set up db connection / a localhost connection
server = couch.Server()
db = server["short_url"]
# set up flask app
app = Flask(__name__)