Skip to content

Instantly share code, notes, and snippets.

View natevw's full-sized avatar

Nathan Vander Wilt natevw

View GitHub Profile
<!doctype html>
<html><head>
<meta charset="utf-8">
<title>Inset border styling</title>
<style>
.list {
box-shadow: inset 3px 3px 10px grey;
height: 95px;
width: 150px;
// paste this into browser's JavaScript console
// it should dump out your entire database as JSON text
// (you can also play with `db` and/or `exportedDocs` variables)
var db = Pouch("metakaolin2", function (e, db) {
if (e) throw e;
db.allDocs({include_docs:true}, function (e,d) {
if (e) throw e;
var docs = d.rows.map(function (r) { return r.doc; });
window.exportedDocs = docs;
@natevw
natevw / gist:c30cd4f0c27323e3c275
Last active August 29, 2015 14:09
Simple fma (usually "fused multiply-add", but in this case it's not really fused so we'll say "fixed", or "functional", or "fun", or the recursive backronym "fma is not unix") template helper for Django — multiply the first two numbers provided and then add the last to that. Optional p= kwarg for rounding results to a fixed precision. When used …
from django import template
#import helper_from_linked_gist as template
register = template.Library()
@register.simple_tag # {% fma m x b %}
#@register.assignment_tag # {% fma m x b as y %}
#@register.simple_assignment_tag # optional "as y", requires using helper_from_linked_gist above
def fma(x, y, z, p=None):
v = float(x) * float(y) + float(z)
return v if p is None else ("%%.%uf" % p) % v
@natevw
natevw / gist:f14812604be62c073461
Created November 17, 2014 23:44
register.simple_assignment_tag — custom Django template tag helper where result can be output directly *or* assigned as caller chooses. See https://gist.github.com/natevw/c30cd4f0c27323e3c275 for a (commented out) example of usage.
from django import template
class Library(template.Library):
def simple_assignment_tag(self, func=None, takes_context=None, name=None):
'''
Like assignment_tag but when "as" not provided, falls back to simple_tag behavior!
NOTE: this is based on Django's assignment_tag implementation, modified as needed.
'''
# (nvw) imports necessary to match original context
@natevw
natevw / table-sorting.html
Last active August 29, 2015 14:10
Boostrap-ish table sorting helper. Inspired by https://github.com/drvic10k/bootstrap-sortable but ended up being a radically simpler design.
<table class="sorting">
<thead>
<tr>
<th>Item</th>
<th data-sorting="natural-dsc">Value</th>
<th data-sorting="default natural-dsc">Last action</th>
</tr>
</thead>
<tbody>
{% for item in items %}
@natevw
natevw / arduino.cc
Created January 20, 2015 22:01
Maybe the Arduino sketch used with node-nrf/test.js?
/*
Copyright (C) 2011 James Coliz, Jr. <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
/**
* Example RF Radio Ping Pair
@natevw
natevw / gist:5ddc9230cbcc9f5a2f4b
Created February 6, 2015 17:28
Couchbase reports file
ubuntu@ip-N-N-N-N:~$ sudo tail -n 500 /opt/couchbase/var/lib/couchbase/logs/reports.log
started: [{pid,<0.496.0>},
{name,menelaus_web_alerts_srv},
{mfargs,{menelaus_web_alerts_srv,start_link,[]}},
{restart_type,permanent},
{shutdown,5000},
{child_type,worker}]
[error_logger:error,2015-02-06T9:26:44.504,ns_1@127.0.0.1:error_logger<0.6.0>:ale_error_logger_handler:do_log:203]
=========================SUPERVISOR REPORT=========================
@natevw
natevw / sample.sh
Created March 23, 2015 18:58
Add secure note to keychain via CLI
security unlock-keychain
security -i
add-generic-password -U -C note -a '' -s "NOTE NAME" -w "SECRET PASSWORD"
@natevw
natevw / README.md
Last active August 29, 2015 14:20
Overflowed element styling

This fades the bottom of an element away when its content overflows. This seems a bit simpler way of accomplishing what did, although it requires calc support to work.

function(head, req) {
// !code lib/mustache.js
// !json templates.thumbnails
//var databaseURL = "http://stravinsky.local:5984/a70_digipics/";
//var databaseURL = "http://dvorak.local:5984/temp/";
var databaseURL = "/temp/";
// requires moustache.js is_array function patched to return (a instanceof Array);
function RowArray(rowToObject) {