Skip to content

Instantly share code, notes, and snippets.

View bendem's full-sized avatar
🥕

bendem bendem

🥕
View GitHub Profile
@bendem
bendem / rotate.sh
Created March 21, 2025 15:07
rotate files, keeping the last x
# bad, if the recent backups failed, this can end up removing everything
find . -type f -name 'test-*' -mtime +5 -delete
# good, keeps 5 files at all time
keep=5
find . -type f -name 'test-*' -printf '%T@\0%p\n' \
| sort -rn \
| cut -d $'\0' -f2 \
| tail -n +$(( keep + 1 ) \
| xargs rm
@bendem
bendem / bw-agent
Last active March 21, 2025 15:08
Bitwarden scripts to keep a session open without the need to export env variables.
#!/usr/bin/env python3
import grp
import os
import pwd
import socket
import sys
import subprocess
import struct
import typing
@bendem
bendem / check olcAccess.sh
Last active March 21, 2025 15:18
Some useful ldap commands
ldapsearch -LLL -o ldif-wrap=no -H ldapi:/// -Y EXTERNAL -b 'cn=config' 'olcAccess=*' olcAccess \
| awk '{
if ($1 == "olcAccess::") {
command = "base64 -d -i"; print $2 | command; close(command)
} else {
print $0
}
}'
[Unit]
Description=Apache Tomcat Web Application Container
After=network-online.target
Wants=network-online.target
[Service]
User=tomcat
Group=tomcat
WorkingDirectory=/opt/tomcat-9
@bendem
bendem / app.js
Last active September 7, 2017 07:16
Reveal a blurred image with your mouse (demo at https://test.bendem.be/blurpath/).
'use strict';
var htmlLoaded = false;
var imgLoaded = false;
var pic = new Image;
pic.onload = function() {
imgLoaded = true;
load();
};
mount="/home/bendem/nas-samba"
d=`date +"%H:%M:%S %d-%m-%Y"`
echo "Backup task running $d"
# Skip if not mounted
grep -qs "$mount" /proc/mounts
if [ $? -ne 0 ]; then
echo "Skipping..."
exit
var Enum = function(values, methods) {
var created = {};
var EnumValue = function(value) {
this.value = value;
}
if(methods) {
for(var name in methods) {
EnumValue.prototype[name] = methods[name];
}
@bendem
bendem / ajax.js
Last active August 29, 2015 14:17
// Simple ajax thing to send stuff
// @param url string
// @param success callback
// @param method string (optional)
// @param data plainobject (optional)
function ajax(url, success, method, data) {
var xhr = new XMLHttpRequest();
// Set the callback to use when all the stuff is done
xhr.onreadystatechange = function() {
// We are not interested in the 3 other stages
@bendem
bendem / ColorUtils.java
Last active August 29, 2015 14:09
Image edition tests, main class is PictureTest (java 8!)
package be.bendem.testing.utils;
public class ColorUtils {
private ColorUtils() {}
public static int[] decompose(int color) {
int[] rgb = new int[3];
rgb[0] = color >> 16 & 0xFF;
@bendem
bendem / index.html
Last active August 29, 2015 14:07
glowstone.turt2live.com's source
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Glowstone Testing</title>
<!--<script src="/bundles/modernizr?v=qVODBytEBVVePTNtSFXgRX0NCEjh9U_Oj8ePaSiRcGg1"></script>-->
<!--<link rel="stylesheet" href="/Content/css/Glowstone.css">-->
<link rel="stylesheet" href="style.css">
<script src="http://glowstone.turt2live.com/bundles/jquery?v=JzhfglzUfmVF2qo-weTo-kvXJ9AJvIRBLmu11PgpbVY1"></script>