Skip to content

Instantly share code, notes, and snippets.

View dantman's full-sized avatar

Daniel Friesen dantman

View GitHub Profile
@dantman
dantman / results.txt
Last active December 18, 2015 05:49
Benchmarking different types of html escapes. strtr vs various ways of doing str_replace.
Daniels-MacBook-Air:5735077 daniel$ php test.php
escape1: 52.938008308411µs.
escape2: 11.997318267822µs.
escape3: 11.176705360413µs.
escape4: 11.816596984863µs.
escape5: 10.962629318237µs.
escape6: 12.953281402588µs.
Daniels-MacBook-Air:5735077 daniel$ php test.php
escape1: 54.372382164001µs.
escape2: 11.764526367188µs.
@dantman
dantman / index.html
Created June 3, 2013 03:25
Testing to ensure that an RDFa rel=":stylesheet" will NEVER be treated as rel="stylesheet"
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>rel=":stylesheet" safety test</title>
<link rel="stylesheet" href="safe.css">
<link rel=":stylesheet" href="unsafe.css">
</head>
<body>
<p>Background color indicates safety within this browser; Blue = Safe, only rel="stylesheet" is loaded. Red = Unsafe, rel=":stylesheet" was loaded as a stylesheet.</p>
@dantman
dantman / composer.json
Last active December 17, 2015 22:19
Testing nested RDFa foaf and foaf in <head> using bnodes.
{
"require": {
"easyrdf/easyrdf": "@beta"
}
}
@dantman
dantman / ns.php
Last active December 17, 2015 20:09
A script to scan over prefix.cc and determine the most popular patterns for rdf namespace IRIs
<?php
$ns = json_decode( file_get_contents( "http://prefix.cc/popular/all.file.json" ) );
foreach ( $ns as $k => $v ) {
if ( is_null( $v ) ) {
unset( $ns->{$k} );
}
}
$types = array( '/ns/', '/ns#', '/rdf/', '/rdf#', '/ns/', '/ns#', '/schema/', '/schema#', '/ontologies/', '/ontologies#', '/vocab/', '/vocab#', '/namespaces/', '/namespaces#', '/ontology/', '/ontology#', '/xml/', '/xml#', '/owl/', '/owl#', '/schema/', '/schema#', '/spec/', '/spec#', '/terms/', '/terms#', '/schemas/', '/schemas#' );
$types = array_combine( $types, array_fill( 0, count( $types ), 0 ) );
@dantman
dantman / Output.css
Created April 5, 2013 22:02
How support for @media inside a media => "..." should work.
@media screen {
.a { color: red; }
}
@media screen and (max-width: 600px) {
.a { color: blue; }
}
@media screen {
.b { color: green; }
}
@dantman
dantman / gevent-stompest-pingpong.py
Created April 2, 2013 07:06
Ping-Pong STOMP server. Demonstrating stompest with gevent.
import logging, gevent
from gevent import monkey
from stompest.config import StompConfig
from stompest.protocol import StompSpec
from stompest.sync import Stomp
## Ideally this code (or something like it) would work without the following two lines
monkey.patch_socket()
monkey.patch_select()
@dantman
dantman / gist:5273637
Last active December 15, 2015 14:19
Typical RL definition for skins.
<?php
$wgResourceModules['skins.yourskin'] = array(
'styles' => array(
'yourskin/yourskin.css' => array( 'media' => 'screen' ),
),
'remoteBasePath' => &$GLOBALS['wgStylePath'],
'localBasePath' => &$GLOBALS['wgStyleDirectory'],
);
@dantman
dantman / TemplateParser.php
Created October 24, 2012 03:14
New templated skin parser attempt
<?php
class TemplateNode {
}
class TemplateText extends TemplateNode {
}
class TemplateCondition extends TemplateNode {}
@dantman
dantman / gist:3333040
Created August 12, 2012 17:10
MediaWiki Notification System Intro
var time = 0;
[
[ 0, 'This is the new notification system.' ],
[ 6, 'As you can see it has autohide just like the previous one.' ],
[ 6, 'And clicking on a message will also hide it just like before.' ],
[ 6, 'But this time arround.' ],
[ 1, 'We support multiple messages.' ],
[ 2, 'Any sane number of them, really.' ],
[ 6, 'Auto-hide is good and all. But frankly sometimes you just HAVE to have a notification stick around.' ],
[ 1, 'This one uses { autoHide: false }', { autoHide: false } ],
@dantman
dantman / gist:3115181
Created July 15, 2012 05:38
Closure based result iterator
<?php
class Application {
// [...]
function getOwners() {
$res = $db->select(
array( 'user', 'application_owner' ),
User::selectFields(),
array( 'ao_app' => $this->getID() ),
__METHOD__,
null,