Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
mindplay-dk / jquery.console.js
Created March 19, 2015 09:36
jquery.console.js
/**
* jQuery wrapper/plugin for console functions in FF/IE/Chrome.
*
* These functions execute silently when no console is available, so
* you can safely leave diagnotics calls in place during development
* and beta-testing.
*
* Examples:
*
* $.log('Hello, World.',1,2,3);
@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 / jquery.scrollbarWidth.js
Created January 26, 2011 15:31
Small plugin that reports the size of the browser's scrollbars in pixels.
/*!
* jQuery Scrollbar Width v1.0
*
* Copyright 2011, Rasmus Schultz
* Licensed under LGPL v3.0
* http://www.gnu.org/licenses/lgpl-3.0.txt
*/
(function($){
@mindplay-dk
mindplay-dk / jquery.swap-jumble.js
Created February 2, 2011 20:40
swap() and jumble() functions for jQuery
/**
* http://plugins.jquery.com/project/swap-jumble
*/
(function($){
$.fn.swap = function(b){
b = $(b)[0];
var a = this[0];
var t = a.parentNode.insertBefore(document.createTextNode(''), a);
b.parentNode.insertBefore(a, b);
/*
bugfix for "DocsByReflection.cs"
http://jimblackler.net/blog/?p=49
Replace broken XMLFromName() method with the following fixed method:
*/
@mindplay-dk
mindplay-dk / pwordwrap.php
Created March 18, 2011 12:53
A drop-in replacement for wordwrap() for proportional fonts
<?php
/**
* Proportional word-wrap (approximation)
*
* Attempts to work as a drop-in replacement for wordwrap()
*
* Based on http://www.php.net/manual/en/function.wordwrap.php#82580
*/
function pwordwrap($str, $width=75, $break="\n")
@mindplay-dk
mindplay-dk / security-context.php
Created June 18, 2011 02:51
Security context checking in PHP
<?php
class SecurityContext
{
private $_readonly = false;
private $_context = array();
public static $actions = array(
);
@mindplay-dk
mindplay-dk / EntityTypeExtension.cs
Created July 18, 2011 13:20
Extension method to get the underlying Entity-type of an NHibernate Proxy (or Entity)
/*
This code assumes an IEntity interface that identifies your persistent types.
*/
/// <summary>
/// This static class provides common extension methods for <see cref="IEntity"/> types.
/// </summary>
public static class EntityExtensions
@mindplay-dk
mindplay-dk / oop-backreferences.php
Created January 3, 2012 17:37
short rant about a shortcoming of OOP languages in general
// let's say we have a house:
$house = new House();
// let's say the house has a door:
$door = new Door();
// why does it take two steps to add the door to the house?