Skip to content

Instantly share code, notes, and snippets.

View gunderwonder's full-sized avatar

Øystein Riiser Gundersen gunderwonder

View GitHub Profile
@gunderwonder
gunderwonder / normalize_flash_video_url.php
Created August 9, 2010 10:36
Normalize Youtube/Video videos to SWF paths
<?php
function normalize_flash_video_url($url) {
$url = trim($url);
if (preg_match('{(^http://www\.)?youtube\.com}', $url)) {
if (preg_match('{watch\?v=([^&]+)}', $url, $matches)) {
if (isset($matches[1]))
return "http://www.youtube.com/v/{$matches[1]}";
} else if (preg_match('{/v/(\w+)}', $url, $matches))
return "http://www.youtube.com/v/{$matches[1]}";
@gunderwonder
gunderwonder / xbase.php
Created August 22, 2010 11:42
Base-encoding/decoding with arbitrary radix.
<?php
/**
* Base-encoding/decoding with arbitrary radix.
* @see http://stackoverflow.com/questions/1119722/base-62-conversion-in-python#answer-1119769
*/
define('BASE_64_ALPHABET', '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
function xbase_encode($number, $alphabet = BASE_64_ALPHABET) {
if ($number == 0)
return $alphabet[0];
@gunderwonder
gunderwonder / html5_boilerplate.html
Created August 26, 2010 10:59
HTML5 boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML5 boilerplate with IE conditional comments magic</title>
</head>
<!--[if lt IE 7]> <body class="ie ie6"> <![endif]-->
<!--[if IE 7]> <body class="ie ie7"> <![endif]-->
<!--[if IE 8]> <body class="ie ie8"> <![endif]-->
<!--[if IE 9]> <body class="ie ie9"> <![endif]-->
<!--[if gt IE 9]> <body> <![endif]-->
@gunderwonder
gunderwonder / wiki_word_form.php
Created September 15, 2010 18:32
Complete Cobweb form example
<?php
// the form...
class WikiWordForm extends Form {
private $word = NULL;
// declarative field configuration; this is where you define the form...
public function configure() {
$this->title = new TextField();
@gunderwonder
gunderwonder / inheritance.js
Created September 21, 2011 17:06
A simple JavaScript inheritance system
/*
* A simple JavaScript inheritance system
* (Like Prototype's `Class.create()`, only without the crazy method wrapping and function decompilation)
*
* Usage
* var A = Class.create({
* // `initialize` is the constructor
* initialize : function(x, y) {
* this.x = x;
* this.y = y;
@gunderwonder
gunderwonder / wp_post_iterator.php
Created November 6, 2011 17:28
WordPress post iterator
<?php
/* Iterator for arrays of WordPress posts or `WP_Query`.
*
* Simplifies "the loop" by automatically handling the `$post` global for each iteration
* (calling `the_post()`, `setup_postdata()` etc.) and makes sure to reset the global state when the loop has finished.
*
* Usage:
* Loop over ten last posts:
* <?php foreach (new WPQueryIterator(array('post_type' => 'post', 'posts_per_page' => 10)) as $i => $p): ?>
* <?php the_title(); ?>
@gunderwonder
gunderwonder / link-devonthink-bear-things.applescript
Created May 6, 2018 17:19
Creates a named DEVONthink group, a Bear note and Things project, linked together