Skip to content

Instantly share code, notes, and snippets.

View LieBtrau's full-sized avatar

Christoph Tack LieBtrau

  • Belgium
View GitHub Profile
@LieBtrau
LieBtrau / songka.py
Last active August 23, 2024 19:41
Songka game Killjoy: finds a sequence of moves so that the player that goes first always wins.
#!/usr/bin/env python3
# Songka game solver
# [Game Rules](https://www.wikihow.com/Play-Congkak)
# [Songka_Plus on Android](https://play.google.com/store/apps/details?id=net.azurewebsites.sungka.twa&hl=en_US)
# This is pretty much a solved game. The player that goes first will always win if he plays optimally.
# There are several sequences to achieve this. The following is one of them:
# Solution found: 41 turns, 93 seeds in the storehouse
# 0 1 4 1 0 4
# 1 1 2 3 2 0
@LieBtrau
LieBtrau / iq-stars.py
Last active August 17, 2024 01:40
Program to find solutions for SmartGames IQ-star puzzle game
#!/usr/bin/env python3
#
# This program is a solver for the [SmartGames IQ-Stars](https://www.smartgames.eu/nl/1-speler-spellen/iq-stars) puzzle game.
# 381 unique solutions can be found. My Thinkpad L580 takes 536s to find them.
import math, sys
from timeit import default_timer as timer
def place_block(block, color, x, y):
# Check if the block can be placed on the board at the given coordinates
@LieBtrau
LieBtrau / firstGradeCalc.py
Last active July 13, 2024 18:24
Create math exercises for 1st to 3rd grade. Addition, subtraction, multiplication and division
#!/usr/bin/env python3
#
# This program prints out three colums of exercises, each time with the result next to it.
# Each column exists of 66 exercises.
#
# 1. Run the program
# 2. Print out the created text file to a DINA4-paper
# 3. Fold back the results of the first column
# 4. Fill in the results for the first column.
# 5. Unfold and check the results
@LieBtrau
LieBtrau / functions.sh
Last active July 12, 2024 16:09
Log user out of Ubuntu session when the sesion duration has been exceeded or total logon time for today has been exceeded.
#!/bin/bash
function current_session_time() {
# Get the duration of the current logon session in seconds
username="$1"
info=$(last -Fn1 $username)
# Get the current time and the session time in seconds
current_time=$(date +%s)
session_time=$(date -d "$(echo $info | awk '{print $5, $6, $7, $8}')" +%s)
@LieBtrau
LieBtrau / battery_level.sh
Last active July 7, 2024 13:09
Log out users when laptop battery level gets too low
#!/bin/bash
# Cronjobs for each user can be edited with "crontab -e"
battery_level=$(cat /sys/class/power_supply/BAT0/capacity)
battery_level_threshold=35
if (( $battery_level > $battery_level_threshold )); then
echo $(date -u) ": Battery level ok:" $battery_level"%"
exit 0
@LieBtrau
LieBtrau / ble-scan.md
Last active October 13, 2021 05:33
Bluetooth Low Energy - Investigating unknown device

Get the ID of your local device

$ hcitool dev
Devices:
hci0	00:1A:7D:DA:71:13

Scan for BLE devices

$ sudo hcitool -i hci0 lescan
LE Scan ...
54:60:09:4A:6D:D9 (unknown)

   ^C

@LieBtrau
LieBtrau / gist:aa1b1065dc0467c604b3601bbea28613
Last active September 7, 2016 18:30
Garmin - OpenStreetMap - Routable

Intro

OpenStreetMap can be used to create free maps for your Garmin. You could download those maps from services like OpenStreetMap.nl. Those maps contain a lot of unnecessary features (houses, woods) that make it hard to follow your route (see the screenshots). So if you want a map that makes it easy for you to keep on track, follow this guide.

Guide

Step 1. Download the map-data

You could use XAPI Query Builder to draw a bounding box and download your maps, but that frequently fails because servers are overloaded. It's better to download a recent map from Geofabrik.