Skip to content

Instantly share code, notes, and snippets.

View cameronjacobson's full-sized avatar

Cameron Jacobson cameronjacobson

View GitHub Profile
@cameronjacobson
cameronjacobson / pcsc
Last active August 29, 2015 13:56
Bare-bones code to interface with PCSCD / NFC readers
import java.util.List;
import javax.smartcardio.*;
// VARIATION OF:
// http://ludovicrousseau.blogspot.com/2010/06/pcsc-sample-in-java.html
// The included commands are specific to acr122u reader / writer for Mifare Classic 1k tags
public class pcsc {
public static void main(String[] args) {
@cameronjacobson
cameronjacobson / geturl.php
Created August 20, 2013 04:46
bare-bones generate temporary access URL to non-public Amazon S3 resource
<?php
$key = 'SECRET_ACCESS_KEY_ID';
$accesskeyid='ACCESS_KEY_ID';
$expires = time()+60; // URL expires in 60 seconds
$stringtosign = "GET\n\n\n{$expires}\n/BUCKET_NAME/PATH/TO/RESOURCE.EXT";
$signature = urlencode(base64_encode(hash_hmac('sha1',$stringtosign,$key,true)));
@cameronjacobson
cameronjacobson / form.php
Created August 17, 2013 07:13
bare-bones Browser-based S3 POST
<?php
if(isset($_GET['success'])){
echo 'done';
exit;
}
$policy = base64_encode(str_replace(array("\r","\n"),"",'{ "expiration": "2023-01-01T12:00:00.000Z", "conditions": [
{"acl": "public-read" },
{"bucket": "MYBUCKET" },
@cameronjacobson
cameronjacobson / PhreezerExample.php
Last active December 15, 2015 08:29
Intuitive way to interact with CouchDB documents
<?php
/**
* Phreezer project page:
* https://github.com/cameronjacobson/Phreezer
*/
class Vehicle
{
public function __construct(){}
@cameronjacobson
cameronjacobson / simpletokenizer.php
Created January 19, 2013 14:19
Simple tokenizer which only splits on space character, while maintaining context for single or double-quoted strings. Uses include creation of very basic DSLs in PHP.
<?php
for($x=0;$x<strlen($argv[1]);$x++){
$tokens[] = getNextToken(substr($argv[1],$x),$x);
}
print_r($tokens);
function getNextToken($input,&$prefix){
@cameronjacobson
cameronjacobson / gist:4533300
Last active December 11, 2015 02:48
reading AngularJS POST with PHP
<?php
// If you don't want to depend on HTTP client to serialize POST body into URI
// encoded format
// ** For Example: AngularJS doesn't natively POST the same way jQuery does.
$post = json_decode(file_get_contents('php://input'), true);
@cameronjacobson
cameronjacobson / useful
Created January 9, 2013 23:05
Useful links
How to do inferred dependency injection in PHP [similar to concept employed by AngularJS]
- http://php.net/manual/en/function.parsekit-func-arginfo.php
@cameronjacobson
cameronjacobson / EventLoop.php
Created November 16, 2012 13:52
early stages of a php libevent project (inspired by reactphp/react)
<?php
include('EventTrait.php');
class EventLoop
{
use EventTrait;
private $base;
private $events;
@cameronjacobson
cameronjacobson / ReactStream.php
Created November 15, 2012 06:56
concept for react:// streamWrapper (reactphp/react)
<?php
class ReactStream {
private $components;
private $position;
private $queue;
function stream_open($path, $mode, $options, &$opened_path)
{
@cameronjacobson
cameronjacobson / tcp_monitor.php
Created November 13, 2012 00:01
Simplistic TCP Monitor
<?php
error_reporting(0);
define('MONITOR_INTERVAL', 60);
$monitors = [
['127.0.0.1',25,80,110]
];