Skip to content

Instantly share code, notes, and snippets.

View Langmans's full-sized avatar

Langmans Langmans

  • Netherlands
  • 13:13 (UTC +02:00)
View GitHub Profile
@Langmans
Langmans / deprecateMethod.php
Created April 28, 2016 09:45
deprecateMethod
<?php
// to be used in a class
function deprecateMethod()
{
$traces = debug_backtrace();
array_shift($traces);
$def = array('class' => null, 'type' => null, 'function' => null);
do {
$trace1 = array_shift($traces);
// dump($trace1);
@Langmans
Langmans / InjectorServiceProvider.php
Last active April 28, 2016 12:58
auto inject classes into your silex route using typehinting, inspired by https://gonzalo123.com/2015/10/19/alternative-way-to-inject-providers-in-a-silex-application/. Supports guessing by psuedocamelcase, camelcase and tablecase(underscores), and using a map.
<?php
use Doctrine\Common\Inflector\Inflector;
use Monolog\Logger;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
@Langmans
Langmans / books.sql
Last active April 28, 2016 19:45
lessql auto convention
-- Adminer 4.2.2 MySQL dump
SET NAMES utf8;
SET time_zone = '+00:00';
SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS `author`;
CREATE TABLE `author` (
`id` tinyint(4) NOT NULL AUTO_INCREMENT,
<?php
header('Content-Type: text/csv');
header(sprintf('Content-Disposition:attachment; filename="data_%s_%s.csv"', date(DATE_ISO8601), str_replace('www.', '', $_SERVER['HTTP_HOST'])));
$fh = fopen('php://output', 'w');
$sep = ',';
$enc = '"';
// excel needs sep to indicate what the seperator is.
fputcsv($fh, array('sep=', ''), $sep, $enc);
$first = true;
@Langmans
Langmans / MyDb.php
Last active May 9, 2016 14:22
lazy singleton
<?php
class MyDb extends PDO {
use LazySingleton;
}
@Langmans
Langmans / video-wrapper.less
Created May 13, 2016 12:54
resizes whatever in a div based on child / parent aspect ratios. IE9+, ff19+, chrome20+, safari6+,opera18, android 4.4, blackberry10,
.video-wrapper {
width:100vw;
height:100vh;
position:relative;
video {
position: absolute;
top:0;
right:0;
bottom:0;
@Langmans
Langmans / app.php
Created May 17, 2016 13:41
twig: readable exception stacktrace
<?php
try {
// render some code with twig_error_runtime
} catch (\Twig_Error_Runtime $e) {
$repl = array(realpath(dirname($_SERVER['SCRIPT_FILENAME'])) => '~');
foreach ($e->getTrace() as $trace) {
if (!isset($trace['class'])) {
continue;
}
<?php
// write above part yourself!
ob_start();
$ch = curl_init('http://api.resmush.it/ws.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('files' => '@' . $cache_path));
@Langmans
Langmans / cleancache.php
Created June 10, 2016 10:44
clean Doctrines FilesystemCache files (cronjob)
<?php
require 'vendor/autoload.php';
use Doctrine\Common\Cache\FilesystemCache;
$dirs = array('_storage');
while ($dir = array_pop($dirs)) {
if ($cache_files = glob($dir . '/*' . FilesystemCache::EXTENSION)) {
foreach ($cache_files as $cache_file) {
$delete = false;
if ($fh = fopen($cache_file, 'r')) {