Skip to content

Instantly share code, notes, and snippets.

@dlueth
dlueth / getFiles.php
Created June 27, 2013 21:36
Fetch files matching an optional regex-pattern recursively from any given directory
getFiles($directory, $recursive = false, $pattern = NULL, $absolute = false) {
$return = array();
$iterator = ($recursive === false) ? new \FilesystemIterator($directory, \FilesystemIterator::SKIP_DOTS) : new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory), \RecursiveIteratorIterator::SELF_FIRST);
$iterator = ($pattern !== NULL) ? new \RegexIterator($iterator, '/' . $pattern . '/i') : $iterator;
$directory = preg_quote($directory . '/', '/');
foreach($iterator as $path) {
if($path->isFile() === true) {
$return[] = ($absolute !== false) ? $path->getPathname() : preg_replace('/^' . $directory . '/', '', $path->getPathname());
}
@dlueth
dlueth / .htaccess
Created July 18, 2013 08:06
Assets for Qoopido.js shrinkimage showing how to convert images to .shrunk files via PHP and how to include it in your .htaccess
AddType application/json .shrunk
AddType application/javascript .shrunk.jsonp
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+.q(?:[0-9]+).shrunk)$ shrinkimage.php?file=$1 [QSA,L]
RewriteRule ^(.+.q(?:[0-9]+).shrunk.jsonp)$ shrinkimage.php?file=$1&jsonp=1 [QSA,L]
</IfModule>
<Ifmodule mod_deflate.c>
@dlueth
dlueth / macports.sh
Last active November 30, 2015 08:04
Macports install, remove and update script
#!/bin/bash
if [ ! $(whoami) = 'root' ]; then
echo "This script should be run as root." > /dev/stderr
exit 1
fi
if [ ! -f "/opt/local/bin/port" ] ; then
echo "This script requires macports to be installed"
exit 1
@dlueth
dlueth / mdnsresponder.sh
Last active April 16, 2022 03:02
Replace Yosemite's DNS discoveryd with the former mDNSResponder.
#!/bin/bash
if [ ! $(whoami) = 'root' ]; then
echo "This script should be run as root." > /dev/stderr
exit 1
fi
spinner()
{
local pid=$!
@dlueth
dlueth / demand.module.extended.js
Last active January 2, 2018 15:23
Qoopido.demand: Extended module with configuration settings - see https://github.com/dlueth/qoopido.demand for further details
(function() {
'use strict';
function definition(demand, provide, path, isObject) {
var settings;
function onPostConfigure(options) {
settings = isObject(options) ? options : {};
}
@dlueth
dlueth / slug.php
Created December 9, 2016 13:39
Sluggify in PHP
<?php
class Modify {
private static $instance = NULL;
protected static $mbstring = NULL;
protected static $iconv = NULL;
protected static $characterset = NULL;
/*
protected static $diacritics = array(
'À'=>'A','Á'=>'A','Â'=>'A','Ã'=>'A','Å'=>'A','Ä'=>'A','Æ'=>'AE',
@dlueth
dlueth / error.js
Last active March 27, 2018 15:48
NodeJS: Custom errors
'use strict';
class CustomError extends Error {
constructor(...args) {
super(...args);
Object.defineProperty(this, 'name', { value: this.constructor.name });
// This is for Node only...
Error.captureStackTrace(this, this.constructor);
@dlueth
dlueth / async.class.js
Created February 28, 2018 08:54
JavaScript: Async constructor
class MyFirstClass {
constructor() {
return new Promise(async (resolve, reject) => {
try {
resolve(this);
} catch(error) {
reject(error);
}
});
}
@dlueth
dlueth / child.js
Created March 22, 2018 08:26
[React: parent/child reference] #react
class Child extends Component {
static defaultProps = {
onRef: undefined
}
componentDidMount() {
this.props.onRef(this);
}
componentWillUnmount() {
@dlueth
dlueth / serviceworker.js
Last active June 20, 2018 15:51
JavaScript: Immediately active Service Worker #JavaScript
self.addEventListener('install', function(event) {
return self.skipWaiting();
});
self.addEventListener('activate', function(event) {
return event.waitUntil(self.clients.claim());
});