Skip to content

Instantly share code, notes, and snippets.

View ckdake's full-sized avatar

Chris Kelly ckdake

View GitHub Profile
@ckdake
ckdake / consistomatic.rb
Created July 20, 2010 16:03
tool to update zones in a dynect platform account based on a config file
require 'rubygems'
require 'dynect_rest'
#config.rb contains config values. example:
# ACCOUNT = "demo-demo"
# USER = "demo"
# PASS = "demo"
# SOACONTACT = "admin.demo"
require 'config.rb'
@ckdake
ckdake / redis_
Created October 15, 2010 21:47
munin plugin for monitoring redis
#!/usr/bin/perl -w
#
## Copyright (C) 2009 Gleb Voronich <http://stanly.net.ua/>, 2010 Chris Kelly <http://ckdake.com/>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; version 2 dated June,
## 1991.
##
@ckdake
ckdake / Gemfile
Created November 2, 2010 18:22
stub for linking with and posting to facebook from rails apps
gem 'rest-client'
gem 'json'
@ckdake
ckdake / Gemfile
Created November 4, 2010 18:09
stub for linking with and posting to twitter from rails apps
gem 'oauth'
gem 'twitter', :git => 'git://github.com/jnunemaker/twitter.git'
# copyright 2002 Chris Kelly ckdake@ckdake.com
main:
.data
str1: .asciiz "What are these?\n"
brk: .asciiz "\n"
start: .byte 0
.text
module DeviseHelper
def devise_error_messages!
unless resource.errors.empty?
content_tag :div, :id => "error_explanation", :escape => false do
content_tag(:h2, "The following errors were encountered:") +
content_tag(:ul, resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join.html_safe)
end.html_safe
end
end
end
@ckdake
ckdake / gist:784743
Created January 18, 2011 16:55
find_or_create_tree_by_name
# Addon for classes using https://github.com/stefankroes/ancestry
# Create the full tree for this root/parent/child if it doesnt yet exist
# .save! is required to generate ancestry fields so that .children works
def self.find_or_create_tree_by_name(root_name = nil, parent_name = nil, child_name = nil)
if root_name.present?
root = self.find_or_create_by_name(root_name)
root.save!
if parent_name.present?
parent = root.children.find_or_create_by_name(parent_name)
parent.save!
// Form dirtyness tracking
$('form *').change( function() {
window.formDirty = true;
});
$('form input').click( function() {
if (this.name == "commit") {
window.formDirty = false;
}
});
window.onbeforeunload = function() {
@ckdake
ckdake / clone_with_modifications.rb
Created January 27, 2011 19:11
monkey patch to Ancestry to add tree cloning
module Ancestry
# https://github.com/stefankroes/ancestry
module InstanceMethods
# Clone an object and all children
# => replacing values with those from attributes if present
# => setting parent to new parent if present
# => setting the "original_id_field_name" if present to the id of the original object
#
# Example use_case:
ruby-1.9.2-p0 adella:benchmarks$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.5.0]
ruby-1.9.2-p0 adella:benchmarks$ php -v
PHP 5.3.3 (cli) (built: Aug 22 2010 19:41:55)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
ruby-1.9.2-p0 adella:benchmarks$ cat foo.rb
msg = "Hello world"