Skip to content

Instantly share code, notes, and snippets.

@koma5
koma5 / delo.sh
Created March 23, 2011 22:03
removes oldest file in a given folder, if the filesystem only has 10 Gigs remaining.
#!/bin/sh
dir=$1
minGigs=$2
available=`df --sync $dir | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{print $4}'`
#10 Gbytes in Kbytes
min=$(($minGigs*1024*1024))
if [ $min -gt $available ]
@koma5
koma5 / scp_films.sh
Created April 9, 2011 19:51
copy all films in a given directory
#! /bin/sh
torrent=$1
#destination=$2
destination="root@172.16.52:/streamer/movie/"
extension="\
.avi \
.mp4 \
.mkv \
@koma5
koma5 / bigFile.bat
Last active January 3, 2016 21:19
generate 10k 1MB (1048576 bytes) files.
@echo off
title bigFile.bat
set /a x=0
del bigFile
mkdir bigFile
:loopname
fsutil file createnew bigFile\F%x%.tmp 1048576
@koma5
koma5 / pingLoop.bat
Created January 21, 2014 07:11
ping until it pings back and than do something...
:wooot
ping -n 5 example.com
IF "%ERRORLEVEL%"=="0" GOTO :end
GOTO :wooot
:end
@koma5
koma5 / mqttThermostat.py
Created December 13, 2016 18:32
Usage : ./mqttThermostat.py minTempC maxTempC stopTime
#!/usr/bin/python
import mosquitto, sys, datetime
min = float(sys.argv[1])
max = float(sys.argv[2])
stopTime = datetime.datetime.strptime(sys.argv[3], "%H:%M").time()
@koma5
koma5 / mqttHeartbeat.py
Last active December 13, 2016 18:43
every minute like that: byteli/mqtt/heartbeat 19:40:01 up 6 days, 4:42, 1 user, load average: 0.00, 0.00, 0.00
import os, time, mosquitto, subprocess
# cronjon
# */2 * * * * /usr/bin/python /root/mqttHeartbeat.py 2>&1 > /dev/null
pidFile = '/var/run/mqttHeartbeatPid'
def on_connect(userdata, flags, rc):
print "connected..."
@koma5
koma5 / magnetHashHexPic.py
Created December 13, 2016 18:51
create a grayscale picture of magnet links
#!/usr/bin/python
import Image, sys, random
hash = random.choice(['411A7A164505636AB1A8276395B375A3A30BFF32',
'79816060EA56D56F2A2148CD45705511079F9BCA',
'f5615dfb80ac995787c1b2219a75df7805278dea',
'43b21801f59336b9271a6c5113904fb72de99ed3',
'938802790a385c49307f34cca4c30f80b03df59c'])
if(len(sys.argv) == 4):
# make sure user.name and user.email are set correctly this time
# check with
git log --format=fuller
# fix author
git rebase -i --root -x "git commit --amend --author 'John Doe <john.doe@example.org>' -CHEAD"
# fix date of commit to date of authoring
git filter-branch --env-filter '
@koma5
koma5 / mqttTempColorScale.py
Last active December 15, 2016 16:51
mqtt color temp scale from blue for -15 C° to red for 40 C° via green
# -*- coding: utf-8 -*-
import mosquitto
def on_connect(client, userdata, rc):
client.subscribe("vw/temp/1")
def on_message(client, userdata, msg):
rgb = colorWheel(scaleTempToColor(float(msg.payload)))
client.publish("vw/neo/color", ','.join(str(x) for x in rgb))
@koma5
koma5 / publishMongoStats.py
Created January 10, 2017 10:55
publish statistics about a mongodb which is recording every mqtt message in my network
import os, pymongo, mosquitto, json
from pymongo import MongoClient
client = MongoClient('mongo')
records = client.mqttRecord
mqttC = mosquitto.Mosquitto("publishMongoStats-"+str(os.getpid()))
mqttC.connect("mqtt", 1883, 60)