Skip to content

Instantly share code, notes, and snippets.

View xeoncross's full-sized avatar

David Pennington xeoncross

View GitHub Profile
@xeoncross
xeoncross / upload.php
Created December 11, 2012 18:13 — forked from codingjester/upload.php
Working PHP example of uploading a photo with V2 api
<?php
#Requires PHP 5.3.0
define("CONSUMER_KEY", "consumer_key");
define("CONSUMER_SECRET", "consumer_secret");
define("OAUTH_TOKEN", "access_token");
define("OAUTH_SECRET", "access_secret");
function oauth_gen($method, $url, $iparams, &$headers) {
<?php
// extend base Stream class by checking stream meta data for remaining stream buffer before reading from blocking streams
// heavily inspired by: https://github.com/clue/Worker/commit/8c6d7a4e733f0ee5aa431ffda1d4929229ae2336
class StreamUnblock extends \React\Stream\Stream
{
public function handleData($stream)
{
// check stream meta data for remaining buffer
// yes, the manual explicitly says this value SHOULD NOT be used,
<?php
// Let's see those errors!
error_reporting(1);
// Give it some time!
set_time_limit(80);
// File ext(types) to check!
$check_files = array(
@xeoncross
xeoncross / http.php
Created January 26, 2013 00:27 — forked from gyuchang/http.php
<?php
/*
* HTTP/HTTPS class: simple HTTP client
* - it's a wrapper for cURL, geared toward API/server-to-server call
* - if you want to mimic a browser, you should NOT use these classes
*/
class HTTP {
const SCHEME = 'http';

Microframework

This is a PHP microframework based on anonymous functions.

Features

  • requested URLs matched using regular expressions
  • request methods (matches using regular expressions too)
  • differenced FIFO queues for each $priority
  • command line usage
  • backward compatibility
<?php
interface Worker
{
public function getCommand();
public function done($stdout, $stderr);
public function fail($stdout, $stderr, $status);
}
@xeoncross
xeoncross / repl.php
Created February 12, 2013 18:17 — forked from kahagon/repl.php
Simple PHP REPL that complies and prints the finished highlighted code when done
#!/usr/bin/env php
<?php
$stdin = fopen('php://stdin', 'r');
$lines = array();
register_shutdown_function(function() use(&$lines) {
$source = join("\n", $lines);
<?php
function extractByClass($class,$context){
preg_match_all('#<\s*(\w+)\s*class="\s*'.$class.'\s*"[^>]*>(.*?)</\s*\g1\s*>#sm',$context,$matches);
return $matches[2];
}
function extractByID($class,$context){
preg_match_all('#<\s*(\w+)\s*id="\s*'.$class.'\s*"[^>]*>(.*?)</\s*\g1\s*>#sm',$context,$matches);
return $matches[2];
<?php
function pre_print_r($var){
echo "<pre>";
print_r($var);
echo "</pre>";
}
function Bigrams($word){
<?php
class StringBalance {
private $startBrace = "(";
private $endBrace = ")";
public $debug = false;
private $startBraceFound;
private $endBraceFound;