Skip to content

Instantly share code, notes, and snippets.

View martijngastkemper's full-sized avatar

Martijn Gastkemper martijngastkemper

View GitHub Profile
@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 / 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 / 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 / .bashrc
Created July 3, 2014 22:49
Solves a runtime exception when executing shell command via PHP exec().
# .bashrc
[ -z "$PS1" ] && return
@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 / 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 / zabbix.php
Last active August 29, 2015 14:01
Zabbix API uitproberen
<?php
// load ZabbixApi (http://zabbixapi.confirm.ch/)
require 'ZabbixApiAbstract.class.php';
require 'ZabbixApi.class.php';
try {
// connect to Zabbix API
$api = new ZabbixApi("...");
@martijngastkemper
martijngastkemper / dump-triggers
Created April 22, 2014 08:51
Dump MySQL triggers
mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt <database> > outputfile.sql
@martijngastkemper
martijngastkemper / ajax.php
Last active August 29, 2015 13:58
Fixes WordPress plugin "File Un-Attach" when WordPress is installed in "different-dir"
# Change
require_once '../../../wp-load.php';
# into
require_once '../../../different-dir/wp-load.php';
@martijngastkemper
martijngastkemper / wp-tell-a-friend-popup-form.php
Last active August 29, 2015 13:58
Make the [Tell a friend] (http://www.gopiplus.com/work/2012/05/21/wordpress-plugin-wp-tell-a-friend-popup-form) plugin for WordPress work with an changed WordPress source directory. Useful for WordPress in Git repositories
# Not working
wp_enqueue_style( 'tell-a-friend', get_option('siteurl').'/wp-content/plugins/wp-tell-a-friend-popup-form/tell-a-friend.css');
wp_enqueue_script( 'tell-a-friend-form', get_option('siteurl').'/wp-content/plugins/wp-tell-a-friend-popup-form/tell-a-friend-form.js');
wp_enqueue_script( 'tell-a-friend-popup', get_option('siteurl').'/wp-content/plugins/wp-tell-a-friend-popup-form/tell-a-friend-popup.js');
# Working
wp_enqueue_style( 'tell-a-friend', plugins_url( 'tell-a-friend.css', __FILE__ ) );
wp_enqueue_script( 'tell-a-friend-form', plugins_url( 'tell-a-friend-form.js', __FILE__ ) );
wp_enqueue_script( 'tell-a-friend-popup', plugins_url( 'tell-a-friend-popup.js', __FILE__ ) );