Skip to content

Instantly share code, notes, and snippets.

View chanakasan's full-sized avatar

Chanaka Abeysinghe chanakasan

View GitHub Profile
<?php
/**
* Return URL-Friendly string slug
* @param string $string
* @return string
*/
function seoUrl($string) {
//Unwanted: {UPPERCASE} ; / ? : @ & = + $ , . ! ~ * ' ( )
$string = strtolower($string);
<?php
/**
* Password hash generator
*
* @static
* @param string $password
* @return string
*/
public static function passwordHash ($password)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
<?php
if (file_exists(__DIR__ . '/' . $_SERVER['REQUEST_URI'])) {
return false; // serve the requested resource as-is.
} else {
include_once 'index.php';
}
guard :shell do
watch(%r{^spec/.+Spec.php}) { |m|
system("clear")
system("bin/phpspec run --no-interaction --format=pretty #{m[0]}")
}
watch(%r{^src/(.+).php}) {
system("clear")
system("bin/phpspec run --no-interaction --format=pretty")
}
# config.yml
fos_rest:
format_listener:
rules:
- { path: ^/, priorities: [ json, xml, html ], fallback_format: ~, prefer_extension: false }
view:
view_response_listener: force
sensio_framework_extra:
view: { annotations: false }
<?php
class EmailTestCase extends PHPUnit_Framework_TestCase {
/**
* @var \Guzzle\Http\Client
*/
private $mailcatcher;
public function setUp()
{
@chanakasan
chanakasan / error.html.twig
Created November 7, 2013 12:17
Symfony2 custom error page, (put in app\Resources\TwigBundle\views\Exception)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page not found!</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
{% block stylesheets %}
@chanakasan
chanakasan / FunctionalTestCase.php
Created November 6, 2013 02:31
Symfony2 FunctionalTestCase for extending integration test classes
<?php
namespace Panda86\AppBundle\Tests;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\StringInput;
class FunctionalTestCase extends WebTestCase
@chanakasan
chanakasan / salt-generate.php
Last active December 27, 2015 11:39
php snippet for generating a random salt
<?php
$salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);