Skip to content

Instantly share code, notes, and snippets.

View lavoiesl's full-sized avatar

Sébastien Lavoie lavoiesl

View GitHub Profile
@lavoiesl
lavoiesl / auto.conf
Created July 19, 2012 20:41
ServerAlias and VirtualDocumentRoot
<VirtualHost *:80>
ServerAdmin www@localhost
ServerName auto.local
ServerAlias *.local
ServerAlias *.*.local
UseCanonicalName Off
VirtualDocumentRoot /var/www/%-2/htdocs
ErrorLog "/var/log/apache2/auto-error_log"
@lavoiesl
lavoiesl / brew-orphans.sh
Created July 26, 2012 09:47
List all installed brew formulas not used by other installed formulas.
#!/bin/bash
# List all installed brew formulas not used by other installed formulas.
# Useful for cleanup
for f in `brew list`; do
[[ -z "$(brew uses --installed $f)" ]] && echo $f
done
@lavoiesl
lavoiesl / CodeGenerator.php
Created August 1, 2012 04:24
Generate a random string of non-ambiguous numbers and letters.
<?php
class CodeGenerator
{
private static $alphabet = '23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
private static $max_offset = 55;
/**
* Generate a random character of non-ambiguous number or letter.
* @return string the character
@lavoiesl
lavoiesl / bookmarklet-dev.js
Created August 21, 2012 00:03
Download UdeM schedule as iCal
(function(d,s){
var n,b=d.getElementsByTagName(s)[0];
function l(u){
n=d.createElement(s);
n.src=u;
b.parentNode.insertBefore(n,b);
}
l("//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
l("//gist.github.com/raw/3409527/converter.js");
})(document, "script");
@lavoiesl
lavoiesl / CommentsAcl.php
Created August 21, 2012 04:04
Workaround for circular dependency in Symfony2 services
<?php
namespace Acme\SiteBundle\Listener;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Acme\SiteBundle\Entity\Comment;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
@lavoiesl
lavoiesl / osx-battery-status.sh
Created August 28, 2012 23:06
Display battery status on OSX, including progress bar
#!/bin/bash
# Usage: osx-battery-status.sh [width of progress bar]
# If specified, will use $width characters to display a progress bar, padding with spaces
# Uses half block when needed
ioreg="`ioreg -c AppleSmartBattery`"
current=`echo "$ioreg" | grep CurrentCapacity | grep -oE "[0-9]+"`
max=`echo "$ioreg" | grep MaxCapacity | grep -oE "[0-9]+"`
battery=$(( $current * 100 / $max ))
@lavoiesl
lavoiesl / .tmux.conf
Created August 28, 2012 23:08
Tmux configuration on OSX
# Make it use C-a, similar to screen..
bind-key C-a last-window
bind-key a send-prefix
set -g prefix C-a
# Reload key
bind r source-file ~/.tmux.conf
set -g history-limit 1000
@lavoiesl
lavoiesl / DoctrineEntityCompilerPass.php
Created August 29, 2012 17:51
DoctrineEntityListener
<?php
namespace Acme\CommonBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
class DoctrineEntityCompilerPass implements CompilerPassInterface
{
@lavoiesl
lavoiesl / benchmark.php
Created September 4, 2012 00:21
Benchmark of different function calls in PHP
<?php
// Commons
$callable = function() {};
function empty_function() {};
class A {
public static function empty_function() {}
public function empty_method () {}
}
@lavoiesl
lavoiesl / genpasswd.sh
Created September 10, 2012 03:55
Generates a random password using only non-ambiguous alphanumeric characters
#!/bin/bash
# Generates a random password using only non-ambiguous alphanumeric characters
# Usage: genpasswd.sh [length]
length=16
if [[ -n "$1" ]]; then
length="$1"
fi