Skip to content

Instantly share code, notes, and snippets.

View pstaender's full-sized avatar
👾
extra terrestrial

Philipp Staender pstaender

👾
extra terrestrial
  • Cologne, Germany
View GitHub Profile
@pstaender
pstaender / rename_invoice_pdfs.ruby
Last active June 23, 2024 08:48
Rename your shitty named invoice pdfs to `YYYY-MM-DD_name-of-the-biller_invoice-number.pdf` (the code below outputs the name in german, remove `Please answer in german.` if you want english output)
# usage: bundle exec ruby rename_invoice_pdfs.rb folder/*.pdf
require "openai"
require "json"
require "fileutils"
require "shellwords"
dry_run = false
client = OpenAI::Client.new(
@pstaender
pstaender / simple_json_anonymizer.mjs
Created February 10, 2023 15:02
Usage: node simple_json_anonymizer.mjs data.json > anonymized.json
import { faker } from '@faker-js/faker/locale/de';
import {readFile} from 'node:fs/promises';
// https://fakerjs.dev/api/
let fields = [
[
/email/i, faker.internet.email,
],
[
/nachname/i, faker.name.lastName,
@pstaender
pstaender / using_php_built-in-server_with_silverstripe.md
Last active September 20, 2022 07:15
Using the PHP built-in-server with SilverStripe v4+

Using the PHP built-in-server with SilverStripe v4+

In your SilverStripe project (the original module can be found here):

  $ composer require pstaender/silverstripe-serve

Just start now the server with:

@pstaender
pstaender / update_hetzner_home_dns.rb
Created February 20, 2022 14:40
Updates your domain via hetzner dns api; like dyndns but without any limitations
require 'json'
require 'httparty'
class HetznerDNS
include HTTParty
base_uri 'https://dns.hetzner.com'
def initialize
@options = {
headers: {
require 'digest'
require 'json'
require 'shellwords'
def command?(name)
`which #{name}`
$?.success?
end
unless command?('sips')
# alias cd to modern cd with auto ls
alias ls='exa -l --git --header'
function cd_and_ls {
cd $1 && ls
}
alias cd=cd_and_ls
@pstaender
pstaender / highlight_text_in_vanilla_js.js
Created April 14, 2021 17:38
Finds all (case-insensitive) text occurrences. Beware: replaces html, so event listener will get lost
window.highlightText = (element, highlightText, styleOrClass = 'highlight') => {
let elements = [];
let html = element.innerHTML;
let newHTML = [];
let style = '';
let klass = '';
if (styleOrClass.includes(':')) {
style = styleOrClass;
} else {
klass = styleOrClass;
@pstaender
pstaender / 1_install_caddy.sh
Last active December 4, 2019 21:26
Install Caddy v1.x on Debian
#!/bin/bash
sudo apt-get install -y git libcap2-bin
echo 'install go lang'
wget -q https://storage.googleapis.com/golang/getgo/installer_linux
chmod +x installer_linux
./installer_linux
source ~/.bash_profile
@pstaender
pstaender / caddy.service
Created September 2, 2019 05:50
/etc/systemd/system/caddy.service
[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
[Service]
Restart=on-abnormal
; User and group the process will run as.
@pstaender
pstaender / lambda_function.js
Created August 30, 2019 14:26
Sentry error handling in aws lambda (nodejs)
const path = require("path");
const Raven = require("raven");
const lambdaHandler = async event => {
throw new Error("test");
return {
statusCode: 200,
body: JSON.stringify({ message: "ok" })
};
};