Skip to content

Instantly share code, notes, and snippets.

View lancejpollard's full-sized avatar
😍
Lots of coding

Lance Pollard lancejpollard

😍
Lots of coding
View GitHub Profile
// http://nodejs.org/api.html#_child_processes
var sys = require('sys')
var exec = require('child_process').exec;
var child;
// executes `pwd`
child = exec("pwd", function (error, stdout, stderr) {
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr);
if (error !== null) {
# parse ruby log message
# customize as needed
LOG_EXPRESSION = /([\w]+),\s+\[([^\]\s]+)\s+#([^\]]+)]\s+(\w+)\s+--\s+(\w+)?:\s+(.+)/
# sample log output from this call:
# logger.info("Ubiquitously") { "[dequeud] #{JSON.generate(params)}"}
string = 'I, [2010-08-15T16:16:46.142801 #81977] INFO -- Ubiquitously: {"title":"Google","url":"google.com","tags":"search, google, api","services":["meta_filter","mixx"],"description":"a search engine!"}'
sample_output.gsub(LOG_EXPRESSION) do |match|
severity = $1
require 'rubygems'
require 'uri'
require 'mechanize'
require 'rack/utils'
# so you can do `params.inspect` throughout Mechanize
class NilClass; def search(*args); []; end; end
Mechanize::Chain::PostConnectHook.class_eval do
<article>
<header>
<h1>Where is the "content" HTML5 tag?!?</h1>
<h2>We Need Better HTML Tags for better markup!</h2>
<meta>
<time class='published'></time>
<meter>4.7 stars</meter>
<keywords>html, standards</keywords>
</meta>
</header>
<!--
Example "ARTICLE" in "semantically ideal" and "optimized" versions
-->
<!-- ideal semantic version -->
<article>
<header>
<hgroup>
<h1></h1>
<h2></h2>
</hgroup>
site do
# menu
menu "main" do
link "/", "Home"
link "/blog", "Blog"
# link "/portfolio", "Portfolio"
link "http://lancepollard.info/", "Resume"
end
# javascripts
{"site.feed.formats"=>
#<Cockpit::Definition:0x2510034
@key="formats",
@nested=false,
@value=["rss", "atom"]>,
"site.time_zone"=>
#<Cockpit::Definition:0x2510494
@key="time_zone",
module ActiveRecord
module Associations
class HasManyThroughAssociation < HasManyAssociation
protected
# added support for STI with polymorphism
def construct_conditions
table_name = @reflection.through_reflection.quoted_table_name
conditions = construct_quoted_owner_attributes(@reflection.through_reflection).map do |attr, value|
if attr =~ /_type$/
construct_polymorphic_sql(table_name, attr)
def select_attributes(*names)
return nil if names.blank?
conditions = names.extract_options!
as = conditions.delete(:as)
if self.column_names.include?("type")
conditions[:type] = (Array(conditions[:type]) + [self.name, self.base_class.name]).compact.uniq
end
conditions = conditions.keys.map do |key|
value = Array(conditions[key]).map { |v| Array(v.to_s).map { |i| self.quote_value(i) } }.uniq.join(",")
@lancejpollard
lancejpollard / format_attributes.rb
Created December 3, 2010 20:20
Format attributes when they are set in ActiveRecord
module FormatAttribute
unloadable
def self.included(base)
base.class_eval do
class << self
# format :cash, :except => "$"
# format :date do |value|
# Date.parse(value)
# end