Skip to content

Instantly share code, notes, and snippets.

View caseysoftware's full-sized avatar

Danger Casey caseysoftware

View GitHub Profile
@caseysoftware
caseysoftware / snippet.php
Last active December 18, 2015 15:39
preg_replace before, using /e
public static function decamelize($word)
{
return preg_replace(
'/(^|[a-z])([A-Z])/e',
'strtolower(strlen("\\1") ? "\\1_\\2" : "\\2")',
$word
);
}
@caseysoftware
caseysoftware / snippet.php
Last active December 18, 2015 15:39
preg_replace after, removing /e
public static function decamelize($word)
{
$callback = create_function('$matches',
'return strtolower(strlen("$matches[1]") ?
"$matches[1]_$matches[2]" : "$matches[2]");');
return preg_replace_callback(
'/(^|[a-z])([A-Z])/',
$callback,
$word
@caseysoftware
caseysoftware / snippet.php
Created June 18, 2013 15:30
The cURL vs Streams fallback
if (in_array('curl', get_loaded_extensions())) {
$_http = new Services_Twilio_TinyHttp(
"https://api.twilio.com",
array("curlopts" => array(
CURLOPT_USERAGENT => self::USER_AGENT,
CURLOPT_HTTPHEADER => array('Accept-Charset: utf-8'),
CURLOPT_CAINFO => dirname(__FILE__) . '/cacert.pem',
))
);
} else {
@caseysoftware
caseysoftware / helloworld.php
Created June 24, 2013 20:10
helloworld.php
<?php
include 'Services/Twilio.php';
$response = new Services_Twilio_Twiml();
$response->say('Hello Monkey');
print $response;
@caseysoftware
caseysoftware / helloworld2.php
Created June 24, 2013 20:19
helloworld2.php
<?php
require 'Services/Twilio.php';
include 'credentials.php';
$client = new Services_Twilio($AccountSid, $AuthToken);
$call = $client->account->sms_messages->create(
'1512-555-1212', // From this number
'1703-555-1212', // Send to this number
@caseysoftware
caseysoftware / app.yaml
Last active December 19, 2015 00:29
Example app.yaml file for a PHP-based Twilio example on Google App Engine
application: examplehelloworld
version: 1
runtime: php
api_version: 1
threadsafe: true
handlers:
- url: .*
script: main.php
@caseysoftware
caseysoftware / app.yaml
Last active December 19, 2015 00:29
Updated app.yaml for the twilio example
application: examplehelloworld
version: 1
runtime: php
api_version: 1
threadsafe: true
handlers:
- url: /images
static_dir: images
@caseysoftware
caseysoftware / make-call.php
Created June 26, 2013 16:51
This is the script to place a call
<?php
require 'Services/Twilio.php';
include 'credentials.php';
$client = new Services_Twilio($AccountSid, $AuthToken);
$call = $client->account->calls->create(
'1512-555-1212', // From this number
'17035551212', // Send to this number
@caseysoftware
caseysoftware / send-sms.php
Created June 26, 2013 16:52
This is the script to send a message
<?php
require 'Services/Twilio.php';
include 'credentials.php';
$client = new Services_Twilio($AccountSid, $AuthToken);
$call = $client->account->sms_messages->create(
'1512-555-1212', // From this number
'17035551212', // Send to this number
@caseysoftware
caseysoftware / acronyms-spelled.php
Last active December 19, 2015 13:39
A list of acronyms you say by spelling, each run through the Twilio TTS engines.
<?php
include 'Services/Twilio.php';
/**
* UN is the oddity
*/
$items = array('CIA', 'NBC', 'CNN', 'HTTP', 'http', 'UTC', 'UN');
$response = new Services_Twilio_Twiml();