Skip to content

Instantly share code, notes, and snippets.

@peterhel
peterhel / cargo-lambda-build.Dockerfile
Created December 12, 2024 16:41
After days of fighting with mingw and mac osx and an old linux laptop... this it what I finally settled with to get my rust lambda compiled.
# 1. This tells docker to use the Rust official image
FROM debian
SHELL ["/bin/bash", "-c"]
RUN apt update && apt install python3-pip python3-venv pkg-config libssl-dev curl -y
RUN python3 -m venv /venv
ENV PATH="/venv/bin:/root/.cargo/bin/:$PATH"
ENV RUST_BACKTRACE=1
RUN python3 -m pip install ziglang
docker run \
-it \
--rm \
--entrypoint bash \
-v ${PWD}:/host \
-e ODBCINI=/opt/odbc.ini \
-e ODBCSYSINI=/opt/ \
public.ecr.aws/lambda/python:3.13
dnf update -y
@peterhel
peterhel / move-recursive-with-find.sh
Created September 20, 2024 07:27
Move all files from one folder into another with folder structure intact using `find`
find from-dir/ -name '*.txt' -exec bash -c 'export A="$(dirname {})"; mkdir -p to-dir/$A && mv {} to-dir/{}' \
@peterhel
peterhel / justlikethis.py
Created October 21, 2023 18:26
json.dumps(decimals)
import json
import decimal
class ComplexEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, decimal.Decimal):
return int(obj) if obj % 1 == 0 else float(obj)
return json.JSONEncoder.default(self, obj)
@peterhel
peterhel / sort-json.sh
Last active July 10, 2023 12:48
sort-json
DSTPATH="path/to/file.json" CONTENT="$(cat ${DSTPATH})"; echo "$CONTENT" | jq --sort-keys > $DSTPATH
@peterhel
peterhel / service_broker.sql
Created March 13, 2023 13:33
List service queues, services, message types and contracts
select sc.name as service_contract_name, smt.name as service_message_type_name, s.name as service_name, sq.name
from sys.service_contracts sc
join sys.service_contract_message_usages scmu on sc.service_contract_id = scmu.service_contract_id
join sys.service_message_types smt on scmu.message_type_id = smt.message_type_id
join sys.service_contract_usages scu on sc.service_contract_id = scu.service_contract_id
join sys.services s on scu.service_id = s.service_id
join sys.service_queue_usages squ on squ.service_id = s.service_id
join sys.service_queues sq on squ.service_queue_id = sq.object_id
@peterhel
peterhel / openvpn-authenticator
Last active December 16, 2022 13:24
IPFire TOTP is kind of a hack. Once an hour a credentials form popup that you need to fill in with bogus credentials to keep the connection alive. But if you save those credentials, shit creek is coming for you, because then you overwrite the password TOTP that's required to trigger the OTP token when you connect. This script just ignore the pas…
#!/usr/bin/python3
###############################################################################
# #
# IPFire.org - A linux based firewall #
# Copyright (C) 2022 Michael Tremer #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
@peterhel
peterhel / today.js
Last active November 12, 2022 19:28
new Date(Math.round(Date.now()/8.64e7)*8.64e7).toISOString()
@peterhel
peterhel / demo.html
Last active August 26, 2022 09:52
Dynamic select boxes
<!doctype html>
<html>
<body>
<select name="brand" id="brand"></select>
<select name="brand" id="model"></select>
<script>
const data = {
Fischer: [
"Speed Cl Zero",
"Speed Twin Skin",
@peterhel
peterhel / DisableScroll.cpp
Created January 1, 2021 22:51
Disable scrolling in windows with empty titles
/*
* Make sure project type is windows application
*/
#define _WIN32_WINNT 0x0500
#include<windows.h>
#include<cmath>
#include <stdio.h>
LRESULT CALLBACK mouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) {