Skip to content

Instantly share code, notes, and snippets.

View thedustin's full-sized avatar

Dustin Breuer thedustin

View GitHub Profile
@thedustin
thedustin / yiq-color-contrast.php
Last active August 29, 2015 14:13
Calculate the textcolor (Black or White) by background-color (YIQ-Contrast) [http://24ways.org/2010/calculating-color-contrast/]
<?php
$fYIQ = (($iRed * 299) + ($iGreen * 587) + ($iBlue * 114)) / 1000;
if($fYIQ >= 128){
echo 'Black textcolor.';
} else {
echo 'White textcolor.';
}
@thedustin
thedustin / sort-by-own-order.php
Created July 13, 2015 13:39
A sort function which use a custom order
<?php
static $aTypesOrder = array(
'PDF', 'DOC', 'BMP', 'PSD', 'AI',
);
/**
* @param array $aAssetA
* @param array $aAssetB
*
@thedustin
thedustin / ArrayUtils.php
Created July 15, 2015 08:05
An ArrayUtil class for php
<?php
/**
* ArrayUtils
*
* @author Dustin Breuer <developer@thedust.in>
* @license 2015 MIT
*/
namespace TheDusti\Util;
@thedustin
thedustin / simple-animation.js
Created July 19, 2015 17:51
Animate an simple value really easy
/**
*
* @param {Number} iFrom
* @param {Number} iTo
* @param {Number} iDuration
* @param {Function} cSetterFunction
*/
function simpleAnimatedValue(iFrom, iTo, iDuration, cSetterFunction){
var iDiff = (iTo - iFrom),
iAnimationEnd = (Date.now() + iDuration),
@thedustin
thedustin / curl-multi-exec.php
Last active September 8, 2015 12:09
curl multi exec with content
<?php
// $arrUrls = ["http://...", ...]
$arrCurls = array();
$resMultiCurl = curl_multi_init();
$arrReturn = array();
foreach ( $arrUrls as $strUrl ) {
$resCurl = curl_init();
@thedustin
thedustin / mirror.php
Created October 12, 2015 07:19
Simple request mirror script, so you can easily debug what e.g. an api request contains
<?php
$aHeaders = getAllHeaders();
header('X-Mirror-Http-Method: ' . $_SERVER['REQUEST_METHOD']);
foreach($aHeaders as $sName => $sValue){
header(sprintf('X-Mirror-%s: %s', $sName, $sValue));
}
echo file_get_contents('php://input');
@thedustin
thedustin / polyfill.js
Created December 3, 2015 15:50
Extended console.log()
/**
* Avoid `console` errors in browsers that lack a console.
* @link https://github.com/h5bp/html5-boilerplate/blob/master/src/js/plugins.js
*/
(function() {
var method,
noop = function() {},
methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group',
@thedustin
thedustin / mini-autogrow.js
Created December 8, 2015 10:14
A simple and tiny autogrow script
jQuery(function($){
var maxHeight = Math.round( $( window ).height() * 0.6 );
$('#TextArea').on( 'keyup input paste cut', function() {
$(this)
.css( 'height', '' )
.css( 'height', Math.min( this.scrollHeight, maxHeight ) );
} );
});
@thedustin
thedustin / parse-url.js
Created June 22, 2016 09:50
Quick parse a url in javascript with an anchor element
var anchor = document.createElement("a"),
props = ["href", "protocol", "host", "hostname", "port", "pathname", "search", "hash", "username", "password", "origin"],
result = {}, i, j;
anchor.setAttribute("href", "//user:pass@hostname:8080/pathname/?q=search#hash");
for(i = 0, j = props.length; i < j; i++){
result[props[i]] = anchor[props[i]];
}
@thedustin
thedustin / FileSystemStreamWrapper.php
Created August 30, 2016 13:42
A php stream wrapper for the file system
<?php
/**
* FileSystemStreamWrapper
*
* @author Dustin Breuer <gist@thedust.in>
*/
/**
* Class FileSystemStreamWrapper
*