Skip to content

Instantly share code, notes, and snippets.

View martijngastkemper's full-sized avatar

Martijn Gastkemper martijngastkemper

View GitHub Profile
@martijngastkemper
martijngastkemper / search-version.bash
Created May 30, 2014 10:47
Search a file by version
#!/bin/bash
fromVersion=$1
if [ -d .sql-update ]
then
start=false
for sqlFile in `ls -v .sql-update/*`
do
if [[ $sqlFile == *$fromVersion* ]]
@martijngastkemper
martijngastkemper / EnvStream.php
Last active August 29, 2015 14:02
I was searching for a solution to make key files available in my Heroku app without adding it to the repository. Using a streamwrapper doesn't work, because ssh2 only accepts strings to files without a schema part. But still want to share this very useless class with you. "echo file_get_contents( 'env://ENV_VAR' );" does exactly the same as "get…
<?php
class EnvStream
{
private $var, $position = 0;
function stream_open($path, $mode, $options, &$opened_path)
{
$this->var = parse_url( $path, PHP_URL_HOST );
return true;
@martijngastkemper
martijngastkemper / .bashrc
Created July 3, 2014 22:49
Solves a runtime exception when executing shell command via PHP exec().
# .bashrc
[ -z "$PS1" ] && return
@martijngastkemper
martijngastkemper / cpv-dom.php
Created July 23, 2014 07:49
Read CPV with dom or xpath tests. Conclusion: very very slow
<?php
$start = microtime(true);
error_log( $start );
// if( !apc_exists( 'xml' ))
// {
$xml = simplexml_load_file('cpv_2008.xml');
// apc_add( 'xml', $xml );
// }
@martijngastkemper
martijngastkemper / template.tpl
Last active August 29, 2015 14:04
Check if file exists
{capture name="preview"}{$smarty.const.PATH_TO_FILE}unknown.pdf{/capture}
{if $smarty.capture.preview|is_file}
<embed width="100%" height="100%" name="plugin" src="....." type="application/pdf">
{/if}
@martijngastkemper
martijngastkemper / apc.php
Created September 17, 2014 08:59
See what's going one in your APC cache. It gives a lot of funky results I don't understand, but sometimes it's useful.
<?php
/*
+----------------------------------------------------------------------+
| APC |
+----------------------------------------------------------------------+
| Copyright (c) 2006-2011 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
@martijngastkemper
martijngastkemper / gist:87514efac2e004862c19
Created October 3, 2014 13:37
Update a Git tag and push that to origin.
# Steps
# 1. Remove tag
git tag -d TAGNAME
# 2. Push to origin
git push origin :refs/tags/TAGNAME
# 3. Create tag
git tag TAGNAME
# 4. Push to origin
git push origin
@martijngastkemper
martijngastkemper / gist:1d158066bbfb76fa0267
Last active August 29, 2015 14:07
Run KeePass 2 on Mac OS
brew install wine winetricks
winetricks dotnet20
wget http://keepass.info/download.html (Select KeePass 2 Portable version)
wine KeePass-2.28/KeePass.exe
@martijngastkemper
martijngastkemper / domains-from-email.sql
Created November 3, 2014 16:35
A mysql query to group the domains in your list of e-mail addresses
SELECT
(substr( email, instr( email, '@') + 1)) as domain,
count(*) as total
FROM relations
GROUP BY domain
ORDER BY total DESC;
@martijngastkemper
martijngastkemper / gist:e9bd5ef40cd233727427
Created November 10, 2014 09:41
Get commit hash of a branch or tag
git rev-list master | head -n 1