Skip to content

Instantly share code, notes, and snippets.

@shanna
shanna / layout
Created August 2, 2011 09:24
Basic application structure.
/
/bin
#{project}
#{project}-cli
#{project}-db
#{project}-job
#{project}-web
#{project}-config
...
* We stole the CLI command hierarchy from git. E.g. ./bin/project web (start|stop|status) [options]
@shanna
shanna / gist:1873425
Created February 21, 2012 03:29
Tiny PHP MySQL abstraction.
<?php
# Mysql
#
# require_once('mysql.php');
# $db = new Mysql(dbname, server, user, pass);
# $sth = $db->query('select * from blah where name = ? limit 1', 'fred') || die($db->error());
# while ($row = mysql_fetch_assoc($sth))
# ...
#
@shanna
shanna / util.hpp
Created February 24, 2012 02:59
Casting to and from strings.
#pragma once
#include <iostream>
#include <sstream>
#include <string>
template<typename T>
T string_to(const std::string& p_string) {
std::istringstream iss(p_string);
T x;
(function ($) {
var providers = {};
/*
Given a URL find a provider that can OEmbed the url given.
*/
function find (url) {
var site = url.match(/^https?:\/\/([^/]+)/)[1];
for (var domain in providers)
if (site.indexOf(domain) > -1)
@shanna
shanna / uri.js
Created April 21, 2012 04:04 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.host; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
@shanna
shanna / path.rb
Created May 17, 2012 05:40
JSONPath like access to Oj JSON structs.
require 'delegate'
require 'oj'
require 'strscan'
# JSONPath like access to Oj JSON structs.
#
# @note Array access is identical to Array#[]
class Oj::Path < SimpleDelegator
class Error < StandardError; end
class MissingError < Error; end
@shanna
shanna / ad_version_1.rb
Created May 21, 2012 07:23
Simple example of why mocks are stupid.
# First iteration of Ad
class Ad
attr_accessor :message
def view
"For sale #{message} call #{owner.name}"
end
end # Ad
@shanna
shanna / Makefile
Created July 5, 2012 23:59
Watch and compile JS and CSS.
templates:
cd web/templates && haml-coffee -i . -n this.nd.templates -o ../js/nd-templates.js
css:
cd web/css && recess nd.less --compile > ../../public/nd.css
app:
cd web/app && coffee -cj ../js/nd.js nd.coffee
js:
@shanna
shanna / persona.go
Created October 8, 2012 13:00
Persona Verification in Go
package persona
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/url"
)
type Auth struct {
@shanna
shanna / tms.c
Created December 3, 2012 05:42
libmosquitto mosquitto_topic_matches_sub
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <mosquitto.h>
int main (int argc, char *argv[])
{
bool matches = false;
mosquitto_topic_matches_sub(argv[1], argv[2], &matches);
printf("matches: %d\n", matches);