Skip to content

Instantly share code, notes, and snippets.

@cuppster
cuppster / DocModule.cs
Created July 5, 2014 21:46
DocModule.cs
using Nancy;
namespace MyApi
{
public class DocModule : NancyModule
{
public DocModule()
{
Get ["/doc"] = _ => {
return View ["index.html"];
@cuppster
cuppster / Adorners.cs
Last active August 29, 2015 14:03
Technique using a binding converter to return an object representing viewmodel state for displaying an adorner.
using System;
using System.Globalization;
using System.Windows.Data;
namespace WpfApplication1
{
/*
see: http://cuppster.com/2014/07/10/using-the-state-pattern-for-adorning-in-xaml/
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
@cuppster
cuppster / ShortGUID.cs
Last active August 29, 2015 14:03
Create short GUIDs with a custom alphabet
using System;
using System.Numerics;
namespace Cuppster
{
/// <summary>
/// converted from the python version at https://github.com/stochastic-technologies/shortuuid
/// </summary>
class ShortUUID
{
@cuppster
cuppster / dms2dec.py
Last active August 29, 2015 14:20 — forked from tomwhipple/dms2dec.py
#!/env/python
# coding=utf8
"""
Converting Degrees, Minutes, Seconds formatted coordinate strings to decimal.
Formula:
DEC = (DEG + (MIN * 1/60) + (SEC * 1/60 * 1/60))
Assumes S/W are negative.
@cuppster
cuppster / 1.js
Created August 15, 2012 22:13
Routed Commands for Backbone.js
// the application
//
var AppView = Backbone.View.extend({
el: $('body'),
initialize: function() {
var view = this;
// command bar
@cuppster
cuppster / 1.py
Created August 15, 2012 23:28
Simple String Generator in Python
import itertools
def string_patterns(pattern, *args):
'''generator for string patterns'''
for data in itertools.product(*args):
s = pattern.format(*data)
yield s
# generate some urls!
@cuppster
cuppster / 1.js
Created August 21, 2012 23:34
Shared backbone.js Collections
/**
* Shared Collections for backbone.js
*/
// shared collection
// useful when the user may enter the site in multiple routes/views,
// but use the same collection
var SharedCollection = function(collection) {
var obj = this;
@cuppster
cuppster / 1.js
Created August 29, 2012 21:06
Updating Views with Events, Models and Rivets
// ## Header View
//
var HeaderView = Backbone.View.extend({
// model backing the view
model: new (Backbone.Model.extend({
defaults: {
hasUpdate: false,
}
})),
@cuppster
cuppster / leo-backbone.js
Created January 27, 2013 01:08
Backbone.js client for Leonardo API
// ## global namespace
//
var Leo = {}
// ## Leonardo Options
//
Leo.options = (function() {
return {
api : 'http://dev.leonar.do/api',