Skip to content

Instantly share code, notes, and snippets.

View tvlooy's full-sized avatar
🐧
<(o)

Tom Van Looy tvlooy

🐧
<(o)
View GitHub Profile
@tvlooy
tvlooy / SomeController.php
Last active December 14, 2015 06:19
log memory usage of a Symfony2 action
<?php
class SomeController extends Controller
{
public function someAction()
{
$dispatcher = $this->get('event_dispatcher');
$dispatcher->addListener('kernel.response', function (\Symfony\Component\EventDispatcher\Event $event) {
file_put_contents(
'/tmp/memory_logger.txt',
@tvlooy
tvlooy / ocp.php
Created April 9, 2013 09:30 — forked from ck-on/ocp.php
<?php
/*
OCP - Opcache Control Panel (aka Zend Optimizer+ Control Panel for PHP)
Author: _ck_, GK, stasilok
Version: 0.1.3
Free for any kind of use or modification, I am not responsible for anything, please share your improvements
* revision history
0.1.3 2013-03-30 show host and php version, can bookmark with hashtag ie. #statistics - needs new layout asap
0.1.2 2013-03-25 show optimization levels, number formatting, support for start_time in 7.0.2
@tvlooy
tvlooy / changekey
Created July 15, 2013 13:38
Change Win7 license key
C:\>slmgr.vbs -ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
C:\>slmgr.vbs -ato
@tvlooy
tvlooy / gist:6172548
Last active December 20, 2015 17:59
PS1 prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
PS1='${debian_chroot:+($debian_chroot)}[\[\033[00;31m\]\u@\h\[\033[00m\] \[\033[00;34m\]\w\[\033[00m\]\[\033[00;31m\]$(parse_git_branch)\[\033[00m\]]\n\$ '
@tvlooy
tvlooy / gist:7006707
Created October 16, 2013 12:09
User cache Symfony2
In config.yml:
services:
cache:
class: Doctrine\Common\Cache\ApcCache
In code:
if ($this->get('cache')->contains('menu')) {
$menu = unserialize($this->get('cache')->fetch('menu'));
@tvlooy
tvlooy / removeacme.sh
Last active December 25, 2015 17:08
Remove AcmeDemoBundle
#!/bin/bash
# Remove bundle files
rm -rf src/Acme
sed -i '/AcmeDemoBundle/,+2 d' app/config/routing_dev.yml
sed -i '/AcmeDemoBundle/d' app/AppKernel.php
rm -rf web/bundles/acmedemo
# Remove the base template
rm -rf app/Resources/
@tvlooy
tvlooy / find_longest.sh
Created October 28, 2013 14:17
Find the longest class name
find symfony/ -name '*.php' -exec grep -iR '^class ' {} \; | cut -d' ' -f2 | awk '{ print length, $0 }' | sort -n
@tvlooy
tvlooy / poc.sh
Created November 6, 2013 12:07
wkhtmltopdf pagination proof of concept
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
tar xf wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
php -S localhost:9090 &
PHP_PID=$!
./wkhtmltopdf-amd64 --footer-right "[page]/[topage]" http://localhost:9090/ poc.pdf
kill $PHP_PID
rm wkhtmltopdf*
@tvlooy
tvlooy / modulelist.php
Last active December 27, 2015 18:29
Get list of installed Magento modules
<?php
require 'app/Mage.php';
Mage::app();
$modules = Mage::getConfig()->getNode('modules')->children();
foreach ($modules as $moduleName => $moduleSettings) {
echo '[' . ($moduleSettings->is('active') ? 'active' : 'disabled') . "]\t";
echo $moduleName;
@tvlooy
tvlooy / wkhtmltopdf.php
Last active January 2, 2016 14:19
wkhtmltopdf with php test
<?php
// Tips:
// prepend with xvfb-run to wrap call in virtual x-server (if wkhtmltopdf version is old and no X is found)
// -O landscape (to turn page 90 deg)
// --post requestType genpdf (to post params, is repeatable)
// --footer-right "[page]/[topage]"
// read man whktmltopdf
$command = '/usr/local/bin/wkhtmltopdf -q http://' . $_SERVER["SERVER_NAME"];