Skip to content

Instantly share code, notes, and snippets.

@fbender
fbender / fbender.zsh-theme
Created March 22, 2024 23:27
Personal ZSH theme based on steeef from official OMZ repository, heavily modified and quite verbose (WIP)
### custom Oh-My-ZSH theme by fbender
#
# verbose theme based on "steeef" from official omz repository
# - vcs_info reduced to show type, name, and branch (if available) of repository only
# - built-in slightly modified "timer" plugin from official omz repository
# - extended Python virtual environment logic, i.a. adding conda support
# - multi-line input (PS2) and debug (PS4) formatting
# - more and different colors, date and time information, running job info, and more
#
# recommended setopts: EXTENDED_HISTORY, RM_STAR_WAIT, CORRECT, CORRECT_ALL
@fbender
fbender / sleep-timer.scpt
Last active March 5, 2024 09:51
AppleScript to put your Mac to sleep after X minutes, fading out the system volume shortly before sleeping. Can be turned into an app via the "Export" feature of the AppleScript Editor.
-- written by Florian Bender, 2015
-- based on work by Michael Wyszomierski <https://wysz.com/wyszdom/2009/06/simple-sleep-timer-with-applescript/>
-- license: Public Domain / CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
tell application "System Events"
set volumeSettings to get volume settings
set volumeValue to (output volume of volumeSettings)
set fadeTime to 10 -- time in seconds for fade change
set fadeChange to (volumeValue div fadeTime)
-- display alert "Volume: " & volumeValue & ", Delta: " & fadeChange
display dialog "Sleep time (min):" default answer "25"
@fbender
fbender / setup-jupyter-py-sci-conda-env.sh
Last active January 16, 2024 16:25
Baseline Scientific Python conda enviroment using VSCode for Jupyter
#!/bin/sh -
#
# Install baseline scientific packages including Jupyter kernel (e.g. into 'base' enviroment):
conda install sympy tabulate seaborn scipy ipykernel
# That's it, you don't need to install all of Jupyter into the enviroment if you "connect" from another
# Jupyter instance, e.g. through VS Code with the Jupyter extension, to this enviroment; the 'ipykernel'
# is sufficient. NumPy, matplotlib, pandas, etc. are part of the dependencies of above packages. Install
# panda's recommended dependencies if numeric operations need a speed up, esp. for large data sets; ref.
# https://pandas.pydata.org/pandas-docs/stable/getting_started/install.html#install-recommended-dependencies
# Use 'pytables' or 'h5py' for very large data sets. For interactive plots, use 'bokeh'. Other interesting
@fbender
fbender / remount-usbdrive.sh
Last active December 19, 2023 17:23
Task source code to remount an ejected external USB drive in Synology DSM (e.g. to enable fully-automated Hyper Backup with auto-eject enabled)
# HOW TO SET UP
# - Go to Task Scheduler and create a new "user-defined script" task for "root" user.
# - Schedule task before e.g. next Hyper Backup run (my sequence is: 00:58 mount task, 01:00
# run drive integrity test, 03:00 run backup, which will eject drive again at the end).
# - Copy this file's content to the "user-defined script" field and save.
# - Make sure execution output logging is configured (e.g. saving to a shared folder).
# - Either run script once and follow next section's info, or run "lsusb" yourself via SSH.
# - Fill in device details in variables below (until "END OF CONFIGURATION").
set -euxo pipefail
lsusb
@fbender
fbender / xml-to-har.py
Last active September 14, 2020 11:19 — forked from craigds/xml-to-har.py
Convert Internet Explorer 'capture network traffic' XML to a HAR file (by @craigds, force-unicode-version).
#!/usr/bin/env python
"""
Converts Internet Explorer 'capture network traffic' XML to a HAR file.
Turns out that XML is just a HAR file anyways, but in XML form. So this
just converts it to JSON, and Bob's your uncle.
Requires Python 2.7+ and LXML.
"""
from __future__ import unicode_literals
@fbender
fbender / base64.m
Last active December 25, 2016 21:20
Base64 for MATLAB
function b64 = base64( str )
%BASE64 Encode string (array of chars) into Base64
% Currently seems to fail for any input > 4 characters. :(
%% Settings
% Valid output codes to choose from.
base64Chars = char([65:90, 97:122, 48:57, 43, 47]); % +/ per RFC 2045 et al.
%base64UrlChars = char([65:90, 97:122, 48:57, 45, 95]); % -_ per RFC 4648 §4
base64PadChar = '=';
@fbender
fbender / vbox-ext-update.sh
Last active December 28, 2015 00:59
Oracle VirtualBox Extension Pack update helper (based on https://forums.virtualbox.org/viewtopic.php?f=7&t=44337#p199593).
#!/bin/bash
# license: MIT
# author: Florian Bender
# original script: Sasquatch (https://forums.virtualbox.org/viewtopic.php?f=7&t=44337#p199593)
# see comment below!
version=$(vboxmanage -v)
echo -n "Installed: $version; "
var1=$(echo $version | cut -d 'r' -f 1)
@fbender
fbender / colorset.sh
Last active December 18, 2015 00:09
Simple helper function for the lazy to colorize terminal scripts. MIT License. Color codes from https://wiki.archlinux.org/index.php/Color_Bash_Prompt#Advanced_prompts
#!/bin/bash
# Copyright (c) 2013 Florian Bender
# License: MIT (see http://opensource.org/licenses/MIT)
function colorset {
style=""
case $1 in
text) style="0;3" ;; ## regular text
HItext) style="0;9" ;; ## high intensity regular text
@fbender
fbender / bootlocal.sh
Last active September 22, 2015 16:59
Since Docker Machine (ex boot2docker) does (mostly) not persist changes in the VM file system, a Discourse installation is easily broken when the VM is restarted. This script prepares the boot2docker VM on each boot so handling Discourse in Docker Machine is easer.
#!/bin/sh
# mounts a folder to /var/discourse and installs bash (required by
# Discourse launcher script)
#
# HOWTO:
#
# 1. `docker machine ssh default` into the VM
# 2. `mkdir /mnt/sda1/var/discourse`
# 3. put this script at /var/lib/boot2docker/bootlocal.sh (this file
# will be persisted through reboots)
@fbender
fbender / mirror.sh
Last active September 1, 2015 16:43
`wget` script to mirror / backup a site and its subressources even if they span across different domains
#!/bin/bash
# `wget` script to mirror / backup a site and its subressources even if they span across different domains
#
# Author: Florian Bender
# Updated: 2015-08-31
# License: MIT
#
# Copyright (c) 2015 Florian Bender <fb+git@quantumedia.de>
#