Skip to content

Instantly share code, notes, and snippets.

@zyphlar
zyphlar / controller_test.php
Created September 10, 2014 22:49
phpunit test example
<?php
namespace Acme\Mybundle\Tests\Controller;
use Liip\FunctionalTestBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Session\Session;
class ControllerTest extends WebTestCase
{
public function testVmplsNew() {
@zyphlar
zyphlar / rgb-hsv-conversion.php
Last active November 16, 2023 20:49
RGB and HSV conversion in PHP
<?php
// note: some of these are written with $this so they work inside classes.
// you could easily rewrite this to be a general function outside a class.
// sorry for the inconsistent tabs
// adapted from: http://www.actionscript.org/forums/showthread.php3?t=50746 via http://stackoverflow.com/questions/1773698/rgb-to-hsv-in-php
class MyClass
{
// usage: $this->hexColorMod("#aa00ff", -0.2); // darker by 20%
// returns: #8700cc
@zyphlar
zyphlar / cron.txt
Last active August 29, 2015 14:08
Amazon AWS EC2 snapshot cron job
# To set up these environment vars correctly, follow the instructions in:
# http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/set-up-ec2-cli-linux.html
# this is necessary to load your AWS credentials from bashrc.
SHELL=/bin/bash
# double-check this and make sure it's the correct path for ec2-describe-volumes
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin
# this needs to be the path above, minus /bin
EC2_HOME=/opt/aws
# this also needs to be set/correctly
<?php
//..
function editAction(){
$form = $this->createForm(new Forms\UserType($userConfig), $user);
$form->handleRequest($request);
if($form->isValid()) {
$em = $this->getDoctrine()->getManager();
@zyphlar
zyphlar / generatePassword.php
Created December 20, 2014 22:36
Generating secure passwords in PHP
<?php
// usage: $newpassword = generatePassword(12); // for a 12-char password, upper/lower/numbers.
// functions that use rand() or mt_rand() are not secure according to the PHP manual.
function getRandomBytes($nbBytes = 32)
{
$bytes = openssl_random_pseudo_bytes($nbBytes, $strong);
if (false !== $bytes && true === $strong) {
return $bytes;
}
@zyphlar
zyphlar / .gitconfig
Created January 22, 2015 00:06
My gitconfig file
[alias]
lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
lg = !"git lg1"
wdiff = diff --word-diff --color-words
[credential]
helper = cache --timeout=3600
[color]
diff = always
[diff]
@zyphlar
zyphlar / open_all_links.js
Created February 10, 2015 17:45
JQuery to open every link on a page due to laziness
@zyphlar
zyphlar / README.md
Last active August 29, 2015 14:23 — forked from oodavid/README.md

Deploy your site with git (improved with secret tokens, branches, and error output)

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
@zyphlar
zyphlar / Preferences.sublime-settings
Last active September 2, 2015 17:05
Binary and Folder exclude patterns for Symfony projects (and in general)
{
"binary_file_patterns":
[
"*.jpg",
"*.jpeg",
"*.png",
"*.gif",
"*.ttf",
"*.tga",
"*.dds",
<?php
namespace Acme\YourBundle\Listener;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Bundle\TwigBundle\TwigEngine;