Skip to content

Instantly share code, notes, and snippets.

View niklas's full-sized avatar

Niklas H niklas

View GitHub Profile
@niklas
niklas / ember-data-create-error-handling.coffee
Created October 30, 2012 17:50
HowTo create a DS.Model from ember-data, handling server-side validation errors
# If we save a record using ember-data's RESTadapter, and it fails, Rails
# returns the validation errors of the model as JSON hash:
#
# {"errors":{"name":["may not be blank"]}}
#
# This patches the RESTadapter to add these errors to the invalid record. It
# can be removed when the following Pull Request was merged into ember-data:
# https://github.com/emberjs/data/pull/376
DS.RESTAdapter.reopen
@niklas
niklas / fetch_facts.sh
Created October 23, 2012 18:57
Fetch facter facts from a remote host and convert to be used in cucumber-puppet
#!/bin/bash
host=$1
if [ -z "$host" ]; then
echo "please provide hostname for node to fetch facts from"
exit
fi
file="features/nodes/$host.yaml"
@niklas
niklas / pivotal2kanbanery.rb
Created August 8, 2012 11:49
Migrate from pivotal tracker to kanbanery
#!/usr/bin/env ruby
# Converts PivotalTracker's (PT) export CSV in a CSV kanbanery (KB) accepts to import.
#
# Features:
# * maps PT's states to KB's columns, see $mapper
# * story types are converted
#
# Bugs:
# * comments are not imported
@niklas
niklas / pause_steps.rb
Created May 4, 2012 10:35
Pause a cucumber scenario and ask for pry
When /^I pause|try pry|I pry|I debug$/ do
STDERR.puts "Pausing..."
if system(%Q~which zenity~)
if system(%Q~zenity --question --text="Paused. Want to pry?"~)
binding.pry
end
else
# no zenity installed, pry without asking
binding.pry
end
@niklas
niklas / plot_tekway.rb
Created March 11, 2012 14:33
434 Mhz grau
PPo00011110101010001111111110000001o
PPo00011110101010001111111100000011o
PPo00011110101010001111111110000011o
PPo00011110101010001111111110000000o
PPo00011110101010001111111110000000o
PPo00011110101010001111111100000000o
PPo00011110101010001111111110000010o
{"1000"=>"0", "1110"=>"1", "1111"=>"P", "0000"=>"o"}
@niklas
niklas / draper_rjs.rb
Created February 22, 2012 22:54
# make the RJS helper proxy `page` available in Draper's Decorator
# in your .js.rjs templates, you can call #decorate on the magic page object
# and then use RJS-powered methods from within your Decorator
#
# page.decorate User.first do |user|
# user.blink
# end
#
# class UserDecorator < ApplicationDecorator
# def blink
# page[ "user_#{model.id}" ].animate 'blink'
@niklas
niklas / gist:1344547
Created November 7, 2011 09:35 — forked from rsanheim/gist:1054078
Devise + Spork + Rails 3.1 RC4 hacks to keep User model from loading prefork
Spork.prefork do
require "rails/application"
# Prevent Devise from loading the User model super early with it's route hacks for Rails 3.1 rc4
# see also: https://github.com/sporkrb/spork/wiki/Spork.trap_method-Jujutsu
Spork.trap_method(Rails::Application, :reload_routes!)
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
# rest of your prefork here...
end
@niklas
niklas / _flash.html.haml
Created November 2, 2011 10:35
render 'flash', :flash => flash # from layout, file put in app/views/application
- unless flash.blank?
#flash
- flash.each do |name, msg|
= content_tag :div, msg, :class => "flash #{name}
@niklas
niklas / define_eigenclass_method_with_closure.rb
Created September 8, 2011 12:15
define Eigenclass method with closure
class Object
def eigenclass
class << self; self; end
end
def eigenclass_eval(&block)
eigenclass.instance_eval &block
end
end
current_scheduler = scheduler(:availabilities)
def current_scheduler.handle_exception(job, exception)
Airbrake.do_the_right_thing(exception, other_params)
puts "job #{job.job_id} caught exception '#{exception}' - the Airbrake has been triggered"
end
class TaskManager
# [..]
# do you think this may work? (hoptoad_options scope)