Skip to content

Instantly share code, notes, and snippets.

View mbunge's full-sized avatar
💭
tinker, tinker, ponder, ponder

Marco Bunge mbunge

💭
tinker, tinker, ponder, ponder
View GitHub Profile
@mbunge
mbunge / gulpfile.js
Created January 29, 2014 13:52
PHPUnit with latest gulp 3.5.0 +
var gulp = require('gulp');
var sys = require('sys');
var gutil = require('gulp-util');
var exec = require('gulp-exec');
gulp.task('phpunit', function() {
gulp.src('./tests').pipe(
exec('phpunit --bootstrap tests/bootstrap.php -c tests/phpunit.xml tests/', function(error, stdout){
sys.puts(stdout);
return false;
@mbunge
mbunge / numberFormat.js
Last active August 29, 2015 14:16
Formatting numbers in Javascript with correct rounding. Binding as Prototype to number.
//Plain method
var numberFormat = function (number, decPlaces, decSeparator, thouSeparator) {
decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces;
decSeparator = decSeparator == undefined ? "." : decSeparator;
thouSeparator = thouSeparator == undefined ? "," : thouSeparator;
var roundAndReduceDecimals = function (num, length) {
return Math.round(num * Math.pow(10, length)) / Math.pow(10, length);
};
@mbunge
mbunge / Input.php
Last active August 29, 2015 14:16
Simple input class to fetch input data without usage of global vars like $_POST. Get in touch and follow at twitter http://twitter.com/makk_eightbit! Thank you!
<?php
/**
* @author Marco Bunge <marco_bunge@web.de>
* @copyright 2015 Marco Bunge
* Get in touch and follow at twitter http://twitter.com/makk_eightbit! Thank you!
*/
/**
* Class Input
*/
@mbunge
mbunge / domIoC.js
Last active August 29, 2015 14:16
Inversion of control for dom element. Get in touch and follow at twitter http://twitter.com/makk_eightbit! Thank you!
/**
* @author Marco Bunge <marco_bunge@web.de>
* @copyright 2015 Marco Bunge http://marco-bunge.de
* @licence MIT http://opensource.org/licenses/MIT
*
* Get in touch and follow me at twitter http://twitter.com/makk_eightbit! Thank you!
*
* Inversion of control for dom elements.
* Allows you to bind custom logic, plugins, etc. to a dom element.
* The binding is referencing passed data attributes.
@mbunge
mbunge / adjustToAspectRatio.js
Created March 11, 2015 14:35
Adjust element to an aspect ratio based on height or width. Get in touch and follow me at twitter http://twitter.com/makk_eightbit! Thank you!
/**
* @author Marco Bunge <marco_bunge@web.de>
* @copyright 2015 Marco Bunge http://marco-bunge.de
* @licence MIT http://opensource.org/licenses/MIT
*
* Get in touch and follow me at twitter http://twitter.com/makk_eightbit! Thank you!
*
* Adjust element to an aspect ratio based on height or width.
* Default aspect ratio is 16:9 (tv)
* Usage:
@mbunge
mbunge / angula-parsley.js
Created August 19, 2015 15:05
Use Parsley 2.0 with angular 1.4.x. Jquery 1.11.x or 2.x required!
/**
* Created by Marco Bunge on 18.08.2015.
* Inspired by http://ryanalberts.com/797/parsley-validation-with-angularjs/
*/
(function (angular, jq, window, document) {
'use strict';
//var ngParsley = angular.module('parsley', [])
//ngParsley.constant('parsleyConfig', {});
var ngParsleyJs = angular.module('parsley', []);
@mbunge
mbunge / HttpErrorHandler.php
Last active August 29, 2015 14:27
Fire http status 500 with Monolog on log level! Usefull when an error occurs.
<?php
/**
*
* @author Marco Bunge <mjls@web.de>
* @copyright 2015 Marco Bunge
* @license http://opensource.org/licenses/MIT
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
@mbunge
mbunge / gist:2925070
Created June 13, 2012 16:23
Anonymus Function Test
<?php
$stdClass = new stdClass();
$stdClass->value = 'HELLO WOLRD';
//return message defined by $stdClass::value with a context
//use $stdClass as scope
$lambda = function($context) use ($stdClass)
{
$msg = $context . ': ' . $stdClass->value;
return $msg;
@mbunge
mbunge / headermessageConvert.php
Created June 26, 2012 21:31
Display a converted raw http message
<?php
/**
* @author Marco Bunge
* @copyright 2012 Marco Bunge <efika@rubymatrix.de>
*/
$string = 'HTTP/1.1 200 OK
Server: Apache/1.3.29 (Unix) PHP/4.3.4
Content-Length: (Größe von infotext.html in Byte)
Content-Language: de (nach RFC 3282 sowie RFC 1766)
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.