Skip to content

Instantly share code, notes, and snippets.

View jwietelmann's full-sized avatar

Joel Wietelmann jwietelmann

View GitHub Profile
@jwietelmann
jwietelmann / barcamp_overlay.html
Last active August 29, 2015 14:01
RAWRRR BARCAMP OVERLAY PROOF OF CONCEPT
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
html {
background-image: url(http://www.barcampnola.com/images/splash.jpg);
background-size: cover;
}
body {
padding: 0;
layout author title
post
edward
Getting Good at Vim

I have used Vim to write code for about a year, and I can confidently say that Vim does two things for me well. The most obvious thing is that it cuts down on my text editing time. If you consider the amount of time you spend highlighting with the mouse and then returning back to the keyboard to edit text, daily, over the course of a year that time begins to adds up.
@jwietelmann
jwietelmann / FizzleBizzle.rb
Created February 18, 2012 20:04
Lazy FizzBuzz
(1..100).each do |n|
str = ""
str += "Fizz" if (n % 3).zero?
str += "Buzz" if (n % 5).zero?
puts str.empty? ? n.to_s : str
end
@jwietelmann
jwietelmann / json_helper.rb
Created March 22, 2012 21:23
Export data from Rails to JSON with optional namespacing
class JsonHelper
# Usage:
# json_register("hello", "Hello, World!")
# json_register("foo.bar", @foobar)
def json_register(name, data)
@json_registry ||= {}
pieces = name.split('.')
last = pieces.pop
@jwietelmann
jwietelmann / handlebone.js.coffee
Created July 9, 2012 17:41
Handlebars view helpers build out tree of View objects
# patched version of Handlebars with helper - passes current view to next context
Handlebars.registerHelper "with", (context, options) ->
context.view = this.view if this.view # the patch
options.fn context
# patched version of Handlebars each helper - passes current view to next context
Handlebars.registerHelper "each", (context, options) ->
fn = options.fn
inverse = options.inverse
ret = ""
@jwietelmann
jwietelmann / handlebars_helpers.coffee
Created September 25, 2012 18:26
Shared Handlebars.js helpers for both Node.js and web client
helpers =
test: (templateName) ->
"THIS IS A TEST"
addHelpers = (handlebars) -> handlebars.registerHelper name, fn for name, fn of helpers
# server-side
if module? && module.exports?
module.exports = addHelpers
models.util = {
singleSubDoc: function(schema, virtualName) {
var realName = '_' + virtualName;
schema.virtual(virtualName)
.get(function() {
if(this[realName].length) return this[realName][0];
else return null;
})
.set(function(value) {
this[realName] = [value];
var mongoose = require('mongoose');
module.exports = exports = function(schema, options) {
schema.method('massAssign', function(fields) {
for(var i in schema.tree) {
if(schema.tree[i].protect || fields[i] == null) continue;
this[i] = fields[i];
}
});
schema.static('massAssign', function(fields) {
@jwietelmann
jwietelmann / mongoose-single-subdoc.js
Created November 30, 2012 04:18
Hack to fake single subdoc field in a mongoose schema
// mongoose doesn't like single embedded schemas
// it likes them as arrays of an embedded schema
// so this is a cheater hack to fake a single subdoc
// it creates a field named `_yourField` and a virtual named `yourField`
// and it makes sure the array keeps just one element in it
// USAGE EXAMPLE:
/*
var models = require('models')
, ChildSchema = models.ChildSchema
, singleSubdoc = require('mongoose-single-subdoc');
@jwietelmann
jwietelmann / gist:4252663
Created December 10, 2012 19:17
jitsu start error
error: Error running command start
error: Nodejitsu Error (500): Internal Server Error
error: There was an error while attempting to deploy the app
error:
error: tar exited with code: 2
error: Error output from Haibu:
error:
error: Error: tar exited with code: 2
error: at ChildProcess.Tar.init (/root/haibu-orchestra/node_modules/haibu/lib/haibu/repositories/tar.js:58:26)
error: at ChildProcess.EventEmitter.emit (events.js:91:17)