Skip to content

Instantly share code, notes, and snippets.

View jornane's full-sized avatar
:octocat:
Enjoying sr.ht

Jørn Åne de Jong jornane

:octocat:
Enjoying sr.ht
View GitHub Profile
@jornane
jornane / _autoload.php
Last active November 10, 2015 12:49
Activate the native C SPL autoloader as included in PHP since PHP 5.1.2. Put this file in your namespace root and make sure it gets included from your PHP entry-point.
<?php
/*
* Copyright (c) 2014-2015, Jørn Åne de Jong <@jornane>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
#!/bin/sh
find ~/Documents/Textual\ Logs -type f -name \*.txt | while read file
do
test -z "$(grep -v '————————————— Begin Session —————————————' "$file" | grep -v '————————————— End Session —————————————' | grep -v '^ $' )" && rm "$file"
done
@jornane
jornane / url.php
Created September 4, 2017 09:16
URL parser
<?php
function getRedirectTo(string $appBaseUrl, $server, $redirectTo = ''): string {
$returnUrlData = strlen($redirectTo) > 0
? parse_url($redirectTo, PHP_URL_SCHEME|PHP_URL_HOST|PHP_URL_PORT|PHP_URL_PATH|PHP_URL_QUERY|PHP_URL_FRAGMENT)
: []
;
$appBaseUrlParsed = parse_url($appBaseUrl, PHP_URL_SCHEME|PHP_URL_HOST|PHP_URL_PORT|PHP_URL_PATH|PHP_URL_QUERY|PHP_URL_FRAGMENT)
if (!array_key_exists($returnUrlData, 'scheme')) {
if (array_key_exists($appBaseUrlParsed, 'scheme')) {
$returnUrlData['scheme'] = $appBaseUrlParsed['scheme'];
<?php
// https://blogs.msdn.microsoft.com/oldnewthing/20040315-00/?p=40253/
function sid2bin($sid) {
if (!preg_match('/^S-(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})(-[1-9][0-9]*){3,255}$/', $sid)) throw new Exception('Not an sid');
$segments = explode('-', $sid);
$str = pack('hhnN', $segments[1], sizeof($segments)-3, $segments[2] >> 32, $segments[2]);
for($i=3;$i<sizeof($segments);$i++) {
$str .= pack('V', $segments[$i]);
}
import time
for i in range(1, 1000):
i = i / 1000.0
then = time.time()
time.sleep(max(0, i - 0.005))
now = time.time()
while now - then - i < 0:
now = time.time()
print(round(now - then - i, 5))
@jornane
jornane / random.php
Created March 9, 2021 16:30
Random string
echo strtolower( strtr( base64_encode( random_bytes( 12 ) ), '/+9876', '012345' ) );
@jornane
jornane / pkg-reset.sh
Created February 4, 2022 21:35
Completely reset pkg and all packages in FreeBSD
# Running this WILL make you cry.
# You have been warned.
rm -rf \
/usr/local/etc \
/usr/local/include \
/usr/local/lib \
/usr/local/libdata \
/usr/local/man \
/usr/local/sbin \

Pushing things to QUAY without selling your soul

Quay is your next hip cloud thingy that's going to change the world. Here, we're going to use it as a Docker registry without giving it full write access to our GitHub account, because we're having cold feet.

You see, when you try to create a new Docker repository in Quay, it helpfully suggests pointing it to a GitHub repo, so it can do all Docker building stuff for you. But in order to let it do that, it wants to have full read and write access to all your repos, both private and public. Personally, I don't think

@jornane
jornane / about:config.txt
Last active March 9, 2022 21:51
Recommended Firefox about:config settings
# Recommended Firefox about:config settings
# Privacy
# https://support.mozilla.org/en-US/kb/how-stop-firefox-making-automatic-connections
extensions.blocklist.enabled;false
browser.safebrowsing.downloads.remote.enabled;false
browser.safebrowsing.malware.enabled;false
browser.safebrowsing.passwords.enabled;false
browser.safebrowsing.phishing.enabled;false
network.prefetch-next;false
@jornane
jornane / centos7-autoupdate.sh
Last active March 14, 2023 06:43
Enable automatic updating on CentOS 7
yum install -y yum-cron yum-utils
sed -i -e '/apply_updates/ s/no/yes/' /etc/yum/yum-cron.conf
tee /etc/cron.daily/0autoreboot.cron <<EOF
#!/bin/sh
needs-restarting -r >/dev/null || { reboot; exit 0; }
needs-restarting -s | grep -q auditd.service && { reboot; exit 0; }
needs-restarting -s | xargs --no-run-if-empty -n1 systemctl restart
EOF
chmod +x /etc/cron.daily/0autoreboot.cron