Skip to content

Instantly share code, notes, and snippets.

View marco-kretz's full-sized avatar

Marco Kretz marco-kretz

View GitHub Profile
@marco-kretz
marco-kretz / FisherYatesShuffle.php
Created November 30, 2018 11:13
Fast FisherYatesShuffle PHP-Implementation
<?php
final class FisherYatesShuffle
{
/**
* Shuffle an input sequence by Fisher-Yates-Shuffle.
*
* @url https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
*
* @param array $input Array to shuffle
@marco-kretz
marco-kretz / get_absolute_width.js
Created July 27, 2018 07:46
Get the absolute width of an element.
const getAbsoluteWidth = (element) => {
const style = window.getComputedStyle(element);
const attrs = ['width', 'padding-left', 'padding-right', 'margin-left', 'margin-right'];
return attrs
.map((k) => parseInt(style.getPropertyValue(k), 10))
.reduce((p, c) => p + c);
};
@marco-kretz
marco-kretz / get_absolute_height.js
Created July 27, 2018 07:45
Get the absolute height of an element.
const getAbsoluteHeight = (element) => {
const style = window.getComputedStyle(element);
const attrs = ['height', 'padding-top', 'padding-bottom', 'margin-top', 'margin-bottom'];
return attrs
.map((k) => parseInt(style.getPropertyValue(k), 10))
.reduce((p, c) => p + c);
};
public function readCSVWithHeaders($csvString, $delimiter = ';')
{
$rows = explode("\n", str_replace("\r", '', $csvString));
$headers = str_getcsv(array_shift($rows), $delimiter);
return array_map(function ($row) use ($headers, $delimiter) {
return array_combine($headers, str_getcsv($row, $delimiter));
}, array_filter($rows, function($row) {
return !empty($row);
}));
@marco-kretz
marco-kretz / get_hostname_from_url.js
Last active July 6, 2017 13:16
JavaScript: Extract hostname from URL
function getUrlHost(url) {
var parser = document.createElement('a');
parser.href = url;
return parser.hostname;
}
@marco-kretz
marco-kretz / require_css.js
Last active July 6, 2017 13:11
Import CSS file dynamically via JavaScript
function requireCSS(url) {
var cssLink = document.createElement("link");
cssLink.href = url;
cssLink.type = "text/css";
cssLink.rel = "stylesheet";
document.getElementsByTagName("head")[0].appendChild(cssLink);
}
@marco-kretz
marco-kretz / ubuntu-php5.6-zts-pthreads
Last active March 25, 2018 23:21
Howto: Install isolated PHP 5.6 ZTS enabled (thread-safe) with pthreads
##############################################################################
# INSTALL isolated PHP 5.6 ZTS (Thread-safe) with pthreads on Ubuntu 14.04 ###
##############################################################################
1) Install necessary bison version
wget http://launchpadlibrarian.net/140087283/libbison-dev_2.7.1.dfsg-1_amd64.deb
wget http://launchpadlibrarian.net/140087282/bison_2.7.1.dfsg-1_amd64.deb
dpkg -i libbison-dev_2.7.1.dfsg-1_amd64.deb
dpkg -i bison_2.7.1.dfsg-1_amd64.deb