Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
mindplay-dk / bench.js
Created March 22, 2014 04:36
JavaScript benchmark function
// noprotect
/**
* JavaScript benchmark function
*
* Usage: console.log(bench(function(){ ... }));
*/
bench = (function() {
var
@mindplay-dk
mindplay-dk / error-relay.php
Last active August 29, 2015 14:08
Relay php errors to exceptions
<?php
/**
* Map php errors to the built-in ErrorException class.
*
* Respects the error_reporting() setting and the error-suppression operator.
*
* @see ErrorException
*/
@mindplay-dk
mindplay-dk / README.md
Last active August 29, 2015 14:14
Replace a checkbox with a custom div for styling

jQuery plugin to replace checkboxes with <div> elements for styling.

This plugin makes no assumptions about class-names or the contents of the <div> element, it only implements the behavior - it returns the generated <div> elements for further operations with jQuery functions, so you can do for example:

$('input[type=checkbox]')
    .checkbox()            // returns set of <div> elements
    .addClass('checkbox')  // adds class="checkbox" to every <div> element

.html('✔') // inserts a unicode checkmark into every element

@mindplay-dk
mindplay-dk / woohah.ts
Last active September 16, 2015 17:09
Typescript event hook and hookable boxed value classes
/// This interface defines an event listener
interface Listener<Event> {
(event: Event): void
}
/// This interface represents a hookable type
interface Hookable<Event> {
/// Attach a handler to this hookable
(handler: Listener<Event>): void
}
@mindplay-dk
mindplay-dk / Loader.js
Created December 1, 2010 22:25
Dynamic loader for JS and CSS resources
/*
Version: 1.1
Developer: Rasmus Schultz <http://mindplay.dk>
License: GPL v3 <http://www.gnu.org/licenses/gpl-3.0-standalone.html>
Gist: <https://gist.github.com/724347>
Removing this notice from the source code would be bad karma.
*/
@mindplay-dk
mindplay-dk / events.ts
Last active December 23, 2015 16:59
Simple event hook in TypeScript
var template_escape = {"\\": "\\\\", "\n": "\\n", "\r": "\\r", "'": "\\'"}
var render_escape = {'&': '&amp;', '"': '&quot;', '<': '&lt;', '>': '&gt;'}
function escape_fn(data) {
return (data || data === 0)
? (data + '').replace(/[&\"<>]/g, (e) => render_escape[e])
: ''
}
@mindplay-dk
mindplay-dk / upgrade.php
Last active December 25, 2015 02:29
Simple (forward migration) command-line SQL script runner for MySQL.
<?php
/**
* Simple (forward migration) command-line SQL script runner for MySQL.
*
* To initialize the ".upgrade" file:
*
* php upgrade.php --init
*
* To flag all SQL files as applied (in the status file) without actually doing any work:
@mindplay-dk
mindplay-dk / example.css
Last active December 25, 2015 05:09
jQuery slideshow plugin (responsive version with CSS3 optimized animation)
/* main container: */
#test {
clear: both;
width: 100%;
min-width: 240px;
max-width: 790px;
height: 320px;
overflow: hidden;
font-family: Verdana, Arial;
@mindplay-dk
mindplay-dk / example.css
Last active February 15, 2016 08:32
Simplified semantic grid calculation for SASS (based on http://semantic.gs/)
#layout {
display: block;
width: 940px; }
#left {
display: inline;
float: left;
width: 60px; }
#content {
@mindplay-dk
mindplay-dk / GDownload.php
Created January 3, 2012 16:02
File Downloader for Yii (PHP)
<?php
/**
* @author Rasmus Schultz
* @link http://mindplay.dk
* @copyright Copyright &copy; 2010 Rasmus Schultz
* @license http://www.gnu.org/licenses/lgpl-3.0.txt
*/
/**
* This class allows multi-threaded file downloads, and regular file downloads.