Skip to content

Instantly share code, notes, and snippets.

@ssx
ssx / interfaces.php
Created September 7, 2013 16:57
An introduction taken from Taylor's Laravel book and extended to display the useful nature of interfaces.
<?php
header("Content-Type: text/plain");
interface BillerInterface {
public function bill(array $user, $amount);
}
interface BillingNotifierInterface {
public function notify(array $user, $amount);
}

Extending the Product Model in Sylius

When I was first playing with Sylius I noticed that there is no easy way to disable a product - I'm sure you could change the stock settings or something. I prefer to have a simple on / off switch so I set about creating one by extending the Sylius Product Model, here's you can do it too:

First, create a bundle within the src folder of the sylius installation (since Sylius is a Symfony2 application it follows the Symfony2 folder structure). This is my first attempt at using Sylius / Symfony2 so I'm not sure about best practices for bundles, but having a bundle for your project that contains all of the extended classes seems sensible. Since I'm working on a super secret site, my bundle will be called 'SuperSecret'. Symfony2 uses psr0, so my folder structure ends up as src/PeterFritchley/Bundle/SuperSecretBundle.

Now that we have a bundle, we need to create a class t

@sweikenb
sweikenb / install_ramcache.sh
Last active December 22, 2015 22:19
Speedup your symfony2 vagrant box by mounting the app/cache folder into the ram of the vm (run this script as root!)
#!/bin/sh
# create mount point
if [ ! -d /ram ]
then
mkdir /ram
fi
# create ramfs
mount -t ramfs -o size=512M ramfs /ram/
@joshuabaker
joshuabaker / getTweetHTML.js
Last active December 23, 2015 09:09
Switches tweet entities, from a Twitter API response, into anchor links, returning HTML ready for display. Built for use with https://github.com/joshuabaker/twitter-proxy
var getTweetHTML = function(tweet)
{
var i, item, entities = {}, html = tweet.text, target;
for (i in tweet.entities.hashtags)
{
item = tweet.entities.hashtags[i];
entities[item.indices[0]] = [item.indices[1], '<a href="https://twitter.com/search?q=%23' + item.text + '" target="_blank">#' + item.text + '</a>'];
}
@jamesmoey
jamesmoey / ExtendedArrayCollection.php
Last active July 24, 2023 07:02
Extend array collection from Doctrine with operation to perform on all the item in the collection.
<?php
namespace Collections;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\PropertyAccess\PropertyAccess;
class ExtendedArrayCollection extends ArrayCollection
{
/**
anonymous
anonymous / main.js
Created November 25, 2013 10:17
reload sf2 wdt on ajax request
$(document).ajaxComplete(function(event, XMLHttpRequest){
var token = XMLHttpRequest.getResponseHeader('x-debug-token'),
protocol = window.location.protocol,
hostname = window.location.hostname;
if(token) {
$.get(protocol+'//'+hostname+'/_wdt/'+token, function(data){
@jvns
jvns / rust-types.md
Last active October 5, 2021 08:41
Rust type tutorial

I found understanding Rust types really confusing, so I wrote up a small tutorial for myself in an attempt to understand some of them. This is by no means exhaustive. There is a types section in the manual, but it has nowhere near enough examples.

I'm not talking about managed pointers (@) at all. A lot of the difficulty with Rust types is that the language is constantly changing, so this will likely be out of date soon.

First, a few preliminaries: it's easier to play with types if you have a REPL and can interactively check the types of objects. This isn't really possible in Rust, but there are workarounds.

To start out: some help

How to get a Rust REPL

@justinrainbow
justinrainbow / spec-builder.php
Created February 20, 2014 15:52
Create PhpSpec base specs from existing code
<?php
require_once 'vendor/autoload.php';
$class = $argv[1];
$class = str_replace('/', '\\', $class);
$refl = new ReflectionClass($class);
run:
casperjs index.js && convert *.jpg video.mpeg && gify video.mpeg out.gif && rm *.jpg video.mpeg
@takeshixx
takeshixx / hb-test.py
Last active September 8, 2025 01:16
OpenSSL heartbeat PoC with STARTTLS support.
#!/usr/bin/env python2
"""
Author: takeshix <[email protected]>
PoC code for CVE-2014-0160. Original PoC by Jared Stafford ([email protected]).
Supportes all versions of TLS and has STARTTLS support for SMTP,POP3,IMAP,FTP and XMPP.
"""
import sys,struct,socket
from argparse import ArgumentParser