Skip to content

Instantly share code, notes, and snippets.

View cameronjacobson's full-sized avatar

Cameron Jacobson cameronjacobson

View GitHub Profile
@cameronjacobson
cameronjacobson / yuy2conversion.php
Last active August 29, 2015 14:25
Convert YUY2 image format to RGB (.ppm) file via tcp connection
<?php
// 160x120 image pixel dimensions
// PPM Header
echo "P3\n";
echo "160 120\n";
echo "255\n";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
@cameronjacobson
cameronjacobson / utfdecode.php
Last active August 29, 2015 14:17
utf8 decode a unicode code point
<?php
// convert utf8 character to its unicode code point
function utf8decode($chr){
switch(strlen($chr)){
case 1:
$x = unpack('c',$chr);
$dec = $x[1] & 127;
break;
case 2:
$x = unpack('c*',$chr);
@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)
@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 / 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 / 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 / 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 / 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 / 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 / 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)
}
}