Skip to content

Instantly share code, notes, and snippets.

View mbernson's full-sized avatar
👨‍💻
Coding...

Mathijs Bernson mbernson

👨‍💻
Coding...
View GitHub Profile
@mbernson
mbernson / gist:1677390
Created January 25, 2012 17:17
Input plaatje
<!DOCTYPE html>
<style type="text/css">
input[ type=submit ] {
color: transparent;
background: transparent url("http://placekitten.com/128/128") no-repeat fixed;
border: none;
width: 64px;
height: 64px;
document.addEventListener("DOMContentLoaded", function() {
var elms = document.getElementsByClassName( 'foo' );
for( var i = 0; i < elms.length; i++ )
elms[i].addEventListener( "click",function() {
this.focus();
this.select();
});
});
<?php
/**
* Autoloader
*/
// Define some useful constants
if(!defined('DS'))
define('DS', DIRECTORY_SEPARATOR);
if(!defined('PS'))
@mbernson
mbernson / Prul.php
Created May 1, 2012 20:16
Prul - unfinished URL router in PHP
<?php
include_once 'PrulRoute.php';
include_once 'PrulException.php';
class Prul
{
protected static $routes = array();
const GET = 'GET';
const POST = 'POST';
@mbernson
mbernson / Australia.user.js
Created May 3, 2012 13:15
Australia.user.js
// ==UserScript==
// @name Australia
// @include *
// @version 1.0
// ==/UserScript==
(function(d){
var rules = ['transform', '-moz-transform', '-webkit-transform', '-ms-transform', '-o-transform'],
deg = 180, css = '';
for(var i = 0; i < rules.length; i++) {
@mbernson
mbernson / db.sql
Created June 14, 2012 10:30
PDO versus ext/mysql test
CREATE DATABASE `php_mysqltest`;
CREATE TABLE `test` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`test_int` int(11) DEFAULT NULL,
`test_float` float DEFAULT NULL,
`test_string` varchar(40) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
<?php
function car_dump() {
return call_user_func_array('var_dump', func_get_args());
}
$foo = array(
'bar',
'baz',
'quux'
);
@mbernson
mbernson / touch_example.js
Created October 24, 2012 10:19
Javascript touch/swipe example
/*
* In this example, `panelElement` references to some DOM object,
* with the open, close and toggle methods to show/hide it.
*/
// This function opens or closes our panel, according to the swipe coordinates
panelElement.performSwipe = function(swipeStart, swipeEnd) {
// In case of a short swipe, just toggle the panel.
if (Math.abs(start - end) < 16) {
this.toggle();
@mbernson
mbernson / gist:4641901
Created January 26, 2013 11:45
Raspberry Pi bootstrap
# Ask for the administrator password upfront
sudo -v
# Upgrade the system, install X and Alsa stuff
pacman -S \
xorg xorg-server xorg-xinit xorg-server-utils xf86-video-fbdev \
alsa-firmware alsa-lib alsa-plugins alsa-utils \
vim git tmux mpd mpc ncmpc htop
# Enable the sound device
@mbernson
mbernson / gist:4960430
Created February 15, 2013 13:40
Idea for Activerecord callbacks in PHP.
<?php
class Event extends ActiveRecord\Model
{
static private $before_save = 'calculate_seats_available';
private function calculate_seats_available() {
$this->seats_available = $this->seats - $this->seats_taken;
}
}