Skip to content

Instantly share code, notes, and snippets.

View simonhaenisch's full-sized avatar
💪
Staying fefeka.

Simon Hänisch simonhaenisch

💪
Staying fefeka.
View GitHub Profile
@simonhaenisch
simonhaenisch / rpi-arch-linux-shairport-sync.sh
Last active February 16, 2021 13:35
Arch Linux with Shairport-Sync (Edimax Wifi, USB audio card) #raspberrypi
# boot arch linux (e. g. from usb drive)
# have a wired internet connection before boot or use wifi-menu to connect to your wifi
# https://wiki.archlinux.org/index.php/USB_flash_installation_media#In_macOS
# change keyboard layout
loadkeys de-latin1
# install arch linux ARM for RPi 1/2/3 (download to SD card, if USB stick is too small)
# https://archlinuxarm.org/platforms/armv6/raspberry-pi
# https://archlinuxarm.org/platforms/armv7/broadcom/raspberry-pi-2
@simonhaenisch
simonhaenisch / nginx-config.md
Last active February 8, 2023 01:20
Nginx configuration boilerplate with SSL

Nginx Configuration Boilerplate

This is my boilerplate for a Nginx config with SSL. I like the idea of modular includes, so I created a /etc/nginx/includes directory for files that get included into the main config file /etc/nginx/nginx.conf. I moved mime.types and fastcgi.conf to that includes folder. I use a common-location-rules.conf file for location rules that are shared between all sites hosted on the server. Relative paths in include directives are relative to the config prefix path (path to the nginx.conf file, by default /etc/nginx/).

The following files are from h5bp/server-configs-nginx:

  • includes/mime.types: here the correct MIME type for javascript (application/javascript instead of text/javascript) is set among others. Using this file is important because the gzip_types rule is set accordingly in gzip.conf.
  • **[includes/expires.conf](htt
@simonhaenisch
simonhaenisch / rpi-cloud-slideshows.md
Last active February 15, 2018 00:51
RPi: owncloud-synced slideshows with frame buffer #raspberrypi

Raspberry Pi: OwnCloud-Synced Slideshows with Frame Buffer

  • Install Arch Linux on the Raspberry Pi as explained in https://gist.github.com/simonhaenisch/d086156a5828c0037acd46b48279388f without alsa and shairport
  • Create an owncloud user rpi and share folders to be synced (without edit permissions)
  • Install owncloud-client: pacman -S owncloud-client
  • Install fonts package: pacman -S ttf-dejavu
  • Install Frame Buffer Image Viewer: pacman -S fbida
  • Install Cron: pacman -S cronie and enable auto-start: systemctl enable cronie
  • Create a folder /var/cloud to be synced to
@simonhaenisch
simonhaenisch / inc-dec.py
Last active March 9, 2018 18:42
Sublime Text 3 plugin for in-/decrementing a multi-selection or creating an ordered (incrementing) list (starting with the value of first selection) #sublimetext
import sublime, sublime_plugin
class IncrementSelectionCommand(sublime_plugin.TextCommand):
# increments each selected number by one
def run(self, edit):
for region in self.view.sel():
value = int(self.view.substr(region))
self.view.replace(edit, region, str(value + 1))
class DecrementSelectionCommand(sublime_plugin.TextCommand):
@simonhaenisch
simonhaenisch / opencv-pixel-index.cpp
Last active February 26, 2021 12:11
Access pixel in an OpenCV Matrix using the data pointer and indexing
// example matrix
Mat img = Mat::zeros(256, 128, CV_32FC3);
// get the pointer (cast to data type of Mat)
float *pImgData = (float *)img.data;
// loop through rows, columns and channels
for (int row = 0; row < img.rows; ++row)
{
for (int column = 0; column < img.cols; ++column)
@simonhaenisch
simonhaenisch / rename-files.py
Last active August 3, 2016 14:07
Rename files (consecutively numbered)
#!/usr/bin/env python
import sys, os
'''
Usage: python rename-files.py [directory] [extension] [new name base]
Example: python rename-files.py . .png frame-
'''
try:
directory = sys.argv[1]
extension = sys.argv[2]
@simonhaenisch
simonhaenisch / mv-from-sub-dirs.sh
Last active August 16, 2016 12:56
Move files with same name from sub-directories
#! /bin/bash
# mv e.g. /dir/00[1|2|3]/file.ext -> /dir/file-[1...3].ext
idx=1 # start index for new file-names (use 0 or zero-based index)
ext=".ext" # file extension (can be a wildcard)
from="/dir/*" # where to look for files
to="." # target of mv command, e.g. "dir/"
for file in $from/*$ext; do
@simonhaenisch
simonhaenisch / ssl-encrypt-decrypt.sh
Last active August 20, 2016 08:51
OpenSSL file en-/decryption
#! /bin/bash
file="path/to/file.txt"
# encrypt
openssl enc -aes-256-cbc -e -in "$file" -out "${file}_encrypted" -pass pass:<password>
# decrypt
openssl enc -aes-256-cbc -d -in "$file" -out "${file}_decrypted" -pass pass:<password>
@simonhaenisch
simonhaenisch / build-scss.js
Created August 20, 2016 10:36
Build SCSS with the `node-sass` npm module
// npm install node-sass
var fs = require('fs'),
sass = require('node-sass');
// specify in-/output files
var inFile = '/path/to/main.scss',
outFile = '/path/to/main.css';
sass.render(
@simonhaenisch
simonhaenisch / selector-based-hotkey.json
Last active February 15, 2018 00:51
Sublime Text hotkey that triggers only when in a certain syntax #sublimetext
[
{
"keys": ["f8"],
"command": "repl_open",
"args": {
"cmd": ["python", "-u", "$file_basename"],
"cwd": "$file_path",
"encoding": "utf8",
"extend_env": {"PYTHONIOENCODING": "utf-8"},
"external_id": "python",