Skip to content

Instantly share code, notes, and snippets.

View tvwerkhoven's full-sized avatar

Tim van Werkhoven tvwerkhoven

  • ASML
  • Netherlands
View GitHub Profile
@tvwerkhoven
tvwerkhoven / dedupe.sh
Last active March 14, 2024 17:38
De-duplicate using APFS clonefile(2) and jdupes in zsh
#!/usr/bin/env zsh
#
# # About
#
# Since APFS supports de-duplication on block-level, it can be useful to
# manually de-duplicate your files if you've migrated/upgrade to APFS not
# using a fresh install.
#
# I've written this simple script with the aim to:
# - Be simple, easy to read and understand (for users to check)
@tvwerkhoven
tvwerkhoven / routeros-config.rsc
Created February 7, 2023 19:06
Mikrotik RouterOS RB2011/RB3011 home configuration with VLAN/QoS/Firewall
###############################################################################
# Topic: Using RouterOS to VLAN your network
# Example: Router-Switch-AP all in one device
# Web: https://forum.mikrotik.com/viewtopic.php?t=143620
# RouterOS: 6.43.12
# Date: Mar 28, 2019
# Notes: Start with a reset (/system reset-configuration)
# Thanks: mkx, sindy
###############################################################################
@tvwerkhoven
tvwerkhoven / rsync_backup.sh
Last active July 5, 2023 05:30 — forked from necolas/rsync_backup
Improved script: - Check if run as root - Clarify rsync(1) flags - Add --inplace for performance, extra preservation flags - Check bless(8) target before setting Improved exclusion file: - Included files listed by Carbon Copy Cloner
#!/bin/bash
#
# This script backups an OS X system to an external volume, effectively
# cloning it. It is based on [0], [1] and [2] for OS X and [3] and [4] for
# Linux. One could also use commercial tools like SuperDuper! or Carbon Copy
# Cloner. The latter website has an interesting list[5] on what files to
# exclude when cloning.
#
# Exclusions (from CCC[5]), see rsync_excludes_osx.txt
#
@tvwerkhoven
tvwerkhoven / .gitignore
Created August 2, 2011 08:59
XeTeX cheatsheet
*.aux
*.log
*.out
*.pdf
*.synctex.gz*
@tvwerkhoven
tvwerkhoven / battery_logger.sh
Last active April 6, 2022 02:56
Log Macbook battery status with system_profiler(8) and ioreg(8), see http://home.strw.leidenuniv.nl/~werkhoven/etc/battlog.html
#!/bin/bash
#
# About
# =====
#
# Log battery info from command-line with SYSTEM_PROFILER(8) and IOREG(8) to a
# user-configurable directory.
#
# Run with -h to see usage options.
#
@tvwerkhoven
tvwerkhoven / notify-high-sensor-value.yaml
Last active December 7, 2021 21:38
Home Assistant automation to notify at high sensor values
blueprint:
name: High sensor value notification
description: Notify users of high sensor values (e.g. CO2, temp, PM2.5), and again when value drops below acceptable level
domain: automation
input:
trigger_sensor:
name: Trigger sensor
description: E.g. CO2, PM2.5, temperature
selector:
entity:
@tvwerkhoven
tvwerkhoven / notify-or-do-something-when-an-appliance-like-a-dishwasher-or-washing-machine-finishes.yaml Home Assistant Blueprint: Notify or do something when an appliance like a dishwasher or washing machine finishes
blueprint:
name: Appliance has finished+
description: Do something when an appliance (like a washing machine or dishwasher)
has finished as detected by a power sensor, and show power consumption.
domain: automation
input:
power_sensor:
name: Power Sensor
description: 'Power sensor entity (e.g. from a smart plug device).'
selector:
@tvwerkhoven
tvwerkhoven / MultiMarkdown_guide.md
Last active December 7, 2020 23:21
Brief introduction to MultiMarkdown highlighting features that were hard to find.
@tvwerkhoven
tvwerkhoven / renamemp3.sh
Created April 5, 2010 20:02
Recursively rename all files in a directory
#!/bin/bash
#
# Recursively rename all files in a directory with the following rules:
# - Convert letters to lower case
# - Convert whitespace to underscore
# - Remove 'track' in the name
#
# Used to clean up filenaming of mp3s
#
# Tim van Werkoven, 20100405 <t.i.m.vanwerkhoven@xs4all.nl>
@tvwerkhoven
tvwerkhoven / kMeans.py
Created June 2, 2018 13:31 — forked from bistaumanga/kMeans.py
KMeans Clustering Implemented in python with numpy
'''Implementation and of K Means Clustering
Requires : python 2.7.x, Numpy 1.7.1+'''
import numpy as np
def kMeans(X, K, maxIters = 10, plot_progress = None):
centroids = X[np.random.choice(np.arange(len(X)), K)]
for i in range(maxIters):
# Cluster Assignment step
C = np.array([np.argmin([np.dot(x_i-y_k, x_i-y_k) for y_k in centroids]) for x_i in X])