Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
mindplay-dk / gist:1207086
Created September 9, 2011 19:18
CSS for database queries?

Most query-languages for databases are not as elegant or expressive as CSS.

Has anyone attempted to use CSS selectors as the query language for databases?

This idea lends itself naturally to document databases - let's say you have the following document:

<blogpost title="This Week's Crazy Idea">
  <user name="Rasmus" class="author"/>
  <body>

...

@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.
@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?
@mindplay-dk
mindplay-dk / yii-phar.php
Created January 13, 2012 16:23
Package the Yii framework as a .phar archive
<?php
/*
Place this script in the Yii framework folder (yii-x.y.z.rxxx/yii-phar.php) and run it
to package the framework into a single phar file.
In the "index.php" of your application, assuming you placed the packaged framework under
your application's "protected" folder, add the following line at the top:
@mindplay-dk
mindplay-dk / Controller.php
Created June 15, 2012 18:49
Extending CController with support for action-method argument resolvers.
<?php
class Controller extends CController
{
/**
* @var array A stack of action-method arguments resolved by calls to resolve() from beforeAction().
*/
protected $resolved = array();
/**
@mindplay-dk
mindplay-dk / migrator.php
Created June 16, 2012 19:11
Migrate a PHP codebase to use namespaces.
<?php
/**
* Namespace Migration Script
*
* @author Rasmus Schultz <rasmus@mindplay.dk>
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*
* This script will scan through an entire PHP codebase and rewrite the
* scripts, adding a namespace clause based on the directory structure,
@mindplay-dk
mindplay-dk / UserProfile.php
Created July 17, 2012 14:24
Strongly-typed views with PHP
<?php
/**
* Example: strongly typed view with PHP.
*
* Rather than traditional "flat views", why not put your views
* in a dedicated namespace and declare them as classes?
*
* Some advantages:
*
@mindplay-dk
mindplay-dk / configuration.php
Created July 26, 2012 16:47
strongly-typed configuration-container
<?php
/**
* Configuration Container
* =======================
*
* @author Rasmus Schultz <rasmus@mindplay.dk>
*
* This is an experimental configuration-container for PHP 5.3, attempting to
* solve a number of problems with configuration in general.
@mindplay-dk
mindplay-dk / jquery.column.js
Created July 30, 2012 20:31
jQuery: find all cells (td/th) in a column of a table
/**
* Find all cells (td/th) in the column of the current cell.
* (excluding rows with cells that span multiple columns.)
*/
(function($) {
$.fn.column = function() {
return $(this)
.filter('th, td')
@mindplay-dk
mindplay-dk / reflection-bench.php
Created August 15, 2012 12:40
A benchmark of reflection API performance in PHP
<?php
/**
* Benchmark: Reflection Performance
*
* Conclusion: there is no performance-gain from caching reflection-objects.
*/
define('NUM_TESTS', 10);