Skip to content

Instantly share code, notes, and snippets.

View nwwells's full-sized avatar

Nathan Wells nwwells

View GitHub Profile
@nwwells
nwwells / progress.groovy
Created May 21, 2012 21:12
A progress bar for Groovy
def progressBar = { max, closure ->
def template = "\r[%s] %s"
def progress = 0
def percent = 0
def barLength = 100
def progressRatio = barLength / 100
while (progress < max) {
def progressBuffer = new StringBuilder();
def step = closure()
@nwwells
nwwells / gen_stats.py
Created June 13, 2012 20:31
A script to populate a mongo database with lots of statistics about nodes
from uuid import uuid1
import random
import json
import time
import sys
import pymongo
import datetime
start = time.time()
@nwwells
nwwells / magic.js
Created September 18, 2012 21:13
magically scrolling input element
var $inputEl = this.$inputEl, //get a jquery element
$tmp = $('<span />'), //create a span
$body = $('body'); // get the body
$tmp.html(_.escape($inputEl.val()));
$body.append($tmp);
var theWidth = $tmp.width();
$tmp.remove();
var widthToSet = (14 + theWidth) + 'px';
$inputEl.width(widthToSet);
@nwwells
nwwells / mq.css
Created October 3, 2012 20:28 — forked from chriscoyier/mq.css
@media only screen and (min-width: 320px) {
/* Small screen, non-retina */
}
@media
only screen and (-webkit-min-device-pixel-ratio: 2) and (min-width: 320px),
only screen and ( min--moz-device-pixel-ratio: 2) and (min-width: 320px),
only screen and ( -o-min-device-pixel-ratio: 2/1) and (min-width: 320px),
@nwwells
nwwells / ExampleUsage.groovy
Created October 24, 2012 14:23
Grails ExportService DSL
exportService.build {
format 'excel'
out response
filename 'facilities'
extension 'xls'
objects Contact.list(params)
parameters([title: 'Facilities'])
fields {
name ('Name') {obj, val -> obj?.facility?.name}
abbreviation ('Abbr')
@nwwells
nwwells / _lookup.scss
Last active December 17, 2015 17:18
tuple lookup function for scss
@function lookup ($targetKey, $map, $index:2, $default:'') {
@each $entry in $map {
@if length($entry) >= $index {
$key: nth($entry, 1);
$value: nth($entry, $index);
@if $key == $targetKey {
@return $value;
}
}
}
@nwwells
nwwells / animate.js
Last active August 29, 2015 13:56
Animate
// TODO - remove dependencies on jquery, underscore, require, and backbone.
define(function (require) {
'use strict';
var _ = require('underscore');
var Backbone = require('backbone');
var transitionEnd = [
'transitionend',
'webkitTransitionEnd',
@nwwells
nwwells / gist:9500088
Created March 12, 2014 03:11
LiveReload of Express Server
grunt.registerTask('delayed-livereload', 'Live reload after the node server has restarted.', function () {
var done = this.async();
setTimeout(function () {
request.get('http://localhost:' + reloadPort + '/changed?files=' + files.join(','), function(err, res) {
var reloaded = !err && res.statusCode === 200;
if (reloaded)
grunt.log.ok('Delayed live reload successful.');
else
grunt.log.error('Unable to make a delayed live reload.');
Verifying that +nwwells is my openname (Bitcoin username). https://onename.io/nwwells
@nwwells
nwwells / keybase.md
Created March 20, 2015 02:06
keybase.md

Keybase proof

I hereby claim:

  • I am nwwells on github.
  • I am nwwells (https://keybase.io/nwwells) on keybase.
  • I have a public key whose fingerprint is B416 497C 71E3 488A 8BCA 9D30 8405 8ED9 C755 9CD1

To claim this, I am signing this object: