Skip to content

Instantly share code, notes, and snippets.

@mjohnsullivan
mjohnsullivan / named_struct.rb
Created May 2, 2011 14:25
Ruby Struct utilities: use named parameters to create Struct-based objects and return JSON from Structs
# Struct utilities
# Author:: Matt Sullivan (mailto:matt.j.sullivan@gmail.com)
# Attempt to require Ruby Gems; 1.8.X gem support only
begin
require 'rubygems'
rescue LoadError
# Ruby Gems not installed
end
@mjohnsullivan
mjohnsullivan / locksmith_client.py
Created January 26, 2012 13:20
Uploading and Accessing KDMs in Locksmith
"""
Remote API wrapper for Locksmith
"""
import urllib
import urllib2
import json
LOCKSMITH_HOST = 'https://locksmith.artsalliancemedia.com'
@mjohnsullivan
mjohnsullivan / mxf.py
Created August 17, 2012 10:53
Determines the essence type of an mxf file for DCI digital cinema content: JPEG2000, MPEG or PCM
import sys
import struct
# MXF Keys
MXF_KEYS = {
'\x06\x0e\x2b\x34\x02\x53\x01\x01\x0d\x01\x01\x01\x01\x01\x51\x00' : 'MPEG2VIDEODESCRIPTOR',
'\x06\x0e\x2b\x34\x02\x53\x01\x01\x0d\x01\x01\x01\x01\x01\x5a\x00' : 'JPEG2000PICTURESUBDESCRIPTOR',
'\x06\x0e\x2b\x34\x02\x53\x01\x01\x0d\x01\x01\x01\x01\x01\x48\x00' : 'WAVEAUDIODESCRIPTOR',
'\x06\x0e\x2b\x34\x02\x53\x01\x01\x0d\x01\x01\x01\x01\x01\x37\x00' : 'SOURCEPACKAGE',
'\x06\x0e\x2b\x34\x01\x02\x01\x01\x0d\x01\x03\x01\x15\x01\x05\x00' : 'MPEG2ESSENCE',
@mjohnsullivan
mjohnsullivan / scuttlebutt_muxdemux_test.js
Created March 7, 2013 17:16
My naive attempt at multiplexing/demultiplexing Scuttlebutt Model streams.
var MuxDemux = require('mux-demux');
var net = require('net');
var Model = require('scuttlebutt/model');
var aModel = new Model
var aModelStream = aModel.createStream()
var bModel = new Model
var bModelStream = bModel.createStream()
// Server
@mjohnsullivan
mjohnsullivan / motion1.js
Last active December 17, 2015 06:39
AxisCam motion detection with classic Node streams
/**
* Parses out motion data from the Axis camera motion stream
*/
var util = require('util'),
Stream = require('stream').Stream
var MotionLevelStream = function() {
this.readable = true
this.writable = true
}
@mjohnsullivan
mjohnsullivan / motion2.js
Created May 13, 2013 08:21
AxisCam motion detection with new Node streams Transform and prototypes
/**
* Parses out motion data from the Axis camera motion stream
* Implemented with the new Node streams using prototypes
*/
var Transform = require('stream').Transform
var MotionLevelStream = function() {
Transform.call(this, {objectMode: true})
}
@mjohnsullivan
mjohnsullivan / motion3.js
Created May 13, 2013 08:21
AxisCam motion detection with new Node streams Transform without prototypes
/**
* Parses out motion data from the Axis camera motion stream
* Implemented with the new Node streams
*/
var stream = require('stream'),
util = require('util')
var MotionLevelStream = function() {
stream.Transform.call(this, {objectMode: true})
@mjohnsullivan
mjohnsullivan / download.py
Last active December 17, 2022 10:05
Python HTTP download with resume and optional MD5 hash checking
import os.path
import shutil
import hashlib
import logging
# Support both Python 2 and 3 urllib2 importing
try:
from urllib.request import urlopen, Request
except ImportError:
from urllib2 import urlopen, Request
@mjohnsullivan
mjohnsullivan / MainActivity.java
Last active March 1, 2024 01:28
Android Wear activity that reads and displays sensor data from the device
package com.example.wear;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.wearable.view.WatchViewStub;
import android.util.Log;
@mjohnsullivan
mjohnsullivan / http_server.rs
Last active March 12, 2024 16:08
Simple HTTP server example for Rust
// Updated example from http://rosettacode.org/wiki/Hello_world/Web_server#Rust
// to work with Rust 1.0 beta
use std::net::{TcpStream, TcpListener};
use std::io::{Read, Write};
use std::thread;
fn handle_read(mut stream: &TcpStream) {
let mut buf = [0u8 ;4096];