Skip to content

Instantly share code, notes, and snippets.

@markizano
markizano / battery-status.py
Last active July 6, 2017 18:20
System Tray Icon Widget.
#!/usr/bin/env python2.7
# Depends on oxygen-icon-theme. Change /usr/share/icons/oxygen to your desired theme.
import code
import gtk
import gobject
import threading
import time
import os, sys
import signal
@markizano
markizano / ifjson.c
Last active March 2, 2020 20:40
ifjson - ifconfig in JSON format.
/**
* ifconjig - readOnly ifconfig for JSON output.
*/
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/if_arp.h>
@markizano
markizano / carbon-relay.openrc
Last active August 11, 2020 00:42
Graphite's Carbon Relay init script written for OpenRC
#!/sbin/openrc-run
# 2020-08-10: @markizano
# Written by inference from https://wiki.gentoo.org/wiki/Handbook:X86/Working/Initscripts
# and https://gist.github.com/robinwl/5ec20144364557b83d90
user=${CARBON_USER:-graphite}
group=${CARBON_GROUP:-apps}
description="An init script for Graphite's carbon-cache daemon."
@markizano
markizano / carbon-cache.openrc
Created August 11, 2020 00:43
Graphite's Carbon Cache init script written for OpenRC
#!/sbin/openrc-run
# 2020-08-10: @markizano
# Written by inference from https://wiki.gentoo.org/wiki/Handbook:X86/Working/Initscripts
# and https://gist.github.com/chalmerj/1492384
user=${CARBON_USER:-graphite}
group=${CARBON_GROUP:-apps}
description="An init script for Graphite's carbon-cache daemon."
@markizano
markizano / gpus.js
Created July 12, 2021 00:30
Calculate dollar/hash and hash/watt of various GPU from MongoDB.
function aggregateGpus(gpu) {
var result = '%name:\n'.replace('%name', gpu.name);
result += ' Price (USD): %price\n'.replace('%price', gpu.price);
result += ' HashRate (MH/s): %hr\n'.replace('%hr', gpu.hashrate);
result += ' Power (W): %power\n'.replace('%power', gpu.power);
result += ' $/MH: %dph\n'.replace('%dph', gpu.pricePerHash);
result += ' MH/W: %hpw\n\n'.replace('%hpw', gpu.hashPerWatt);
print(result);
}
@markizano
markizano / xwait.py
Created November 2, 2021 17:32
xwait.py: Wait X number of seconds before returning control of the command after a period of inactivity via the mouse and keyboard.
#!/usr/bin/env python3
import os, sys
import time
import json
import threading
from libinput import LibInput, constant
from glob import glob
@markizano
markizano / zilwatch.sh
Created January 13, 2022 22:36
Watch my miner - stop it when the window opens and resume it when the window closes. I use with `/usr/bin/screen -L`
#!/bin/bash
export startlog='ZIL PoW Window Start' \
endlog='ZIL PoW Window End' \
minerproc='/usr/local/share/gminer-2.54/miner' \
screenlog=~/screenlog.0
tail -n0 -F "$screenlog" | \
while read logline; do
echo "$logline" | grep -qF "$startlog" && {
@markizano
markizano / dictmerge.py
Created April 27, 2022 16:17
Enables one to merge dictionaries in Python whilst preserving previous keys.
def dictmerge(target, *args):
'''
Merge multiple dictionaries.
Usage:
one = {'one': 1}
two = {'two': 2}
three = {'three': 3}
sum = dictmerge(one, two, three)
@markizano
markizano / .bashrc
Created July 20, 2022 17:07
bashrc snippet to preserve history across sessions since `HISTFILESIZE=-1` is unreliable.
export DATEFORMAT='%F/%R:%S';
export HISTCONTROL=ignoreboth
export HISTFILE=$HOME/.bash_history
export HISTFILESIZE=-1
export HISTSIZE=81920
export HISTTIMEFORMAT="$DATEFORMAT "
export HISTLOG=~/.bash_history.d
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:.:~/bin
export PROMPT_COMMAND='echo -en "\n\e[36m$?\e[0m; "; history -a; histlog "$(history 1)"'
@markizano
markizano / yamllint.py
Created October 5, 2022 11:33
Walk a directory for files and do a lint check on loading up YAML configuration files.
#!/usr/bin/env python3
import os
import sys
import yaml
def main(target):
if not os.path.isdir( target ):
print('Could not walk %s. Target is not a directory or doesnt exist.' % target)
return 1