Skip to content

Instantly share code, notes, and snippets.

View jens's full-sized avatar

Jens Norrgrann jens

View GitHub Profile
@jens
jens / brainwash
Last active August 29, 2015 14:07 — forked from halo/brainwash
#!/usr/bin/env ruby
require 'ipaddr'
module Brainwash
module Help
extend self
def examples
<<-END
@jens
jens / leader
Last active December 29, 2015 15:09
leader
#!/bin/bash
if [ "$#" -ne 2 ]
then
echo "Usage: leader portnumber command"
exit 1
fi
first_run=1
while :
@jens
jens / gist:7673606
Last active December 29, 2015 12:58
testar
testar
@jens
jens / forego.rb
Created November 27, 2013 10:27 — forked from guitsaru/forego.rb
require 'formula'
class Forego < ScriptFileFormula
homepage 'https://github.com/ddollar/forego'
url 'https://godist.herokuapp.com/projects/ddollar/forego/releases/0.8.2/darwin-amd64/forego'
sha1 '62f4c0cb7e48647ca7c9ef4a801f49576b577d4a'
version '0.8.2'
test do
system "#{bin}/forego", "version"
@jens
jens / gist:4709481
Created February 4, 2013 20:30
Error with sensu using chef-client v 11
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/sensu/libraries/json_file.rb
================================================================================
NoMethodError
-------------
undefined method `attribute' for Chef::Resource::JsonFile:Class
@jens
jens / prepare-commit-msg
Created September 15, 2011 13:46
Get story id from branch name and add pivotal reference to commit message
#!/usr/bin/env ruby
#
# Copy this file into .git/hooks and chmod +x
#
branchname = `git branch --no-color 2> /dev/null`[/^\* (.+)/, 1].to_s
PIVOTAL_REFERENCE = /s-(\d+)/i
if story_match = branchname.match(PIVOTAL_REFERENCE)
story_id = story_match.captures.first
reference = "[#%s]" % story_id
`echo "#{reference}"|cat - #{ARGV[0]} > /tmp/out && mv /tmp/out #{ARGV[0]}`
@jens
jens / attached_file.rb
Created May 17, 2011 21:27 — forked from mrmemes-eth/attached_file.rb
Duplicate items when using update_attributes and decent_exposure
class AttachedFile < ActiveRecord::Base
belongs_to :parent, :polymorphic => true
end
@jens
jens / attached_file.rb
Created May 17, 2011 19:25
Duplicate items when using update_attributes and decent_exposure
class AttachedFile < ActiveRecord::Base
belongs_to :parent, :polymorphic => true
end
class ShoppingCartWidget < Apotomo::Widget
include Devise::Controllers::Helpers
helper ApplicationHelper
after_add do |me, parent|
me.root.respond_to_event :item_removed, :with => :redraw, :on => me.name
end
has_widgets do |me|
@user = User.find(param(:user))
class Product
include Mongoid::Document
field :name
embeds_many :product_items
has_many_related :articles
def update_product_items
product_items.destroy_all
articles.all.each do |a|