Skip to content

Instantly share code, notes, and snippets.

@odracci
odracci / gist:458452
Created June 30, 2010 09:19 — forked from cirpo/gist:457991
Fix symfony td_actions
#sf_admin_container ul.sf_admin_td_actions li a {
padding-left:20px;
padding-top: 3px;
}
<?php
$number = '0123456789394872394';
$match = array();
preg_match_all('/(.{1,3})/', $number, $match);
$res = implode(' ', $match[0]);
var_dump($res);
?>
@odracci
odracci / UploadImageInSymfonyForm.php
Created August 5, 2010 09:06
sfWidgetFormInputFileEditable
<?php
$this->widgetSchema['image'] = new sfWidgetFormInputFileEditable(array(
'label' => 'Image',
'file_src' => sprintf('/uploads/%s/%s', sfConfig::get('app_upload_image_path', 'images') ,$this->getObject()->getImage()),
'is_image' => true,
'edit_mode' => !$this->isNew(),
'template' => '<div>%file%<br />%input%<br />%delete% %delete_label%</div>',
));
$this->validatorSchema['image_delete'] = new sfValidatorBoolean();
<?php
/**
* Override processUploadedFile in ObjectForm
* Require sfImageTransformPlugin
* @see lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine::processUploadedFile()
*/
protected function processUploadedFile($field, $filename = null, $values = null) {
$filename = parent::processUploadedFile($field, $filename, $values);
if ($filename != "" && $values[$field]) {
$method = 'scale';
<?php
/**
* @Route("/demo/secured")
*/
class SecuredController extends Controller
{
/**
* @Route("/login", name="_demo_login")
* @Template()
*/
#!/bin/sh
# Pre-commit hook passing files through jslint
#
# This ensures that all js, html and json files are valid and conform
# to expectations.
ROOT_DIR=$(git rev-parse --show-toplevel)
JSLINT="${ROOT_DIR}/node_modules/.bin/jslint --indent 4 --white true"
@odracci
odracci / .bashrc
Created March 18, 2012 13:49 — forked from trumbitta/.bash_aliases
My version with tweaks and inspiration from holman/dotfiles
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_unpushed {
local unpushed=`/usr/bin/git cherry -v origin/$(get_git_branch) 2> /dev/null`
[[ "$unpushed" != "" ]] && echo "$(tput setaf 1) ++> $(tput sgr0)"
}
@odracci
odracci / Vagrantfile
Created June 22, 2012 07:31
vagrant and puppet files for making a mongodb dev environment
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
config.vm.network :hostonly, "10.0.0.2"
config.vm.forward_port 27017, 27017
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "."
puppet.manifest_file = "puppet.pp"
end
end
@odracci
odracci / Puppet config snippet to define a Launchpad PPA
Created June 22, 2012 07:31 — forked from blueyed/Puppet config snippet to define a Launchpad PPA
This defines pparepo which allows to add a PPA (Personal Package Archive) repository from Launchpad to a client. It uses apt::key, which I have taken (and maybe modified) from http://projects.puppetlabs.com/projects/1/wiki/Apt_Keys_Patterns (blog post at
# Setup a PPA repo, where the name is "user/ppaname", e.g. "blueyed/ppa" ("ppa" being the default)
define pparepo($apt_key = "", $dist = $ppa_default_name, $supported = ["lucid", "hardy"], $ensure = present, $keyserver = "keyserver.ubuntu.com") {
$name_for_file = regsubst($name, '/', '-', 'G')
$file = "/etc/apt/sources.list.d/pparepo-${name_for_file}.list"
file { "$file": }
case $ensure {
present: {
if ($dist) and ($dist in $supported) {
File["$file"] {
@odracci
odracci / DemoController.php
Created July 1, 2012 23:32 — forked from havvg/DemoController.php
Impersonating a User in Symfony2
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Role\SwitchUserRole;