Skip to content

Instantly share code, notes, and snippets.

@kafene
kafene / ifsetor.md
Created August 2, 2014 15:35
PHP 5.6+ ifsetor/coalesce userspace implementation

Ref: https://wiki.php.net/rfc/ifsetor

So I found out something sad: the variadics RFC implementation was altered so that ...$arg can only come last.

And since we can't pass a non-variable default value by reference, it can go first, just kind of confusing looking, unfortunately.

<?php

function coalesce($default, &amp;...$args) {
@kafene
kafene / monolog-pimple-whoops-examples.php
Last active August 7, 2024 05:22
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
###
####### HISTIGNORE #######
###
# examples from interwebs, noob dot file notes
#export HISTIGNORE='pwd:exit:fg:bg:top:clear'
# (if try to erasedups do not ignore things want 2 pune but on OSX it no workie)
# ignore things that start with a space, and ignore the exit command
#HISTIGNORE='[ \t]*:exit'
# some slashdot dudes says
#export HISTIGNORE="&:ls:[bf]g:exit:pwd:clear:mount:umount:[ \t]*"
@kafene
kafene / insertAdjacentElement.md
Last active August 29, 2015 14:18
Element.prototype.insertAdjacentElement shim

This is a shim for Element.prototype.insertAdjacentElement, which is supported all major browsers except Firefox.

Example: https://jsfiddle.net/kafene/s6Lweg5k/

if ("undefined" === typeof (Element.prototype.insertAdjacentElement)) {
    Object.defineProperty(Element.prototype, "insertAdjacentElement", {
        enumerable: false,
        writable: true,
        configurable: true,
@kafene
kafene / promise-script-loader.md
Last active August 29, 2015 14:22
Using Promises to load scripts

I had a few of scripts I want to load in my userscript before executing it. After some head scratching and messing around with Promises it turns out it's quite easy. This way there's no need to require a larger module loader and other dependencies, which can be a pain to work with when writing userscripts.

(function load(scripts) {
    // Wait for DOMContentLoaded/window.onload
    if (document.readyState !== "interactive" && document.readyState !== "complete") {
        document.addEventListener("DOMContentLoaded", load.bind(null, scripts));
        return;
    }
@kafene
kafene / README.md
Last active February 24, 2017 22:48 — forked from EmanueleMinotto/README.md
PHP Microframework

Microframework

This is a PHP (5.3+) microframework based on anonymous functions.

Features

  • requested URLs matched using regular expressions
  • request methods (matches using regular expressions too)
  • differenced FIFO queues for each $priority
  • command line usage
  • backward compatibility
  • integrated Dependency Injection and settings system
  • named patterns
@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 / 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