Skip to content

Instantly share code, notes, and snippets.

View mertenvg's full-sized avatar
🤖
when in doubt, just use Go

Merten van Gerven mertenvg

🤖
when in doubt, just use Go
View GitHub Profile
@mertenvg
mertenvg / gist:3814370
Created October 1, 2012 20:58
Nohup with command sequence
# Create a test.pid file containing the pid of the sh process.
# Run the main command. Example: Sleep for 15 seconds.
# Then remove the pid file once the main command process is ended or killed.
$ nohup sh -c "sleep 15; rm test.pid" >/dev/null 2>&1 & echo $! > test.pid
@mertenvg
mertenvg / index.html
Created October 28, 2012 20:44
A CodePen by Merten van Gerven. CSS3 Flexible Box Layout
<html>
<head>
<title>CSS3 Flexible Box Layout</title>
</head>
<body>
<div id="container1">
<div id="box1"></div>
<div id="box2"></div>
</div>
<div id="container2">
@mertenvg
mertenvg / optval.function.php
Created December 14, 2012 19:48
Extract an option from the results of getopt specifying the keys in order of preference.
/**
* Extract an option from the results of getopt specifying the
* keys in order of preference.
*
* @param array $options Result from getopt('ab:c::', array('add', 'bacon', 'create'))
* @param string $key1 First key to look for e.g. 'add'
* @param string $key2 Second key to look for e.g. 'a'
* @param string $keyn Other possible aliases...
* @return mixed The value from options array or null otherwise
*/
@mertenvg
mertenvg / bool.function.php
Created December 14, 2012 19:49
Conert to boolean by using normal PHP falsey equivalencies with the addition of string 'false' which PHP usually considers truthy.
/**
* Conert to boolean by using normal PHP falsey equivalencies with
* the addition of string 'false' which PHP usually considers truthy.
*
* @param mixed $val Value to convert to boolean
* @return boolean Boolean equivalent
*/
function bool($val)
{
if (
@mertenvg
mertenvg / extractFullClassNameFromFile.function.php
Created December 14, 2012 19:54
Extract a fully qualfied (namespaced) classname from a php file. This function assumes PSR-0 compliance.
/**
* Extract a fully qualfied (namespaced) classname from a php file.
* This function assumes PSR-0 compliance.
*
* @param string $filePath Path to the php file.
* @return string|false The resulting classname
*/
function extractFullClassNameFromFile($filePath)
{
if (!file_exists($filePath)) {
@mertenvg
mertenvg / project-phpunit-skelgen.php
Created December 14, 2012 20:46
Recursively find PHP files and run phpunit-skelgen to create unit test skeleton files. Files must use the .php extension and be PSR-0 compliant, contain a namespace and class name. Files ending in 'Interface.php' are ignored.
#!/usr/bin/env php
<?php
$help = <<<'HELP'
EXAMPLES
./project-phpunit-skelgen.php -s <dir> -o <dir> -b <file>
DESCRIPTION
Recursively find PHP files and run phpunit-skelgen to create unit test skeleton files.
@mertenvg
mertenvg / .htaccess
Created December 20, 2012 14:10 — forked from anonymous/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /passgen/index.php [L,QSA]
</IfModule>
function select_text(element) {
var start = 0;
var end = element.value.length;
if (element.createTextRange) {
var selRange = element.createTextRange();
selRange.collapse(true);
selRange.moveStart('character', start);
selRange.moveEnd('character', end - start);
selRange.select();
@mertenvg
mertenvg / select_contents.function.js
Created January 23, 2013 11:18
Set the selection to the contents of the specified DOM element.
function select_contents(element) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
@mertenvg
mertenvg / iris.jquery.js
Last active December 11, 2015 15:18
Expand and collapse a container vertically on mouseover and mouseout. usage: $.iris($iconCtnr, 40, $iconCtnr.height(), '.selected');
$.iris = function (container, minHeight, maxHeight, keepInSightSelector, callback) {
var self = this;
var timeout = null;
var $container = $(container);
function handleKeepInSight () {
if (!keepInSightSelector) {
return;
}