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 / 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 \
@jornane
jornane / random.php
Created March 9, 2021 16:30
Random string
echo strtolower( strtr( base64_encode( random_bytes( 12 ) ), '/+9876', '012345' ) );
@jornane
jornane / centos8-autoupdate.sh
Last active February 1, 2024 13:47
Enable automatic updating on CentOS 8
# NOTE: Need at least 8.1, does not work on 8.0
dnf install -y dnf-automatic
sed -i -e '/apply_updates/ s/no/yes/' /etc/dnf/automatic.conf
tee /etc/cron.daily/0autoreboot.cron <<EOF
#!/bin/sh
dnf needs-restarting -r >/dev/null || { reboot; exit 0; }
EOF
chmod +x /etc/cron.daily/0autoreboot.cron
systemctl enable --now dnf-automatic.timer
@jornane
jornane / about:config.txt
Last active November 19, 2024 06:32
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
@jornane
jornane / GROW.md
Created October 23, 2017 12:12
How to grow a partition in Linux

How to grow a partition in Linux

This guide will walk you through the steps required to grow a partition in Linux. You will have to reboot through this guide.

  1. If possible, make a snapshot.

Often, you will want to grow the partition table because you made your virtual hard disk too small, and you tried to extend it in your hypervisor, only to find out that your partition is still the same size as it was before.

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))
<?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]);
}
@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'];
#!/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