Skip to content

Instantly share code, notes, and snippets.

@DaveRandom
DaveRandom / .gitignore
Created August 2, 2016 10:07
Default repository layout - PHP web application
vendor # ignore composer data
# ignore PHP Storm config
# you may want to ignore your IDE config and you may want to commit it, up to you
.idea
@cgray
cgray / route-to-url.php
Created April 4, 2017 03:54
Given an array of placeholder values and a FastRoute uri definition build a url
<?php
function buildUrl($uri, array $params) {
$matches = [];
$pattern = '{\s* ([a-zA-Z_][a-zA-Z0-9_-]*) \s*(?:: \s* ([^{}]*(?:\{(?-1)\}[^{}]*)*))?\}';
$optionalSegments = '\[.*'.$pattern.'\]';
$uri = preg_replace_callback('~'.$optionalSegments.'~x', function($match) use ($params) {
$uri = trim($match[0], '[]');
if (isset($params[$match[1]])) {
@DaveRandom
DaveRandom / script.js
Last active June 6, 2018 09:36
Tweet icon for Jeeves in SO chat
// ==UserScript==
// @name Tweet icon for Jeeves in SO chat
// @namespace http://room11.org/
// @version 1.0
// @description @PeeHaa sucks
// @author @DaveRandom
// @match *://chat.stackoverflow.com/rooms/*
// @grant none
// ==/UserScript==