Skip to content

Instantly share code, notes, and snippets.

View nicholasruunu's full-sized avatar

Nicholas Ruunu nicholasruunu

View GitHub Profile
if ( ! function_exists('dd'))
{
/**
* Dump the passed variables and end the script.
*
* @param mixed
* @return void
*/
function dd()
{
// Immutable class
class Person {
private $name;
public function __construct(string $name) {
$this->name = new Name($name);
}
public function rename(string $name) {
$this->name->rename($name);
final class DatabaseName implements Name {
private $db;
private $table;
public function __construct(Database $db, string $table) {
$this->db = $db;
$this->table = $table;
}
public function rename($name) {
<?php
namespace Memory\PlayingField;
use Memory\PlayingField;
final class IncompletePlayingField
{
private $cards = array();
private $numberOfCards = 0;
final class User
{
private $password;
public function changePassword($string)
{
$this->password = new Password($string);
}
}
@nicholasruunu
nicholasruunu / DomainEventProxy.php
Last active August 29, 2015 14:26
DomainEventProxy trait exmple
<?php
trait DomainEventProxy
{
private $eventMethodMapping = [];
private function callMappedMethod(DomainEvent $event, ...$arguments)
{
$method = $this->resolveMethod($event);
$this->$method($event, ...$arguments);
@nicholasruunu
nicholasruunu / message.php
Created October 17, 2011 14:45
Flash message error handler
<?php
/**
* Message + Flash Message class
*
* Usage: $this->message->success('Your thing was successful', (bool) $is_flash, (string) $group);
* $this->message->error('There was an error');
*
* @author Nicholas Ruunu
*/
@nicholasruunu
nicholasruunu / jquery_template.js
Created November 2, 2011 12:12
jQuery class template
$(function() {
var MyClass = function() {
var $this = $(this);
var $login_form = $('#login_form');
// Constructor (will always run when loaded)
(function() {
// Submit login_form
@nicholasruunu
nicholasruunu / jpholdr.js
Created November 2, 2011 15:04
jPholdr, Ultra Lightweight Placeholder Plugin for jQuery
/**
* jPholdr
* Ultra Lightweight Placeholder Plugin for jQuery
*
* @author: Nicholas Ruunu
* @email: nicholas@ruu.nu
* @website: http://ruu.nu
*
* Example: $('#form').jPholdr();
*/
@nicholasruunu
nicholasruunu / color-shader.js
Last active December 15, 2015 14:49 — forked from jonathanmarvens/color-shader.js
Made it a little more DRY
/**
* @author Jonathan Barronville
* @example
* var color_001 = colorShader( '000000', 255 );
* // color_001 === 'ffffff';
* var color_002 = colorShader( 'ffffff', -255 );
* // color_002 === '000000';
* @param {String} color_hex
* @param {Number} amount
* @return {String}