Skip to content

Instantly share code, notes, and snippets.

View samstewart's full-sized avatar

Sam Stewart samstewart

  • New York, New York
View GitHub Profile
@samstewart
samstewart / changes_diagnostic_app.md
Last active December 17, 2015 12:29
changes I made to the playhaven diagnostic app

Compatibility with UI Tests for Diagnostic App

I added a contentDescription to the major UI components for the SDK so that my UI tests of DiagnosticApp could discern when the main view was being shown.

Logging Fix

Currently, the SDK allows system log level to override the log level set in code in the Playhaven SDK. The idea is to allow support developers to "turn on" the verbose logs when debugging an app that is "mute" in production and the flag can be set via adb setprop log.tag.[APP NAME] [LOG LEVEL]. Unfortunately, this flag defaults to INFO even if the support developer never calls setprop. This means that the code level setting can never restrict the logs below a level of INFO because the device setting takes precedence.

The system property concept as a whole seemed problematic and unreliable so I switched to a small configuration file placed in /sdcard/loglevel.prop that simply listed the appropriate log level. If this file does not exist, the SDK defaults to the code level setting but

@samstewart
samstewart / dump_dom.js
Created May 28, 2013 04:22
Nice script to dump all the visible elements of the DOM to JSON.
/* Dump the DOM as a javascript object in the new window.
Possibly useful links:
https://developer.mozilla.org/en-US/docs/Web/API/document.elementFromPoint
*/
function dump_dom ()
{
<ul id="form_templates" class="fields hidden">
<li class="name">
<label class="field_name">Name</label>
<input type="text" name="name"></input>
<span class="error_message"></span>
</li>
<li class="email">
<label class="field_name">Email</label>
<input type="email" name="email" class="email" novalidate></input>
<span class="error_message"></span>
@samstewart
samstewart / UIImage+CompatibleImage.m
Created August 30, 2013 19:09
Loads iPad and iPhone images according to Apple's naming convention. Nice for retina displays
//
// UIImage+CompatibleImage.m
// Notescast 3.6
//
// Created by Sam Stewart on 8/25/13.
//
//
#import "UIImage+CompatibleImage.h"
@samstewart
samstewart / retina.js
Created August 30, 2013 19:14
Simple JQuery plugin that replaces all images in a webpage according to the iOS device and resolution. Expects files named according to Apple's naming scheme. I'd like to add -Landscape and -Portrait modifiers in the future.
(function() {
var root = (typeof exports == 'undefined' ? window : exports);
var config = {
// Ensure Content-Type is an image before trying to load @2x image
// https://github.com/imulus/retinajs/pull/45)
check_mime_type: true
};
@samstewart
samstewart / output.json
Created December 26, 2013 23:56
sample cucumber output
[
{
"description" : "",
"elements" :
[
{
"description" : "",
@samstewart
samstewart / Makefile
Last active January 1, 2016 22:49
Template for CPP makefiles (correction to http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/)
# g++ -mmacosx-version-min=10.8 -o bin/kepler kepler.cpp image_compare.cpp s3_conn.cpp report_parser.cpp `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs` -L 'reference source/jsoncpp-src-0.5.0/libs/linux-gcc-4.2.1' -ljson -I 'reference source/jsoncpp-src-0.5.0/include/json' -L 'reference source/libs3-2.0/build/lib' -I 'reference source/libs3-2.0/inc' -I include -lcurl -lxml2 -lz -ls3
GMLINKER=`GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
IDIR = include
CC = g++
CFLAGS =-I$(IDIR) -mmacosx-version-min=10.8 -Wall -I/usr/local/include/GraphicsMagick -g
ODIR = bin
LDIR =../lib
@samstewart
samstewart / photo_import.py
Created January 11, 2014 05:50
Photo import script
#!/usr/bin/python
# awesome python script that takes all files from the camera and archives them.
# it imports from the temp directory and builds a large archive in the Photo folders.
# The current iteration is quite functional in an effort for conciseness.
import os, time, shutil, calendar, subprocess, sys, fnmatch, shutil, re
from os import path
class PhotoArchiver:
@samstewart
samstewart / java_Makefile.make
Created June 13, 2016 15:49
Simple makefile for java
# A simple makefile for java programs
JCC = javac
LIBS = /usr/bin/apache-commons.jar:/usr/bin/pdfbox.jar
JFLAGS = -g -cp $(LIBS):.
# we clear any default suffixes
.SUFFIXES: .java .class
@samstewart
samstewart / vec2ind.m
Created September 23, 2016 19:25
Vector indexing in matlab. use a vector to index a multidimensional array.
% simple command that converts a vector to a multidimensional index given the size of the array
% you should ignore any singleton dimensions (don't provide an element of the vector)
% TODO turn this into a Gist
% size_of_matrix: vector of dimensions of the matrix (can include singleton dimensions)
% vec_index: a vector whose nth component corresponds to the nth index.
function indx = vec2ind(size_of_matrix, vec_index)
% We convert this to a linear index. Not that matlab takes the full n dimensional integer
% lattice and converts it to a one dimensional integer lattice by reading off successive columns.
% the formula (really bijection between countable sets) between Z^n_1 x Z^n_2 x Z^n_3 --- Z^n_k is given by
% (a_0, a_1, ..., a_n) -> a_0 + (b_0)(a_1 - 1) + (b_0 b_1) (a_2 - 1) + (b_0 b_1 b_2) (a_3 - 1) + ....