Skip to content

Instantly share code, notes, and snippets.

View philsturgeon's full-sized avatar

Phil Sturgeon philsturgeon

View GitHub Profile
@philsturgeon
philsturgeon / default.rb
Created January 8, 2013 18:02
Get PHP 5.4 in Ubuntu 12.04 (or just upgrade to 12.10)
# Use PHP 5.4
apt_repository "php54" do
uri "http://ppa.launchpad.net/ondrej/php5/ubuntu"
distribution node['lsb']['codename']
components ["main"]
keyserver "keyserver.ubuntu.com"
key "E5267A6C"
end
@philsturgeon
philsturgeon / All Posts
Last active April 16, 2021 13:44
Octopress iTunes Feed
---
layout: post
title: "Episode 3: ExpressionEngine StackExchange"
date: 2012-12-20 10:47
comments: true
filename: some-file-name-without-extension
length: 52409154
summary: ExpressionEngine Pro Anna Brown and Testing Hero Chris Hartjes join Ben Edmunds and Phil Sturgeon to discuss the recent rumblings in the ExpressionEngine community and the new EE StackExchange site. We talk about Inversion of Control (IoC), what it is, why its useful and how it's done.
---
@philsturgeon
philsturgeon / jenkins.rb
Created January 30, 2013 22:27
A vague attempt.
#
# Cookbook Name:: kapture
# Recipe:: ci
#
# Future Phil - When shit breaks try this:
# http://sqa.stackexchange.com/questions/5242/jenkins-fails-to-restart-after-updating-plugins
app_name = 'kapture-ci'
app_config = node[app_name]
@philsturgeon
philsturgeon / gist:4956941
Created February 14, 2013 22:20
Autoload through folder structures and whatnot
def Object.const_missing(name)
@looked_for ||= {}
str_name = name.to_s
raise "Class not found: #{name}" if @looked_for[str_name]
@looked_for[str_name] = 1
file = str_name.gsub!(/(.)([A-Z])/,'\1/\2') && downcase!
@philsturgeon
philsturgeon / exception
Last active December 15, 2015 02:59
Sentry if v exception
try {
$this->sentry->authenticate(array(
'email' => $email,
'password' => $password,
), (bool) $this->input->post('remember'));
} catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
// Could not log in with password. Maybe its an old style pass?
try {
@philsturgeon
philsturgeon / gist:5220258
Created March 22, 2013 10:07
Test PHP 5.5
cd /tmp
git clone http://git.php.net/repository/php-src.git -b PHP-5.5
cd php-src
./buildconf
./configure --disable-all --enable-debug --enable-maintainer-zts
make test
@philsturgeon
philsturgeon / gist:5281485
Created March 31, 2013 18:08
PHP, you crazy bitch.
php > $i = '';
php > var_dump(++$i);
string(1) "1"
php > var_dump(++$i);
int(2)
php > var_dump(++$i);
int(3)
@philsturgeon
philsturgeon / example.php
Last active December 15, 2015 18:19
Generating a 'X','Y' string from an array for an IN query with as little code as possible in Python and PHP. This is done as a learning exercise for me to see how list comprehensions work, being used for some random Twitter "your friends signed up" worker.
<?php
$users = [['id' => 1, 'name' => 'Jack'], ['id' => 2, 'name' => 'Jill']];
echo implode(',', array_map(function($u) { return "'{$u['id']}'"; }, $users));
@philsturgeon
philsturgeon / broken.py
Last active December 15, 2015 23:29
Apple Push Notification (APN) is a whiny little bitch which needs a new connection every single time. Using time.sleep(1) will cause the SSH connection to break after 4 or 5 pushes, so you need to make a new connection each time. Yay.
from apns import APNs, Payload, PayloadAlert
import time
tokens = [u'tokenhexabcdef0123456789']
apns = APNs(use_sandbox=True, cert_file='client.pem', key_file='key.pem')
alert = PayloadAlert("", loc_key="FOO", loc_args=['Some Guy'])
payload = Payload(alert=alert, sound="default", badge=1)
for token in tokens:
@philsturgeon
philsturgeon / gist:5417208
Created April 19, 2013 00:18
Magical PSR-0 Replacement
function autoload($className)
{
if (file_exists('autoload.php')) {
require_once('autoload.php');
return;
}
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {