Skip to content

Instantly share code, notes, and snippets.

View mmmunk's full-sized avatar

Thomas Munk mmmunk

View GitHub Profile
@mmmunk
mmmunk / gtk4-image-scale.py
Last active September 9, 2022 09:30
New way of scaling images using pixbuf and gtk
#!/usr/bin/env python3
# https://discourse.gnome.org/t/scaling-images-with-cairo-is-much-slower-in-gtk4/7701
# https://blog.gtk.org/2018/03/16/textures-and-paintables/
import gi
gi.require_version("Gtk", "4.0")
gi.require_version("Gdk", "4.0")
gi.require_version("GdkPixbuf", "2.0")
from gi.repository import Gtk, Gdk, GdkPixbuf
@mmmunk
mmmunk / eog-helloworld.py
Last active February 8, 2021 14:10
Quick'n'dirty ½-færdigt hello world Eye of Gnome plugin inkluderende en ½-færdig dialog
# 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 / receive_commands.py
Last active January 12, 2021 09:44
Simple UDP packet commands from one program to another
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 October 28, 2020 14:36
Search for and optionally replace strings in files
{ BinSearchReplace Version 0.9 }
program BinSearchReplace;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Windows, SysUtils;
const
cFileChunkSize = 500000;
@mmmunk
mmmunk / check-checksums.sh
Last active January 15, 2021 13:01
Usage of HashDeep (apt install hashdeep)
#!/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 / rsync-verify.txt
Last active September 17, 2020 12:21
Verify filetree via rync
Create/update the copy:
rsync -avi --delete A/ B/
Verify:
rsync --dry-run --recursive --checksum --times --delete --itemize-changes --verbose --stats A/ B/
@mmmunk
mmmunk / fetch-ex.js
Created September 3, 2020 11:25
Example use of Javascript Fetch
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) {
@mmmunk
mmmunk / TempLoggerService.c
Created June 18, 2020 11:14
Very basic Windows Service template in C
// Very basic Windows Service template - maybe not fully correct/complete but it works.
// x86_64-w64-mingw32-gcc -mwindows -municode -O2 -s -o TempLoggerService.exe TempLoggerService.c
// SC create TempLoggerService binpath="C:\Temp\TempLoggerService.exe"
// SC delete TempLoggerService
#include <windows.h>
#include <stdio.h>
#define SERVICE_NAME L"TempLoggerService"
@mmmunk
mmmunk / image2data.sh
Last active April 12, 2021 11:39
Reads a directory of picture files and creates a single-file HTML-document including all the pictures as Base64 data inside the document
#!/bin/bash
echo -n "data:"`file --mime-type --brief $1`";base64,"`base64 --wrap=0 $1` >`realpath $1`".b64"
@mmmunk
mmmunk / WindowsBatchTipsTricks.cmd
Last active October 23, 2019 09:44
Tips & Tricks for Windows Batch files
REM This file is not meant to be run in it's entirety
REM --- Check if script is run as administrator
net session >nul 2>&1
if %errorlevel% neq 0 (
echo This script must be run with administrator privileges
pause
exit /B
)