Skip to content

Instantly share code, notes, and snippets.

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import javax.imageio.ImageIO;
@tresbailey
tresbailey / gist:e4f246cc611e8c22c134
Created December 16, 2014 16:48
BashRC for Mac git, Docker, Java, and Proxies
# System-wide .bashrc file for interactive bash(1) shells.
# The below is just appended to the /etc/bashrc
export ARCHFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future"
alias vidiff='git diff | vi -'
export DOCKER_HOST=tcp://192.168.59.103:2376
export DOCKER_CERT_PATH=/Users/tresbailey/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/
@tresbailey
tresbailey / gist:6926072
Created October 10, 2013 21:40
Default functions and methods to use with json.dumps for returning valid, full JSON representations of your domain models.
from mongoalchemy.document import Value
from pymongo.objectid import ObjectId
from market import DB
def remove_OIDs(obj, recursive=False):
"""
Removes the ObjectID types from an object
before returning
"""
@tresbailey
tresbailey / template-compiler.js
Last active December 24, 2015 07:59
Compiler for javascript templates (using underscorejs syntax) to be output as a *.js file. Write your templates in HTML and include them into the single page app as js file includes instead of keeping them all in HTML source. Watches the file system for changes to the html files in the given directory to run automatically on changes. Requires no…
fs = require('fs')
under = require('underscore')
path = require('path')
fs.watch('market/static/templates', function(event, fileName) {
if ( '.html' == path.extname(fileName) ) {
console.log('Received a change on '+ fileName +'...');
var templ = fs.readFileSync('market/static/templates/'+ fileName).toString();
var html_name = path.basename(fileName, '.html');
fs.writeFileSync('market/static/templates/_compiled/'+ html_name +'.js', 'var '+ html_name.replace(/-([^-]*)$/,'_'+'$1') +' = '+ under.template(templ).source);
@tresbailey
tresbailey / RestTestable.java
Created October 19, 2012 00:59
Going against the grain on best practices, and presenting an annotation to shunt requests for a given path to a component that forces a return of a different object. Avoids boilerplate in each of the controller methods to search for paths.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.tresback.testing;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@tresbailey
tresbailey / backbone_persist.coffee
Created August 8, 2012 13:46
Generically Persist BackboneJS Objects into MongoDB with NodeJS (coffeescript)
mongoose = require 'mongoose'
Backbone = require 'backbone'
$ = require 'jquery'
_ = require('underscore')._
Schema = mongoose.Schema
Articles = new Schema
identity: Number,
order: Number,
@tresbailey
tresbailey / (client)controller.js
Created July 20, 2012 17:16
Chat App using nodejs for server, socket.io for passing messages to/from the browser, coffeescript for some server-side files (for now), node-redis for persisting chats, express(node) for http wrapping, and jade for templating (for now), and backbone for
var NodeChatController = {
init: function() {
this.socket = io.connect('http://localhost');
var mysocket = this.socket;
this.model = new models.NodeChatModel();
this.view = new NodeChatView({model: this.model, socket: this.socket, el: $('#content')});
var view = this.view;
this.socket.on('message', function(msg) {
@tresbailey
tresbailey / gist:3106865
Created July 13, 2012 19:30
Use Backbone and jQuery to Pull Albums and Photos for a Facebook User
<!DOCTYPE html>
<html>
<head>
<title>Backbone with Mighty Moo Photos</title>
</head>
<body>
<ul id="albums-list">
</ul>
<ul id="friends-list">
@tresbailey
tresbailey / dict_format.py
Created March 24, 2012 04:53
Often times, when parsing a user-inputted JSON converted to dict object for a RESTful web service, I have a need to verify the high-level structure of the JSON. In the REST service, we may have many resources with various needed input dicts. Thus I want
TYPE_PARSERS = {
'http://www.w3.org/2001/XMLSchema.xsd#string': str,
'http://www.w3.org/2001/XMLSchema.xsd#int': int,
'http://www.w3.org/2001/XMLSchema.xsd#float': float,
'http://www.w3.org/2001/XMLSchema.xsd#date': { 'module': 'datetime',
'klass': 'datetime',
'method': 'strptime',
'args': '%d-%m-%y'},
'http://www.w3.org/2001/XMLSchema.xsd#datetime': { 'module': 'datetime',
'klass': 'datetime',