Skip to content

Instantly share code, notes, and snippets.

View hlfbt's full-sized avatar
🤔

Alexander Schulz hlfbt

🤔
View GitHub Profile
@hlfbt
hlfbt / getopts.sh
Created May 3, 2019 13:46
Simple somewhat advanced getopts only dependent on bash and expr
#!/bin/bash
# Simple more advanced arguments parsing than builtin tools like getopts or a simple while/case looping over the arguments
#
# Features include handling of:
# - multiple grouped shorthands (f.i. -abc becoming -a -b -c),
# - equal sign value assignment (f.i. --arg=value becoming --arg value, and also -a=value becoming -a value)
# - dashless value assignment (f.i. arg=value becoming arg value)
#
# The only dependencies are bash (for arrays) and expr (included in coreutils) (for regexp matching and extraction) which are likely available everywhere (even in a busybox or on a mac!)
#
@hlfbt
hlfbt / cache.js
Last active August 29, 2015 14:19
A simple cache for javascript. Useful to have a simple interface to share variables over between pageloads.
function Cache () {
"use strict";
if (this.constructor != Cache) throw new TypeError("Constructor Cache requires 'new'");
/*
A dumb, simple cache, to make access to cross-pageload variables easy and manageable.
All cache times are in milliseconds.
*/
var storage = window['localStorage'];
@hlfbt
hlfbt / select.js
Last active September 7, 2016 12:07
A stupid simple framework just like jquery that mainly grew out of procrastination. I use this wherever the jquery way is much more elegant/easier but there is no jquery available (i.e. in a userscript before the page completely loaded). May be expanded every now and then as I deem fit.
/*/
* This simulates JQuery's constructor functionality as best as easiest possible
* Some minor things that I never really use (like calling select() without arguments,
* or some ambiguous css paths not being interpreted by querySelectorAll correctly)
* might not really work, but I personally don't see much need to make it more complicated
* to work around them currently.
/*/
var select = function (s, c) {
if (!c || c == null)
c = document;
@syl20bnr
syl20bnr / i3_focus_win.py
Last active July 13, 2024 14:29
Python script for i3 which allows to focus the nth window of the current container hierarchy. It requires i3-py: https://github.com/ziberna/i3-py
#!/usr/bin/env python
#
# author: syl20bnr (2013)
# goal: Focus the nth window in the current workspace (limited to 10 firsts)
#
# Example of usage in i3 config:
#
# bindsym $mod+0 exec focus_win.py -n 0
# bindsym $mod+1 exec focus_win.py -n 1
# ... ...