Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
mindplay-dk / gameoflife.go
Created December 19, 2013 02:28
My first stab at programming in Go: Conway's Game of Life and a simple test-suite
package main
import (
"bytes"
)
const newline = "\n"
const alive = "O"
const dead = "."
@mindplay-dk
mindplay-dk / BlowfishService.php
Last active December 26, 2015 07:49
A simple Blowfish password hashing service
<?php
BlowfishService::init();
/**
* Blowfish password hashing service
*
* This class will throw (immediately on load) on PHP versions prior to 5.3.2, which
* did not support the Blowfish algorithm. (and/or would fall back to DES.)
*
@mindplay-dk
mindplay-dk / addRule.js
Created October 12, 2013 02:08
Add CSS rules at run-time
/**
* This function allows for definition of CSS rules at run-time
*/
window.addRule = (function() {
var el;
return function(selector, rule) {
if (!el) {
if (document.createStyleSheet) {
@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.html
Created October 9, 2013 20:23
jQuery slideshow plugin
<div id="test">
<div class="slide">
<img src="http://farm4.staticflickr.com/3125/2629096658_8c57d707b3_z.jpg"/>
</div>
<div class="slide" data-delay="2">
<img src="http://farm7.staticflickr.com/6143/5951493219_f65139d65a_z.jpg"/>
</div>
<div class="slide" data-delay="5">
<img src="http://farm1.staticflickr.com/89/253367473_74a5c4dae2_z.jpg"/>
</div>
@mindplay-dk
mindplay-dk / example.html
Created October 9, 2013 19:24
jQuery formstate()
<form method="post">
<input type="hidden" name="hidden" value="this won't be included"/>
<div style="display:none">
<input type="text" name="hidden_text" value="this can be filtered"/>
</div>
<input type="password" name="password"/><br>
<input type="text" name="text"/><br>
<input type="checkbox" name="checkboxes" value="a"/> a
<input type="checkbox" name="checkboxes" value="b"/> b
<input type="checkbox" name="checkboxes" value="c"/> c <br>
@mindplay-dk
mindplay-dk / example.js
Created October 9, 2013 19:21
jQuery DOM shortcuts
/*
And now for a demonstration...
Note that this little script is shorter than the equivalent hand-written HTML code.
I didn't benchmark it, but it's likely faster than inserting and parsing HTML too,
since document.createElement() is used when creating the elements, and that is
generally about 10 times faster than parsing out HTML.
*/
@mindplay-dk
mindplay-dk / named-functions.html
Created October 9, 2013 17:46
Testing scope of named functions in other named functions and in closures.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function outside() {
function inside(message) {
window.alert(message);
@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 / jquery.order.js
Created October 4, 2013 12:52
jQuery plugin to sort/order a list of HTML elements (including lists, tables, any element type or structure)
/**
* Sort a list of elements and apply the order to the DOM.
*/
jQuery.fn.order = function(asc, fn) {
fn = fn || function (el) {
return $(el).text().replace(/^\s+|\s+$/g, '');
};
var T = asc !== false ? 1 : -1,
F = asc !== false ? -1 : 1;
this.sort(function (a, b) {