Skip to content

Instantly share code, notes, and snippets.

View tjlytle's full-sized avatar

Tim Lytle tjlytle

View GitHub Profile
@tjlytle
tjlytle / gist:1041899
Created June 23, 2011 04:22
Example singleton
<?php
class Singleton
{
public static function getInstance()
{
static $instance;
if(empty($instance)){
$class = get_called_class();
$instance = new $class;
}
@tjlytle
tjlytle / oauth.php
Created June 8, 2011 16:32
Command Line Script to get Access Token using Zend_Twitter
#!/usr/bin/php
<?php
require_once 'Zend/Oauth/Consumer.php';
require_once 'Zend/Console/Getopt.php';
//set valid config file types/extensions
$configTypes = array('ini', 'xml', 'json', 'yaml');
//setup command line opts
$opts = new Zend_Console_Getopt(array(
@tjlytle
tjlytle / account.php
Created May 11, 2011 02:45
Sample of In-Progress Twilio Library
<?php
require_once 'Twilio/Client.php';
require_once 'auth.php';
//setup client
$twilio = new Twilio_Client(ACCOUNT_SID, ACCOUNT_TOKEN);
//get account information
echo 'Account: ' . $twilio->accounts->getAccount(ACCOUNT_SID)->getFriendlyName() . PHP_EOL;
@tjlytle
tjlytle / select.php
Created March 19, 2011 17:54
Example of using PHP's Date objects to generate a select element.
<select name="time" id="time">
<?php
$now = new DateTime();
$select = new DateTime();
$select->setTime(0,0);
$tomorrow = new DateTime('tomorrow');
$tomorrow->setTime(0,0);
?>
<?php while($select < $tomorrow): ?>
<?php $diff = $select->diff($now) ?>
@tjlytle
tjlytle / test-email.php
Created March 12, 2011 21:03
Test the PHP mail() function.
<?php
mail('user@example.com', 'Testing PHP Mail Function', 'It Works');
@tjlytle
tjlytle / voicemail.php
Created February 27, 2011 00:21
Sample script to go directly to voicemail.
<?php
require_once 'client.php'; //setup the Twilio rest client and assorted vars
$number = '1235556789'; //the number you're calling
$data = array('From' => $callerID,
'To' => $number,
'Url' => "http://twimlets.com/message?Message%5B0%5D=Voicemail&");
//place both calls
$call1 = $client->request("$version/Accounts/$accountSid/Calls", 'POST', $data);
@tjlytle
tjlytle / odesk-outright.php
Created January 11, 2011 01:50
Simple script to convert an oDesk export to Outright's expected format.
<?php
$in = fopen($argv[1], 'r');
$out = fopen('php://output', 'w');
$fields = fgetcsv($in);
$map['date'] = 'Date';
$map['description'] = 'Description';
$map['payee'] = 'Employer';
$map['amount'] = 'Amount';
@tjlytle
tjlytle / gist:721280
Created November 30, 2010 07:06
Example setup of Zend_Service_Twitter using stored credentials.
$token = new Zend_Oauth_Token_Access();
$token->setToken(TWITTER_USER)
->setTokenSecret(TWITTER_PASS);
$twitter = new Zend_Service_Twitter(array(
'accessToken' => $token,
'consumerKey' => TWITTER_CONSUMER_KEY,
'consumerSecret' => TWITTER_CONSUMER_SECRET));
@tjlytle
tjlytle / Twitter User
Created November 8, 2010 15:51
Example getting follower count and last status using SimpleXML and the Twitter API. Any information returned from the show API (http://dev.twitter.com/doc/get/users/show) can be accessed.
<?php
function getUser($name){
$user = simplexml_load_file('http://twitter.com/users/show.xml?screen_name='.$name);
return $user;
}
$user = getUser('tjlytle');
echo $user->followers_count;
​echo $user->status->text;​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
@tjlytle
tjlytle / gist:565773
Created September 5, 2010 05:29
Calibre Recipe for Doctrine2 Manual
#!/usr/bin/env python
import string, re
from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import Tag, NavigableString
class Doctrine2(BasicNewsRecipe):
title = 'Doctrine2'