Skip to content

Instantly share code, notes, and snippets.

View Zegnat's full-sized avatar

Martijn van der Ven Zegnat

View GitHub Profile
<?php
// Create a DateTimeImmutable with the date and time to compare to.
// Use your current timezone, or the timezone of your visitor. I am in Sweden.
$now = new DateTimeImmutable('now', new DateTimeZone('Europe/Stockholm'));
// Create the object with your birthday.
$birthday = $now->setTimezone(new DateTimeZone('Europe/Amsterdam')); // Born in the Netherlands
$birthday = $birthday->setDate(1991, 10, 23); // On the 23rd of October, 1991
$birthday = $birthday->setTime(20, 9); // 9 minutes past 8 in the evening
// What year is it?
$currentyear = intval($now->format('Y'));
<style>
table {
border-collapse: collapse;
}
th, td {
padding: .5em 2em .5em .5em;
border-right: 1px dotted #AAA;
border-bottom: 1px solid #CCC;
}
th {
@Zegnat
Zegnat / custom.css
Last active May 14, 2017 08:21
Facebook with PII censored.
/* People’s names. */
span > a[data-hovercard^="/ajax/hovercard/user.php?"], /* poster and shares */
.UFICommentActorName, /* comments */
.UFICommentBody .profileLink /* inside comments */
{
background-color: currentColor;
}
/* People’s avatars. */
a[data-hovercard^="/ajax/hovercard/user.php?"] > div > img._s0, /* poster */
@Zegnat
Zegnat / Zegnat.Utils.ServerRequestFromGlobals.php
Last active April 10, 2017 22:40
Construct a PSR-7 ServerRequest through a PSR-17 factory for the current HTTP request.
<?php
declare(strict_types=1);
namespace Zegnat\Utils;
use Interop\Http\Factory\ServerRequestFactoryInterface;
use Interop\Http\Factory\StreamFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
@Zegnat
Zegnat / .htaccess
Last active April 5, 2017 00:34
This emulates https://github.com/lazd/mdn.io/ in a 2 line .htaccess file. Compatible with any Apache server with mod_alias enabled.
RedirectMatch 303 /(.+)$ https://duckduckgo.com/?q=!+site:developer.mozilla.org+$1
Redirect 303 / https://developer.mozilla.org/en-US/docs/JavaScript
@Zegnat
Zegnat / Mail.php
Created March 25, 2017 15:15
Dirty EmailSenderInterface implementation for Omnimail.
<?php
namespace Zegnat\Omnimail;
use Omnimail\EmailSenderInterface;
use Omnimail\EmailInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
class Mail implements EmailSenderInterface
{
CodeMirror.defineSimpleMode('human_resource_machine', {
// The start state contains the rules that are intially used
start: [
// Possible header.
{
regex: /^-- HUMAN RESOURCE MACHINE PROGRAM --$/,
token: 'string'
},
// Comment definition.
{
/* Show flags on links to a different language than your entry: */
.h-entry:not([lang|="nl"]) a[hreflang|="nl"]::after { content: ' 🇳🇱'; }
.h-entry:not([lang|="en"]) a[hreflang|="en"]::after { content: ' 🇬🇧'; }
/* You can overwrite on a regional basis: */
.h-entry:not([lang|="en"]) a[hreflang="en-US"]::after { content: ' 🇺🇸'; }
/* Then remove flags for your default language: */
.h-entry:not([lang]) a[hreflang|="en"]::after { content: none; }
@Zegnat
Zegnat / test.txt
Last active December 21, 2016 07:57
Restults from https://kartikprabhu.com/static/demo/selection-encodeURI.html on Windows 10 Pro.
---
Internet Explorer 11
Version: 11.576.14373.0
non-breaking space? Let's try UTF non-breaking space in decimal or non-breaking space in hex?
non-breaking%20space?%20Let's%20try%20UTF%20non-breaking%20space%20in%20decimal%20or%20non-breaking%20space%20in%20hex?
@Zegnat
Zegnat / QBool.php
Created August 22, 2016 12:14
For when you need a quantum boolean that is true only some percent of the time.
<?php
namespace Zegnat;
class QBool
{
public $chance;
public $scale;
public function __construct($chance)