Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am mikezter on github.
* I am mikezter (https://keybase.io/mikezter) on keybase.
* I have a public key whose fingerprint is F0B9 2EEA 086C 43D5 F894 B4AF 70EA 19A2 7908 F63A
To claim this, I am signing this object:
@mikezter
mikezter / remote_link_renderer.rb
Created May 29, 2009 09:37
AJAX link renderer for WillPaginate
@mikezter
mikezter / template_identification.rb
Created January 20, 2010 11:52
Add Template Identification HTML Comments to ERB output in Rails
# Add Template Identification HTML Comments to ERB output
module ::ActionView
module TemplateHandlers
class ERB < TemplateHandler
include Compilable
cattr_accessor :erb_trim_mode
self.erb_trim_mode = '-'
def compile(template)
buf = <<-HTML
<% unless request and request.xhr? %>
@mikezter
mikezter / update_single_attribute.rb
Created February 22, 2010 17:40
update a single attribute on dirty ActiveRecords
module ActiveRecord
class Base
# updates a single attribute on the record directly to the database using
# ActiveRecord::Base.update_all
def update_single_attribute(name, value)
write_attribute(name, value)
self.class.update_all({name => value}, {self.class.primary_key => read_attribute(self.class.primary_key)}, {:limit => 1})
end
end
end
@mikezter
mikezter / gist:403561
Created May 17, 2010 09:12 — forked from tpitale/gist:162954
mongodb init script
#! /bin/sh
### BEGIN INIT INFO
# Provides: mongodb
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the mongodb data-store
# Description: starts mongodb using start-stop-daemon
@mikezter
mikezter / .bashrc
Created August 13, 2010 10:33
my .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# ANSI color codes
@mikezter
mikezter / dynamic_attributes.rb
Created August 31, 2010 09:00
Allow an ActiveRecord to behave like a schemaless document
module DynamicAttributes
class DynamicAttributesError < StandardError; end;
def self.included(base)
base.send(:include, InstanceMethods)
base.send(:extend, ClassMethods)
end
module ClassMethods
@mikezter
mikezter / r_open_struct.rb
Created September 3, 2010 17:47
Recursive OpenStruct
require 'ostruct'
class ROpenStruct < OpenStruct
def table
@table ||= {}
end
def method_missing(mid, *args)
mname = mid.id2name
len = args.length
@mikezter
mikezter / application_controller.rb
Created September 10, 2010 09:01
Very simple logging of bot crawls in your Rails app. Drops to imedo.de
# drops to imedo.de
class ApplicationController < ActionController::Base
around_filter :log_crawlers, :unless => :logged_in?
def log_crawlers
action_start = Time.now
yield
duration = Time.now - action_start
Crawling.log(request, duration)
end
end
@mikezter
mikezter / HDCP MASTER KEY
Created September 15, 2010 00:21
HDCP MASTER KEY
HDCP MASTER KEY (MIRROR THIS TEXT!)
This is a forty times forty element matrix of fifty-six bit
hexadecimal numbers.
To generate a source key, take a forty-bit number that (in
binary) consists of twenty ones and twenty zeroes; this is
the source KSV. Add together those twenty rows of the matrix
that correspond to the ones in the KSV (with the lowest bit
in the KSV corresponding to the first row), taking all elements