Skip to content

Instantly share code, notes, and snippets.

View devster's full-sized avatar

Jeremy Perret devster

View GitHub Profile
@devster
devster / SiteMapXML.php
Created March 21, 2012 17:14
Helper sitemap xml
<?php
/**
* SiteMapXML
*
* A simple helper to make simple sitemap.xml with images
*
* Usage:
* // without images
* $sitemap = new SiteMapXML();
@devster
devster / SiteMapIndexXML.php
Created March 21, 2012 17:21
Helper sitemap index xml
<?php
/**
* SiteMapIndexXML
*
* A simple helper to make simple sitemap.xml of index
*
* Usage:
* $sitemap = new SiteMapIndexXML();
* $sitemap->addSiteMap('http://example.org/sitemap-products.xml');
@devster
devster / MyForm.php
Created March 27, 2012 10:19
Basic Form robot protection sf1
<?php
class MyForm extends sfForm
{
protected $robotProtectionFieldName = "_honeypot_robot";
public function __construct($defaults = array(), $options = array(), $CSRFSecret = null)
{
parent::__construct($defaults, $options, $CSRFSecret);
@devster
devster / npDriverJpegoptim.class.php
Created April 10, 2012 15:48
Jpegoptim driver for npAssetsOptimizerPlugin for sf1
<?php
class npDriverJpegoptim extends npDriverBase
{
public function doProcessFile($file, $replace = false)
{
if (false === $replace)
{
throw new LogicException('JPEG optimization only support file replacement atm');
}
@devster
devster / npDriverLessmin.class.php
Created April 10, 2012 15:49
Lessmin driver for npAssetsOptimizerPlugin for sf1
<?php
require_once sfConfig::get('sf_lib_dir').'/vendor/lessphp/lessc.inc.php';
class npDriverLessmin extends npDriverBase
{
public function doProcessFile($file, $replace = false)
{
$lessc = new lessc($file);
$optimizedContent = cssmin::minify($lessc->parse());
@devster
devster / deploy.rb
Created November 7, 2013 17:50
Capistrano/Capifony: ask tag or revision hash before a deploy.
set :branch, "master"
task :set_branch_revision do
default_tag = `git tag`.split("\n").last
tag = Capistrano::CLI.ui.ask "Tag to deploy (make sure to push the tag first): [#{default_tag}] "
if tag.empty?
default_revision = `git log origin/#{branch} -n 1 --pretty=format:%H`
default_short_revision = default_revision[0, 10]
revision = Capistrano::CLI.ui.ask "Revision to deploy (on branch #{branch}): [#{default_short_revision}] "
@devster
devster / gist:7675162
Last active December 29, 2015 13:09
Detect Windows OS with ruby
require 'rbconfig'
isWindows = /mswin|win|mingw|cygwin/i === RbConfig::CONFIG['host_os']
@devster
devster / gist:7710264
Last active December 29, 2015 18:19
Elegant way to create an API URL
<?php
/**
* Elegant way to create an API URL
*
* Usage:
* $this->getResourceUrl('/product/%s/id-%d', 'edit', 13);
* // will produce http://domain.com/product/edit/id-13
*
* // A resource can be an array to embed this method in an other method
@devster
devster / gist:7783986
Created December 4, 2013 08:17
Transform a camel case string to an underscore string
<?php
/**
* Transform a camel case string to an underscore string
*
* @param string $str
* @return string
*/
public static function camelCaseToUnderscore($str)
{
@devster
devster / gist:7888116
Last active December 30, 2015 21:29
Trim all blank chars from a string
<?php
$str = " Hello world
";
echo trim($str, " \t\n\r\0\x0B"); // will echo "Hello World"