Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
karl-gustav / stderr
Last active February 8, 2024 11:42
Listening for macOS wakeup events
JIT session error: Symbols not found: [ _OBJC_CLASS_$_NSWorkspace, _NSWorkspaceDidWakeNotification ]
Failed to materialize symbols: { (main, { __swift_FORCE_LOAD_$_swiftObjectiveC_$_watch_for_lock_unlock, _got.$sSY8rawValuexSg03RawB0Qz_tcfCTq, _$sSo18NSNotificationNameaSYSCMA, __swift_FORCE_LOAD_$_swiftos_$_watch_for_lock_unlock, _got.$s8RawValueSYTl, _got.$ss20_SwiftNewtypeWrapperPSYTb, _$s10Foundation12NotificationVIeghn_So14NSNotificationCIeyBhy_TR, _symbolic _____ 21watch_for_lock_unlock18ScreenLockObserverC, _got.$ss20_SwiftNewtypeWrapperMp, _$s21watch_for_lock_unlock18ScreenLockObserverCMn, _$sSo18NSNotificationNameaABSYSCWL, _$s21watch_for_lock_unlock18ScreenLockObserverCMm, _got.$s15_ObjectiveCTypes01_A11CBridgeablePTl, _associated conformance So18NSNotificationNameaSHSCSQ, _associated conformance So18NSNotificationNameas20_SwiftNewtypeWrapperSCSY, _$sSo18NSNotificationNameaABs35_HasCustomAnyHashableRepresentationSCWl, _$sSo18NSNotificationNameas20_SwiftNewtypeWrapperSCMc, _$sS2Ss21_ObjectiveCBridgeab
@karl-gustav
karl-gustav / main.py
Created December 13, 2022 12:52
Minimal Python3 webserver (zero dependencies)
import http.server
import socketserver
from http import HTTPStatus
import os
class Handler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(HTTPStatus.OK)
self.end_headers()
@karl-gustav
karl-gustav / backup.sh
Created November 13, 2022 10:23
Backup script with aes-256-cbc encryption and automatically spits the output into 4GB chunks (for fat32 file systems)
#! /bin/bash
if ! [ $# -eq 1 ] ;then
echo "Ha mappen du vil ha backup av som argument"
exit 1
fi
echo "Navn på backupen:"
read name
echo "Passord:"
@karl-gustav
karl-gustav / fullURL.go
Created September 25, 2022 20:42
Get full URL from http request in go
func fullURL(r *http.Request, overridePath ...string) string {
scheme := "http"
if r.TLS != nil {
scheme = "https"
}
if len(overridePath) != 0 {
return fmt.Sprintf("%s://%s%s", scheme, r.Host, overridePath[0])
}
return fmt.Sprintf("%s://%s%s?%s#%s", scheme, r.Host, r.URL.Path, r.URL.RawQuery, r.URL.Fragment)
@karl-gustav
karl-gustav / encrypt_decrypt.go
Created September 25, 2022 20:32
AES encryption and decryption with password
// based on https://github.com/isfonzar/filecrypt/blob/master/filecrypt.go
func encryptAES(password, plaintext string) (string, error) {
key := []byte(password)
nonce := make([]byte, 12)
// Randomizing the nonce
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
return "", fmt.Errorf("io.ReadFull(...): %w)", err)
}
@karl-gustav
karl-gustav / server.js
Created February 11, 2022 22:43
Minimal pure node js server
const http = require('http');
const url = require('url');
function handler(req, res) {
res.writeHead(200, {'Content-type':'text/plain'});
res.write('Hello, I am a webserver !');
res.end();
}
const port = process.env.PORT || 8080;
@karl-gustav
karl-gustav / main.go
Created December 16, 2021 11:11
using zap for logging in GCP
package main
import (
"github.com/blendle/zapdriver"
"go.uber.org/zap"
)
func main() {
structuredLogger, _ := zapdriver.NewProduction()
defer structuredLogger.Sync() // flushes buffer, if any
@karl-gustav
karl-gustav / heic_to_jpg.sh
Created October 24, 2021 14:13
Convert heic --> jpg on a mac
for file in *.heic; do sips -s format jpeg "$file" --out "${file%.heic}.jpg" && rm -f "$file"; done
@karl-gustav
karl-gustav / archive.applescript
Created October 20, 2021 10:45
Script for archiving a message (used in keyboard maestro)
tell application "System Events"
click menu item "Archive" of menu "Message" of menu bar 1 of application process "Mail"
end tell
@karl-gustav
karl-gustav / .vimrc
Created October 5, 2021 06:11
my .vimrc file (mac)
filetype plugin indent on
syntax on
au FileType gitcommit set tw=72
" scrolling in (iTerm2)
:set mouse=a
" Spellchecking in vim
:setlocal spell spelllang=en_us