Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Munk mmmunk

View GitHub Profile
@mmmunk
mmmunk / image2data.sh
Last active Apr 12, 2021
Reads a directory of picture files and creates a single-file HTML-document including all the pictures as Base64 data inside the document
View image2data.sh
#!/bin/bash
echo -n "data:"`file --mime-type --brief $1`";base64,"`base64 --wrap=0 $1` >`realpath $1`".b64"
@mmmunk
mmmunk / Keep-Windows-Awake.c
Last active Mar 30, 2021
Keep Windows awake
View Keep-Windows-Awake.c
// Build: x86_64-w64-mingw32-gcc -Wall -mwindows -Os -s -o Keep-Windows-Awake.exe Keep-Windows-Awake.c
#include <windows.h>
int main() {
/* Keep Windows awake for the lifetime of this thread */
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
/* Wait via a messagebox */
MessageBox(NULL, "Windows is now being prevented from falling asleep.\n\nPress OK to end this...", "Keep-Windows-Awake", MB_OK | MB_ICONINFORMATION);
}
@mmmunk
mmmunk / eog-helloworld.py
Last active Feb 8, 2021
Quick'n'dirty ½-færdigt hello world Eye of Gnome plugin inkluderende en ½-færdig dialog
View eog-helloworld.py
# Placeres i ~/.local/share/eog/plugins
# Baseret på https://wiki.gnome.org/Apps/EyeOfGnome/Plugins
from gi.repository import GObject, Gdk, Gtk, Eog
class TextDialog(Gtk.Dialog):
def __init__(self, parent, initialtext):
Gtk.Dialog.__init__(self, title="My Dialog", transient_for=parent, flags=0)
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK, Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
self.set_default_size(300, 100)
@mmmunk
mmmunk / check-checksums.sh
Last active Jan 15, 2021
Usage of HashDeep (apt install hashdeep)
View check-checksums.sh
#!/bin/bash
# Files changed or deleted since checksum creation are noted.
# New files are not noted.
if [ -z "$1" ]; then
DIR=`pwd`
else
DIR=`realpath $1`
fi
@mmmunk
mmmunk / receive_commands.py
Last active Jan 12, 2021
Simple UDP packet commands from one program to another
View receive_commands.py
import sys
import socket
import random
# Create and bind UDP socket
bind_ip = sys.argv[1]
bind_port = int(sys.argv[2])
msgsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
msgsock.bind((bind_ip, bind_port))
print('Waiting for commands on', bind_ip, 'port', bind_port)
@mmmunk
mmmunk / BinSearchReplace.dpr
Created Oct 28, 2020
Search for and optionally replace strings in files
View BinSearchReplace.dpr
{ BinSearchReplace Version 0.9 }
program BinSearchReplace;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Windows, SysUtils;
const
cFileChunkSize = 500000;
@mmmunk
mmmunk / MariaDB test-server.txt
Last active Oct 23, 2020
Nem opsætning af simpel/slank MariaDB test-server på Windows
View MariaDB test-server.txt
Nem opsætning af simpel/slank MariaDB test-server på Windows
------------------------------------------------------------
Hent seneste stable MariaDB til Windows
(ZIP-fil uden debug-symbols, ikke MSI)
fra https://downloads.mariadb.org/
Der oprettes en valgfri rod-mappe
@mmmunk
mmmunk / rsync-verify.txt
Last active Sep 17, 2020
Verify filetree via rync
View rsync-verify.txt
Create/update the copy:
rsync -avi --delete A/ B/
Verify:
rsync --dry-run --recursive --checksum --times --delete --itemize-changes --verbose --stats A/ B/
View C compiler for Windows on Ubuntu.md

Command 'x86_64-w64-mingw32-gcc' not found, but can be installed with:

64-bit exe: sudo apt install gcc-mingw-w64-x86-64

32-bit exe: sudo apt install gcc-mingw-w64-i686

@mmmunk
mmmunk / fetch-ex.js
Created Sep 3, 2020
Example use of Javascript Fetch
View fetch-ex.js
function call_api(url, args, rsp_json, result_func) {
// Start the fetch chain of promises
fetch(url, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(args)
})
.then(rsp => {
// rsp.ok true if rsp.status is 200-299
if (rsp.ok) {