Skip to content

Instantly share code, notes, and snippets.

View baldwindavid's full-sized avatar

David Baldwin baldwindavid

  • Indianapolis, IN
View GitHub Profile
@baldwindavid
baldwindavid / thesaurus.rb
Last active April 15, 2021 16:09
You'll need an API key from words.bighugelabs.com
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'cgi'
# Get a free API key at https://words.bighugelabs.com/account/getkey
API_KEY = '[YOUR API KEY HERE]'
API_VERSION = 2
WORDS_PER_LINE = 4

Keybase proof

I hereby claim:

  • I am baldwindavid on github.
  • I am baldwindavid (https://keybase.io/baldwindavid) on keybase.
  • I have a public key whose fingerprint is 4F3A C424 8315 8EF6 3CC5 DCF1 E130 F0B0 D0D2 73C2

To claim this, I am signing this object:

@baldwindavid
baldwindavid / dependent_presence_validator.rb
Created February 27, 2013 19:19
A validator that checks the presence of other related fields that should be present. It would probably always be used in conjunction with :allow_blank => true.
class DependentPresenceValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
dependents = [options[:dependents]].flatten
dependents.each do |dependent|
unless record.send(dependent).present?
record.errors.add dependent, "must not be blank when #{attribute.to_s.humanize} is present."
end
@baldwindavid
baldwindavid / gist:3229724
Created August 1, 2012 18:47
Git aliases
alias g="git"
# Log
alias gl="gitx"
# Commit: Prepare Commit in Gitx (run gitx first to refresh)
alias gc="gitx; gitx -c"
# Checkout branch
alias gco="g checkout"
if ($.browser.msie && $.browser.version == 7) {
$(function() {
var zIndexNumber = 1000;
$("div").each(function() {
$(this).css('zIndex', zIndexNumber);
zIndexNumber -= 10;
});
});
}
@baldwindavid
baldwindavid / thes.rb
Created April 10, 2012 19:42
Simple script to query thesaurus entries - Get an api key and then point to the file via bash_profile (e.g. alias thes='ruby ~/whateverpath/thes.rb)
require 'rubygems'
require 'net/http'
require 'uri'
require 'json'
require 'cgi'
# 1) Get an api key - http://words.bighugelabs.com/api.php
# 2) Point to the file via bash_profile (e.g. alias thes='ruby ~/whateverpath/thes.rb)
# 3) From command line type... thes dog or thes cool
@baldwindavid
baldwindavid / Gemfile
Created March 28, 2012 14:52
The guts of a page tree using slugs - acts_as_tree, friendly_id - Allows for routes like /about/our-people/developers
gem 'acts_as_tree'
gem "friendly_id", "~> 4.0.1"
def plan
Plan.find(plan_id)
end
def plan=(_plan)
self.plan_id = _plan.id
end
class Plan
PLANS = [
{
:id => 1,
:name => "Individual",
:can_send => true,
:amount => "???",
:interval => "month",
:trial_period_days => 30,
class User < ActiveRecord::Base
belongs_to :plan # or however you get your plan - mine is actually not in an AR model
def can_do_cool_thing?
plan.can_do_cool_thing?
end
def can_do_other_cool_thing?
plan.can_do_other_cool_thing?