Skip to content

Instantly share code, notes, and snippets.

View jmather's full-sized avatar

Jacob Mather jmather

View GitHub Profile
@jmather
jmather / User.php
Created December 20, 2012 17:46
How to make VichUploaderBundle change an image
public function setProfileImage($profile_image)
{
$this->profile_image = $profile_image;
if ($profile_image instanceof UploadedFile) {
$this->setUpdatedAt(new \DateTime());
}
}
<?php
use Silex\WebTestCase;
use Silex\Application;
use Silex\Provider\SessionServiceProvider;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
class unitTest extends WebTestCase
{
<?php
use Silex\WebTestCase;
use Silex\Application;
use Silex\Provider\SessionServiceProvider;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
class unitTest extends WebTestCase
{
public function testUn()
@jmather
jmather / example.php
Created December 16, 2012 02:40
Proxy Pattern Example
<?php
interface MyAPI
{
public function getThing();
}
class MyApiImplentation implements MyAPI
{
public function getThing()
@jmather
jmather / .init.sh
Created December 4, 2012 22:41
Easily create a new project
#!/bin/bash
source /etc/profile
git init
mv base.iml $1.iml
cd .idea/
cat modules.xml | sed "s/base/$1/g" > modules.xml.new
mv modules.xml.new modules.xml
@jmather
jmather / .profile
Created November 23, 2012 04:55
Getting firefox prepped for working with Selenium
PATH=$PATH:$HOME/bin
@jmather
jmather / BadCharacterMungerFilter.php
Created November 14, 2012 20:52
Filter bad rss unhappy characters out
<?php
class BadCharacterMungerFilter extends sfFilter
{
public function execute($filterChain)
{
$filterChain->execute();
// Execute this filter only once
if ($this->isFirstCall()) {
$response = $this->getContext()->getResponse();
@jmather
jmather / SSLManagementListener.php
Created November 9, 2012 21:22
Redirect to SSL only on given
<?php
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
class SSLManagementListener
{
private $domain;
public function isEmailUnique($email_address)
{
$qb = $this->createQueryBuilder('e')
->select('COUNT(e.id)')
->where('e.email_address = :email')
->setParameter('email', $email_address);
$result = $qb->getQuery()->getSingleScalarResult();
if ($result > 0)
@jmather
jmather / test.js
Created November 2, 2012 19:33
random-guess
// here is how I suspect you are currently doing something.
// Assuming you have a piece of data you need to send back with your request processing:
function sendMyRequest(info)
{
var response_callback = function(data) {
callMyActualReturnMethod(data, info);
}
$.get('/some/path', response_callback, 'json');
}