Skip to content

Instantly share code, notes, and snippets.

@Gronis
Gronis / README.md
Last active October 16, 2021 21:13
Use Swedish zipcodes to get access to municipality, county, city and gps-coordinates.

Download from geonames (updated regularly)

curl https://download.geonames.org/export/zip/SE.zip > SE.zip
unzip SE.zip
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Gronis
Gronis / grouped_light.py
Created January 31, 2018 17:33 — forked from jjensn/grouped_light.py
Grouped light platform for Home Assistant
import asyncio
import logging
# Import the device class from the component that you want to support
from homeassistant.core import callback
from homeassistant.components import light
from homeassistant.const import (STATE_OFF, STATE_ON, SERVICE_TURN_ON,
SERVICE_TURN_OFF, ATTR_ENTITY_ID)
from homeassistant.components.light import (SUPPORT_BRIGHTNESS,
SUPPORT_RGB_COLOR,
@Gronis
Gronis / get_mac_address
Last active June 20, 2020 18:30
Get the mac address for a certain host.
#!/bin/bash
#
# Get the mac address for a certain host.
#
# Requires ping and arp tool.
#
# Usage:
# get_mac_address HOSTNAME
#
@Gronis
Gronis / Dockerfile
Last active September 1, 2021 11:50
Kryptokrona node on docker
FROM ubuntu as builder
ENV CC=gcc-8
ENV CXX=g++-8
RUN apt-get update && apt-get install -y \
software-properties-common &&\
add-apt-repository -y \
ppa:ubuntu-toolchain-r/test &&\
@Gronis
Gronis / README.md
Last active October 5, 2021 23:15
Home assistant xmrig config

Control the number of mining cores on xmrig from home assistant. The script calls the http interface on xmrig and sets the number of cores used for mining with cn-pico algorithm. Feel free to edit to your usecase.

Put __init__.py file in <homeassistant_root>/custom_components/xmrig/__init__.py

Then add the following to your configuration.yaml

xmrig:
  host: <host>
 port: 
@Gronis
Gronis / node_datachannel_wrtc.js
Created August 17, 2021 16:54
A (partially) wrtc compatible wrapper layer around node-datachannel so that node-datachannel can be used as wrtc backend for various webrtc libraries when running inside a nodejs environment.
import libdatachannel from 'node-datachannel';
const do_nothing = (..._) => { };
const decorate_channel = channel => {
Object.defineProperty(channel, "readyState", {
get: function () {
return channel.isOpen() ? 'open' : 'closed'
}
});
Object.defineProperty(channel, "label", {
@Gronis
Gronis / cleardockerlogs.sh
Created October 5, 2021 20:42
Docker shell scripts
#!/bin/bash
date "+%Y-%m-%d %H:%M:%S"
sudo sh -c 'truncate -s 0 $(docker system info 2> /dev/null | grep "Docker Root Dir" | cut -d ":" -f2 | cut -d " " -f2-)/containers/*/*-json.log';
@Gronis
Gronis / hdr10conversion.js
Last active January 29, 2024 17:10
This script takes a hdr10 video and returns a string for x265 encoder with the correct light levels.
#! /usr/bin/env node
// For info about hdr transcoding, go here:
// https://codecalamity.com/encoding-uhd-4k-hdr10-videos-with-ffmpeg/
//
// This script takes a hdr video and returns a string for x265 encoder with the correct light levels like this:
// "hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display=G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(11000000,0):max-cll=0,0"
//
const proc = require('child_process');
@Gronis
Gronis / reboot-on-low-mem.sh
Created November 1, 2022 23:13
Reboot if system has less than 64MB of system memory left. Useful when running RAM filesystem and reboots can be used for cleanup. Put in cron
#!/usr/bin/env bash
bash -c "[ $(cat /proc/meminfo | grep MemAvailable | awk '{ printf("%d", $2 < 65536) }') == '1' ] && reboot"