Skip to content

Instantly share code, notes, and snippets.

@brantsch
brantsch / i3lock-wrapper.sh
Created October 4, 2015 08:16
Wrap i3lock to randomly select an image from a folder and automatically scale it to fit your monitor resolution.
#!/bin/bash
random_wallpaper="$(find $1 -maxdepth 1 -name *.png | shuf | head -1)"
actual_size="$(identify -format %wx%h $random_wallpaper)"
target_size=$(xrandr | head -n 1 | awk -e '{OFS=""; gsub("[ ,]+","",$10); print $8,"x",$10;}')
if [[ "$actual_size" != "$target_size" ]]; then
convert "$random_wallpaper" -background black -gravity center -scale $target_size -extent $target_size png:- | i3lock -i /proc/self/fd/0
else
i3lock -t -i "$random_wallpaper"
fi
@brantsch
brantsch / sudoku.pl
Created July 25, 2014 07:47
Sudoku solver in Prolog
:- use_module(library(clpfd)).
/*
Show a sublist of <Pos> in <Sublist>.
<Offset> Offset into <Pos>
<Step> Step size used in iterating through <Pos>
<Length> Length of the sublist.
*/
getSublist(_,_,_,0,[]). % base case
@brantsch
brantsch / battery_widget.lua
Created October 24, 2013 14:40
My battery widget for AwesomeWM on my Laptop. If you want this to work on your machine, you might need to make substantial changes. This widget targets Awesome 3.4.
-- Create a battery widget
mybatterywidget = widget({type="textbox"})
-- do not forget to add the widget to your panel ;-)
-- display the current charge (in %) and the charging/discharging rate (in W)
-- for the battery identified by <adapter>
function show_battery(adapter)
local fcur = io.open("/sys/class/power_supply/"..adapter.."/charge_now")
local fcap = io.open("/sys/class/power_supply/"..adapter.."/charge_full")