Skip to content

Instantly share code, notes, and snippets.

View adlerweb's full-sized avatar

Florian Knodt adlerweb

View GitHub Profile
@adlerweb
adlerweb / energy.py
Created May 27, 2021 18:19
Fetch predicted renewable energy generation for Germany and find time of day where appliances would theoretically run with lowest environmental impact
import datetime
import urllib.request
import json
weeknr = datetime.date.today().strftime("%V")
year = datetime.date.today().strftime("%Y")
url = "https://energy-charts.info/charts/power/data/de/week_"+year+"_"+weeknr+".json"
data = urllib.request.urlopen(url).read()
data = json.loads(data)
@adlerweb
adlerweb / kernelcheck.py
Created January 21, 2022 13:10
Gentoo: Check if currently active kernel matches latest installed version of gentoo-sources (x86_64)
#!/usr/bin/python3
import os
tmp = os.popen('uname -r')
kernelO = tmp.read()
kernelO = kernelO.replace('-x86_64', '').strip()
tmp = os.popen('eselect kernel list | grep [1] | cut -d " " -f 6')
kernelN = tmp.read()
kernelN = kernelN.replace('linux-', '').strip()
@adlerweb
adlerweb / kernelclean.py
Created January 21, 2022 13:13
Gentoo: Clean old kernel files located in /boot (genkernel) - Use at your own risk
#!/usr/bin/python3
import os
import re
os.chdir('/boot')
files=(os.listdir('/boot'))
keep = [
@adlerweb
adlerweb / kernelcheck.sh
Created January 21, 2022 13:23
Archlinux: Check if running kernel matches installed kernel (aka: do I need to reboot). Might work for other distros too.
if [ $(file /boot/vmlinuz* | cut -d ' ' -f 9) != $(uname -r) ] ; then echo 'reboot'; else echo 'ok'; fi
@adlerweb
adlerweb / deploy_yay.sh
Last active June 25, 2022 11:18
Unattended deployment of yay on a system. Useful when generating VMs on the fly.
#!/bin/bash
version=$(git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags https://github.com/Jguer/yay.git '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3 | tr -d 'v')
url="https://github.com/Jguer/yay/releases/download/v${version}/yay_${version}_x86_64.tar.gz"
tmp=$(mktemp -d)
if [ -d "$tmp" ]
then
if [ "$(ls -A $tmp)" ]; then
echo "Oops. Temporary directory $tmp is not empty"
@adlerweb
adlerweb / composersetup.sh
Created June 10, 2017 11:05
Composer Install Script
#!/bin/sh
#Taken from https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md, here to allow for simple installation
#Use at your own risk.
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
@adlerweb
adlerweb / ha.php
Created October 1, 2022 17:45
Homeassistant/PHP: Read sensor via REST API
<?PHP
function getHA($id) { //ID to read - for example sensor.foo
$key = ''; //Long-lived access token, can be obtained in HomeAssistant UI→Profile
$url = 'http://127.0.0.1:8123/'; //URL to your HA including trailing /
$opts = [
"http" => [
"method" => "GET",
"header" =>
"Content-Type: application/json\r\n" .
/***************************************************************************
IR Ferraris Reader
2019 Adlerweb//Bitbastelei
Florian Knodt - www.adlerweb.info
Note: Just a few minutes of coding, not heavily tested, etc
***************************************************************************/
#include <Arduino.h>
unsigned long last1 = 0;
unsigned long last2 = 0;
unsigned long lasts = 0;
unsigned int dur1 = 0;
unsigned int dur2 = 0;
byte tgt1 = 128;
byte tgt2 = 128;
void setup() {
Serial.begin(115200);
#include <LEDMatrixDriver.hpp>
extern "C" {
#include "user_interface.h"
}
// This sketch draw marquee text on your LED matrix using the hardware SPI driver Library by Bartosz Bielawski.
// https://github.com/bartoszbielawski/LEDMatrixDriver
// Example written 16.06.2017 by Marko Oette, www.oette.info