Skip to content

Instantly share code, notes, and snippets.

@kafene
kafene / pulseaudio-systemd-user.md
Created May 18, 2017 08:00
Pulseaudio via systemd --user

~/.config/systemd/user/pulseaudio.service:

[Unit]
Description=Pulseaudio Sound Service
Requires=pulseaudio.socket

[Service]
Type=notify
ExecStart=/usr/bin/pulseaudio --verbose --daemonize=no
@kafene
kafene / gpg-wkd.md
Last active April 12, 2024 19:14
Setting up WKD for self-hosted automatic key discovery

I just got this working so I figured I'd share what I found, since there's hardly any information about this anywhere online except an RFC, the GPG mailing list and one tutorial from the GnuPG blog.

You can use automatic key discovery with WKD (Web key directory) to make it easy for users to import your key, in GPG since version 2.1.12. Since this feature is fairly new, it isn't yet available in the current LTS release of Ubuntu (16.04; xenial), however it is available in Debian stable (stretch).

I couldn't add a DNS CERT or DANE / OPENPGPKEY record through my email service (which also hosts my nameservers). I tried making the PKA record - a foo._pka.example.com TXT record but GPG doesn't seem to recognize it and fails; I'm still investigating why.

So the last option for self-hosted auto-discovery was WKD.

First thing I had to do was add an email address to my key. My primary UID is just my name so the key represents my identity rather

@kafene
kafene / background.js
Created August 29, 2023 14:37
Tab deque modified (tabs.moveInSuccession)
/* jshint esversion:11 */
// Maps each window ID to an array of its tab IDs
const deques = {};
// New background tabs will be added after the current tab instead of at the end of the deque
let addBackgroundTabsAfterCurrent = false;
// Create deque for this windowId if it does not exist
// Omit hidden tabs, keep discarded tabs at the end.
@kafene
kafene / firefox-extension-get-selected-text.md
Created March 10, 2017 13:17
Getting the currently selected text in a Firefox extension

Post e10s, this seems to be the most consistent way (should work in both pre and post-e10s builds):

const tabs = require("sdk/tabs");

function getSelectedText() {
    return new Promise(function (resolve, reject) {
        tabs.activeTab.attach({
            contentScript: "self.postMessage(String(getSelection()));",
 onMessage: resolve,
@kafene
kafene / distances_slc_haversine.php
Created July 25, 2014 06:56
distance calculations using Spherical Law of Cosines and Haversine Formula
<?php
# Spherical Law of Cosines
function distance_slc($lat1, $lon1, $lat2, $lon2) {
$a = sin(deg2rad($lat1)) * sin(deg2rad($lat2));
$b = cos(deg2rad($lat1)) * cos(deg2rad($lat2));
$c = cos(deg2rad($lon2 - $lon1));
$distance = rad2deg(acos($a + $b * $c));
return round($distance * 60 * 1.1515, 4);
}
@kafene
kafene / mailhog-install.sh
Created June 16, 2018 00:16
Install Mailhog
#!/usr/bin/env bash
set -euo pipefail
if [[ -f /usr/local/bin/mailhog ]]; then
echo 'It seems mailhog is already installed.' >&2
echo 'Remove </usr/local/bin/mailhog> to force reinstallation.' >&2
exit 1
fi
if [[ "$EUID" -ne 0 ]]; then
@kafene
kafene / monolog-pimple-whoops-examples.php
Last active September 24, 2021 20:51
Set up some Monolog handlers, a Pimple Container, and Whoops
<?php
/**
* Various configurations of Monolog and Whoops
* using a Pimple Container as service locator
*
* Monolog: https://github.com/Seldaek/monolog
* Pimple: https://github.com/fabpot/Pimple
* Whoops: https://github.com/filp/whoops
* Swift Mailer: https://github.com/swiftmailer/swiftmailer
@kafene
kafene / com.ubuntu.desktop.pkla
Created July 24, 2014 10:12
/var/lib/polkit-1/localauthority/10-vendor.d/com.ubuntu.desktop.pkla (see: policykit-desktop-privileges)
[Mounting, checking, etc. of internal drives]
Identity=unix-group:admin;unix-group:sudo
Action=org.freedesktop.udisks.filesystem-*;org.freedesktop.udisks.drive-ata-smart*;org.freedesktop.udisks2.filesystem-mount-system;org.freedesktop.udisks2.encrypted-unlock-system;org.freedesktop.udisks2.filesystem-fstab;
ResultActive=yes
[Change CPU Frequency scaling]
Identity=unix-group:admin;unix-group:sudo
Action=org.gnome.cpufreqselector
ResultActive=yes
@kafene
kafene / openssltest.php
Created July 11, 2021 21:20
openssl algorithm testing
<?php
set_error_handler(static function ($severity, $message, $file, $line) {
throw new \ErrorException($message, 0, $severity, $file, $line);
});
$str = 'Testing OpenSSL algorithms...';
$tag = random_bytes(16);
foreach (openssl_get_cipher_methods() as $algo) {
@kafene
kafene / cb-aerosnap
Created July 22, 2014 20:48
A script for adding aero style window snapping to Openbox.
#!/usr/bin/env python
# cb-aerosnap:
# A script for adding aero style window snapping to Openbox.
# Written for CrunchBang Linux <http://crunchbang.org/>
# by Philip Newborough <corenominal@corenominal.org>
# ----------------------------------------------------------------------
# License:
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#