Skip to content

Instantly share code, notes, and snippets.

@lillesvin
lillesvin / izbot2-lb.rb
Created June 16, 2022 22:03
iZBOT 2 Leaderboard Viewer
=begin
Leaderboard scraper for iZBOT 2 (but can probably be adapted
for other games using Steam leaderboards.
WARNING: USE AT YOUR OWN RISK! THIS SCRAPES STEAM FOR THE
LEADERBOARD DATA, WHICH IS PROBABLY AGAINST THE STEAM TOS.
SETUP: First of all, you'll need Ruby (probably version 2.7
or above), and then you'll need 'oga' (`gem install oga`).
@lillesvin
lillesvin / swebrick.rb
Created September 16, 2020 13:20
Simple Ruby/WEBrick wrapper to serve stuff over HTTPS/TLS/SSL
#!/usr/bin/ruby
require 'webrick/https'
require 'openssl'
require 'optparse'
# Defaults
cfg = {
port: 8443,
root: "."
@lillesvin
lillesvin / monitor.sh
Last active December 11, 2019 11:40
Monitor a file looking for a string. If the moving average of the interval is lower than THRESHOLD, do something!
#!/bin/bash
# This is executed whenever conditions are met
# Change this to whatever you would like to have happen
alert() {
echo 'ALERT, ALERT!!!'
printf "Average hit interval: %.2f sec.\n" "$AVG"
printf "Threshold: %d sec.\n" "$THRESHOLD"
printf "Window length: %d\n" "$WINDOW_LENGTH"
printf "Last window: %s\n" "${INTERVALS[*]}"
@lillesvin
lillesvin / csvize-server-status.rb
Last active March 15, 2019 11:08
Parses Apache Extended Server Status pages and converts them to CSV. Great in combination with https://github.com/BurntSushi/xsv
#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'csv'
if ARGV.length < 1
puts "Error: Please supply a URL pointing to an Apache Extended Server Status page"
exit
@lillesvin
lillesvin / shplit.sh
Created August 3, 2016 07:22
Command line split timer that optionally uses a file as a pipe. You can have OBS read the contents of that file to display your timer in a video/stream if you don't want to just capture part of the terminal window. You can "split" by hitting Return/Enter (in the terminal) while the timer is running, and stop the timer with Ctrl-C (in the termina…
#!/bin/bash
if [[ "${1}x" == "x" ]]; then
USE_PIPE=false
else
USE_PIPE=true
PIPE=${1}
fi
FORMAT="%s.%2N"
@lillesvin
lillesvin / cron-hack
Last active March 2, 2016 12:30
Hack to run bi-weekly jobs via Cron
# Hack to run every 2nd Tuesday:
# - Cron notation to run every Tuesday
# - PHP exits with (effectively): date("W") % 2
# - Hacked to remove all '%' because cron can't handle them
# - Use shell chaining (&& and ||) to determine even/odd weeks
# - && for even week numbers, || for odd
# So to run `echo "Still here ..."` every other Tuesday at 10:30 AM:
30 10 * * 2 php -r 'exit((int)fmod(date("W"),2));' && echo "Still here ..."
# Note: PHP can obviously be replaced with anything that
@lillesvin
lillesvin / bytescramble.rb
Last active September 20, 2015 07:27
Data bending is fun!
#!/usr/bin/env ruby
##
# ByteScramble
#
# Copyright 2015 Anders K. Madsen <lillesvin@gmail.com>
# Licence: MIT <https://opensource.org/licenses/MIT>
#
# Description:
# ------------
@lillesvin
lillesvin / git-lint-php
Created August 28, 2015 08:45
Creates a git command 'lint-php' (if this script exists in your PATH and is executable) that syntax checks all modified/added files that end in ".php".
#!/bin/bash
files=$(git status --porcelain | sed -e 's/^.* //' | grep -P '\.php$')
for f in $files; do
php -l $f
done
@lillesvin
lillesvin / get_git_branch.sh
Last active August 29, 2015 14:22
Show active git branch in Bash prompt
#!/bin/bash
# Put this in $HOME/bin/get_git_branch.sh
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then
if [[ "$branch" == "HEAD" ]]; then
branch='detached*'
fi
fi
@lillesvin
lillesvin / shutdown_handler.php
Created May 26, 2015 07:35
Handler for logging last error even when fatal
class ShutdownHandler
{
private $catch;
private $error;
public function __construct($catch = null)
{
$this->catch = $catch ?: E_ERROR | E_PARSE;
}