Skip to content

Instantly share code, notes, and snippets.

View cameronjacobson's full-sized avatar

Cameron Jacobson cameronjacobson

View GitHub Profile
@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 / 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 / barebones_closure.go
Last active August 29, 2015 13:56
Bare-bones closure in GO
package main
import "fmt"
func closure(val string) func() {
return func() {
fmt.Println(val)
}
}
@cameronjacobson
cameronjacobson / json_example.go
Last active August 29, 2015 13:56
simple example of how one could wrap their structs for json en/decoding
package main
import (
"encoding/json"
"fmt"
)
type blah struct {
Numbers []int
Astring string
@cameronjacobson
cameronjacobson / octave_interface.php
Created March 19, 2014 02:30
Programmatic access to GNU Octave
<?php
$octave_command = "octave --no-window-system -q";
$spec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/octave_stderr.txt", "a")
);
@cameronjacobson
cameronjacobson / config.json
Last active February 3, 2024 14:19
Experimenting with ways to place thin "auth" layer to give web browsers direct / whitelisted access to CouchDB resources
{
"Host": "http://127.0.0.1:5984",
"Patterns":{
"GET":[
"^/_all_db",
"^/b$",
"^/c"
],
"POST":[
"^/db/"
@cameronjacobson
cameronjacobson / flex.html
Created October 14, 2014 02:25
Flexbox cheatsheet
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="normalize.css">
<style>
.flex {
height:200px;
margin-right:5px;
// DEFINES FLEX CONTEXT FOR IMMEDIATE CHILDREN
@cameronjacobson
cameronjacobson / LSB.php
Last active September 2, 2022 14:44
PHP Late Static Binding - example
<?php
abstract class GenericParser
{
abstract public static function getTokens();
public function convertTextToArray($data){
$tokens = static::getTokens();
@cameronjacobson
cameronjacobson / EDITOR.php
Created March 24, 2015 14:27
Invoke $EDITOR from PHP script
<?php
$descriptorspec = array(
0 => fopen('php://stdin','r'),
1 => fopen('php://stdout','w'),
2 => array("file", "/tmp/error-output.txt", "a")
);
$tempfile = tempnam('/tmp','testing_');
$cmd = getenv('EDITOR').' '.$tempfile;
@cameronjacobson
cameronjacobson / utf8encode.php
Last active August 29, 2015 14:17
utf8 encode a unicode code point
<?php
// utf8-encode a unicode code point
function utf8encode($cp){
if($cp <= 0x7f){
return pack("c", $cp);
}
else if($cp <= 0x7ff){
return pack("cc",
0b11000000 | (($cp >> 6) & 31),
0b10000000 | ($cp & 63)