Skip to content

Instantly share code, notes, and snippets.

voxdolo /
Created Oct 15, 2020
Programatically export and/or delete Heroku dataclips
#!/usr/bin/env bash
# there were a handful of clips that I didn't want to delete versus hundreds that I did,
# so I just removed the UUIDs of the clips I wanted to keep from uuids.txt by hand
cat uuids.txt | while read uuid
curl \
-H "authorization: Bearer $(heroku auth:token)" \
-H "content-type: application/json" \
View gist:4211367
(ns hackerfews.core
2 (:require [net.cgrand.enlive-html :as html]))
4 (def url ( ""))
6 (defn titles
7 [docx] (flatten (map :content (html/select docx [:td.title :a]))))
9 (defn numbers-in-nodes
10 [docx selector] (let [x (flatten (map :content (html/select docx selector)))]
View view_helpers.rb
module ClearEyes
module ViewHelpers
def self.included(base)
base.send(:attr_accessor, :image, :options)
def r_image( pixel_ratio )
insert_on = -File.extname(self.image).size-1
image_tag(self.image.insert(insert_on, "@#{pixel_ratio}x"), self.options)
voxdolo / decent_decorator.rb
Created Jun 1, 2012
Simple monkey patch for decent_exposure's nu_nu branch to add automatic decoration of singular resources. Throw this in config/initializers and monkey patch your way to victory! Assumes a module like the one included.
View decent_decorator.rb
class DecentExposure::ActiveRecord::Finder
def decorated_singular_resource
rescue NameError
def resource
if plural?
voxdolo / attached_file.rb
Created May 17, 2011 — forked from jens/attached_file.rb
Duplicate items when using update_attributes and decent_exposure
View attached_file.rb
class AttachedFile < ActiveRecord::Base
belongs_to :parent, :polymorphic => true
voxdolo / scope_steps.rb
Created Mar 30, 2011
Scope assertions to portions of the page
View scope_steps.rb
module SectionLocator
def within_parent(content, elements = ['*'], &block)
expr = %(//*[(#{elements.join('|')})/descendant-or-self::*[contains(., "#{content}")]])
within(:xpath, expr, &block)
def within_parent_preceding(content, elements = ['*'], &block)
expr = %(//*[(#{elements.join('|')})[contains(., "#{content}")]]/..)
within(:xpath, expr, &block)
voxdolo / cancan_exposure.rb
Created Mar 28, 2011
A default exposure for decent_exposure that assigns instance variables (to make cancan happy)
View cancan_exposure.rb
default_exposure do |name|
collection = name.to_s.pluralize
if respond_to?(collection) && collection != name.to_s && send(collection).respond_to?(:scoped)
proxy = send(collection)
proxy = name.to_s.classify.constantize
instance_variable_set("@#{name}") = if id = params["#{name}_id"] || params[:id]
proxy.find(id).tap do |r|
voxdolo / _session_output.irb
Created Jan 20, 2011
Confusing Mongoid output - full source from examples below at:
View _session_output.irb
ruby-1.9.2-p0 :026 > s = Session.create
=> #<Session _id: 4d3845f0c1037b05f3000005, created_at: 2011-01-20 14:25:52 UTC, updated_at: 2011-01-20 14:25:52 UTC, name: "aa", custom: nil>
ruby-1.9.2-p0 :027 > s.timers <<
=> [#<Pomodoro _id: 4d384601c1037b05f3000006, created_at: 2011-01-20 14:26:09 UTC, updated_at: 2011-01-20 14:26:09 UTC, duration: 1500>]
ruby-1.9.2-p0 :028 > s.timers.count
=> 1
ruby-1.9.2-p0 :029 > s.reload
=> #<Session _id: 4d3845f0c1037b05f3000005, created_at: 2011-01-20 14:25:52 UTC, updated_at: 2011-01-20 14:25:52 UTC, name: "aa", custom: nil>
ruby-1.9.2-p0 :030 > s.pomodoros.count
=> 0
voxdolo / btelles-master-rspec-output.txt
Created Dec 3, 2010
RSpec run output. Rubies: 1.8.7p302 and 1.9.2-p0.
View btelles-master-rspec-output.txt
(in /Users/voxdolo/dev/decent_exposure)
DecentExposure classes extending DecentExposure
- should respond to #expose
- should respond to #default_exposure
- creates a method with the given name
- prevents the method from being a callable action
- declares the method as a helper method
voxdolo /
Created Oct 7, 2010
error after running rake cucumber. using ruby 1.9.2p0, rails 3, rspec 2.0.0rc
/Users/dev/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:566:in `block in process_args': invalid option:
--profile (OptionParser::InvalidOption)
from /Users/dev/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:545:in `new'
from /Users/dev/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:545:in `process_args'
from /Users/dev/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:576:in `run'
from /Users/dev/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/minitest/unit.rb:492:in `block in autorun'
(in /Users/dev/hashrocket/heatusa)
You can’t perform that action at this time.