Skip to content

Instantly share code, notes, and snippets.

Avatar

glaszig

  • available for hire. contact me.
  • remote
View GitHub Profile
@glaszig
glaszig / fswatch-scp.sh
Last active Nov 10, 2020
use fswatch to scp changed files to remote host
View fswatch-scp.sh
#!/usr/bin/env sh
# Copyright 2020 glaszig
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@glaszig
glaszig / curl_action_mailbox.md
Last active Apr 1, 2021
rails' action mailbox without installing rails on your mail server
View curl_action_mailbox.md

forward email to action mailbox without installing rails

rails provides [rake tasks][rake] to forward mails to [action mailbox][actionmailbox]'s [relay ingress][postfix]. that's fine unless you have your mail server(s) on another system and don't want to install rails (and all dependencies, i.e. the ruby runtime).
since the rake tasks basically just [upload stdin to your rails app via http][relayer] you can do everything with curl.

action-mailbox-relayer.sh

#!/usr/bin/env sh
curl -sS -u "actionmailbox:$INGRESS_PASSWORD" \
@glaszig
glaszig / gitea-backup-s3.sh
Last active Jan 24, 2020
FreeBSD Gitea backup to AWS S3
View gitea-backup-s3.sh
#!/usr/bin/env sh
#
# requires openssl >= 1.1.1 due to usage of -pbkdf2 option
#
# to decrypt the encrypted backup:
# openssl aes-256-cbc -d -a -salt -pbkdf2 -in gitea-dump.zip.enc -out gitea-dump.zip -pass pass:your-password
#
# conifgure with a dotfile `.backuprc` in your $HOME:
# BUCKET="foobar"
# GITEA_CUSTOM=/usr/local/etc/gitea
@glaszig
glaszig / setup.rb
Created Oct 31, 2018
quick and dirty dev setup for macos
View setup.rb
#!/usr/bin/env ruby
require 'open3'
ENV["HOMEBREW_NO_AUTO_UPDATE"] = "1"
ENV["HOMEBREW_INSTALL_URL"] ||= "https://raw.githubusercontent.com/Homebrew/install/master/install"
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
@glaszig
glaszig / regexp_escape.py
Created Oct 21, 2018
Jinja plugin (for use with Ansible) to run re.escape against input
View regexp_escape.py
# (c) 2018, glaszig@gmail.com
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the MIT license.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# MIT License for more details.
#
@glaszig
glaszig / test_helper.rb
Created Oct 15, 2018
Method to set value of range input field with Capybara
View test_helper.rb
class ActionDispatch::IntegrationTest
# usage: set_range "My Range Field", to: 42
# this also triggers the input's change and/or input events
# as opposed to find_field("My Range Field").set 42
def set_range(locator = nil, to:, **find_options)
find_field(locator, find_options).execute_script %Q(this.value = "#{to}")
end
end
View git-jail-bootstrap.sh
#!/usr/bin/env sh
set -e
HOME_DIR="/home/git"
WWW_DIR="/usr/local/www/gitweb"
REPOS_PATH="$HOME_DIR/repositories"
GITWEB_CONF="/etc/gitweb.conf"
GITWEB_PATH="/usr/local/share/examples/git/gitweb"
BANNER="# created by bootstrap script. manual changes might get lost."
@glaszig
glaszig / mkp2pblocklist
Last active Apr 5, 2020
creates a blocklist for your p2p endeavors
View mkp2pblocklist
#!/usr/bin/env sh
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2020 glaszig <glaszig@gmail.com>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
@glaszig
glaszig / if_.patch
Created Aug 2, 2016
munin 2.0.19 if plugin patch
View if_.patch
--- if_.orig 2016-08-02 23:52:05.691224811 +0200
+++ if_ 2016-08-02 23:52:49.563223127 +0200
@@ -91,7 +91,7 @@
# iwlist first)
if [[ -r /sys/class/net/$INTERFACE/speed ]]; then
SPEED=$(cat /sys/class/net/$INTERFACE/speed 2>/dev/null)
- if [[ -n "$SPEED" ]]; then
+ if [ -n "$SPEED" -a "$SPEED" -gt "0" ]; then
echo $SPEED
return
@glaszig
glaszig / hex_benchmark.rb
Last active Jun 20, 2016
ruby hex encode algorithm performance comparison
View hex_benchmark.rb
require 'benchmark'
ITERATIONS=100_000
INPUT='https://www.example.com/path/to/image.png'.freeze
def interpolate
INPUT.to_enum(:each_byte).map{ |byte| "%02x" % byte }.join
end
def unpack