Skip to content

Instantly share code, notes, and snippets.

<div id="bellend" class="bellend hidden">STOP THAT</div>
<style>
.hidden {
display:none;
}
.bellend {
background: #000;
color: #FFF;
height: 100%;
@mattattui
mattattui / gist:8302079
Created January 7, 2014 16:36
Sample jquery theme-switcher
<?php
// This code shouldn't actually be *here*, obviously
$theme = filter_input(INPUT_POST, 'theme', FILTER_VALIDATE_REGEXP, [
'options' => [
'regexp' => '/^pink|blue|whatever$/',
],
]);
if ($theme) {
// Persist the theme somehow (just session here, but could be cookie or user profile)
@mattattui
mattattui / Session.php
Created May 25, 2013 15:25
A Doctrine DBAL 2.3 session storage class for https://github.com/php-loep/oauth2-server For use if you've written an API with Doctrine ORM or DBAL, not zetacomponents/database.
<?php
/**
* Doctrine DBAL server storage class for LEOP's OAuth2 server library
*
* Why? Because the built-in one uses zetacomponents/database and the rest of
* your app uses Doctrine2 ORM or DBAL. Using this DBAL implementation offers
* no other advantages; zetacomponents/database and doctrine/dbal are roughly
* equivalent.
*/
namespace Inanimatt\OAuth2\Server\Storage\DBAL;
<?php
require_once __DIR__.'/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
$request = Request::createFromGlobals();
$dirty_html = $request->get('dirty_input');
$config = HTMLPurifier_Config::createDefault();
<?php
namespace Acme\DemoBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class ImportCSVCommand extends ContainerAwareCommand
@mattattui
mattattui / gist:5201092
Last active December 15, 2015 04:19
Using SPLFileInfo, DirectoryIterator, and php://temp
<?php
$dir = new DirectoryIterator('/Users/matt/Projects/Domain-Calendar');
$files = new RegexIterator($dir, '/^composer/');
foreach($files as $file) {
echo $file->getPathName().PHP_EOL;
}
@mattattui
mattattui / CSVIterator.php
Created February 19, 2013 23:18
Simple CSV iterator
<?php
class CSVIterator extends SPLFileObject
{
protected $first_row = true;
protected $columns;
public function __construct ($filename, $delimiter = ',')
{
parent::__construct($filename);
@mattattui
mattattui / imageTest.php
Created February 8, 2013 12:17
3 ways to test if a file is an image
<?php
/**
* Test if given file is a web image (gif/jpg/png)
*
* Requires PHP 5.3 or newer (builtin) or the Fileinfo PECL extension.
*
* @param string $file Path to image
* @return boolean True if web image, or false if unreadable or not image
*/
@mattattui
mattattui / deploy.sh
Created January 5, 2013 09:48
Simple default-safe rsync deployment script
#!/bin/bash
# Will add --dry-run unless the --go option is set. All other arguments passed to rsync (e.g. --delete)
SOURCE=.
DEST=example.com:/var/www/mysite
DRYRUN="--dry-run"
args=()
for var in "$@"
@mattattui
mattattui / gist:4352338
Created December 21, 2012 11:47
Zend Mail and Swift Mailer examples
<?php
// Zend Mail
use Zend\Mail;
$mail = new Mail\Message();
$mail->setBody('This is the text of the email.');
$mail->setFrom('[email protected]', 'My site');
$mail->addTo('[email protected]', 'Their name');
$mail->setSubject('Test Subject');