Skip to content

Instantly share code, notes, and snippets.

@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:
*/
// Extension for System.Type enabling direct access to <summary> contents.
//
// This extension uses DocsByReflection by Jim Blackler:
//
// http://jimblackler.net/blog/?p=49
//
// (this just does the summary for types, but it should be easy to extend this
// concept to include other members and other tags...)
static class DocsByReflectionExtensions
@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 / StringSubstitutionExtension.cs
Created March 31, 2011 16:39
A static class that allows you to use name/value pairs from an dictionary to substitute string-representations of object values - this extension complements String.Format()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Mindplay.Extensions
{
/// <summary>
/// This extension provides an alternative to <see cref="String.Format"/> allowing the
/// use of an <see cref="IDictionary{String,Object}"/> to replace named (rather than
@mindplay-dk
mindplay-dk / restart-sidebar.vbs
Created June 17, 2011 21:22
Restart the Windows 7 Sidebar (for easier Gadget development)
Set WMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
For Each sidebar in WMI.ExecQuery("Select * from Win32_Process Where Name = 'sidebar.exe'")
sidebar.Terminate()
Next
sidebarPath = "C:\Program Files\Windows Sidebar\sidebar.exe"
CreateObject("Wscript.Shell").Run """" & sidebarPath & """", 0, False
@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