Skip to content

Instantly share code, notes, and snippets.

@sneakin
sneakin / gist:70270
Created February 25, 2009 16:55
#attributes_for – Provides accessors for associated records.
# Copyright (C) 2009 SemanticGap(R)
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
@sneakin
sneakin / do_action_generator.rb
Created February 25, 2009 19:32
rSpec macro to help w/ controller action specs
# Copyright (C) 2009 SemanticGap(R)
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
@sneakin
sneakin / rubyfu_kindness.rb
Created March 24, 2009 03:23
rubyfu_kind_of.rb – Extends Object.kind_of? and Class to allow `3.kind_of?(String | Fixnum)` type magic or by doing `3.kind_of?(String, Fixnum)`
# rubyfu_kind_of.rb
# Extends Object.kind_of? and Class to allow `3.kind_of?(String | Fixnum)`
# type magic or by doing `3.kind_of?(String, Fixnum)`
#
# Copyright (C) 2009 Nolan Eakins
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
@sneakin
sneakin / hash_remap.rb
Created April 6, 2009 19:49
Hash#remap – alters a Hash's keys using a supplied mapping.
class Hash
# Given a hash that maps keys to the new key, this method will return a new
# Hash whose keys are contained in the map Hash, but whose values come from
# the Hash #remap was called on.
#
# Ex: { 1 => 2, 2 => 3 }.remap(1 => 100, 2 => 200) # => { 100 => 2, 200 => 3 }
#
def remap(mapping)
ret = Hash.new
mapping.each do |src, dest|
@sneakin
sneakin / rubyfu_speling.rb
Created April 7, 2009 02:13
Overrides #method_missing and #const_missing to resolve mispeled methods and constants
# rubyfu_speling.rb
# Overrides #method_missing and #const_missing to resolve
# mispeled methods and constants.
#
# Copyright (C) 2009 Nolan Eakins
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
@sneakin
sneakin / rubyfu_speling.rb
Created April 7, 2009 16:45 — forked from sneakin/rubyfu_speling.rb
rubyfu_speling.rb – Overrides #method_missing and #const_missing to resolve mispeled methods and constants.
# rubyfu_speling.rb
# Overrides #method_missing and #const_missing to resolve
# mispeled methods and constants.
#
# Copyright (C) 2009 Nolan Eakins
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
@sneakin
sneakin / .gitignore
Created August 30, 2009 17:22
Basic arithmetic parser & evaluator using RACC
*~
*.tab.rb
coverage
<html>
<head>
<script src="http://trooptrack.com/javascripts/jquery.js?1260408052" type="text/javascript"></script>
<script src="http://trooptrack.com/javascripts/jquery.ui.all.js?1260408052" type="text/javascript"></script>
<script src="http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/scripts/date.js" type="text/javascript"></script>
<script src="http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/scripts/jquery.datePicker.js" type="text/javascript"></script>
<script type="text/javascript">
$(window).load(function() {
$(".input_date").datePicker();
});
@sneakin
sneakin / ff.rb
Created February 13, 2010 18:08
FriendFeed archiver
#!/usr/bin/ruby
# FriendFeed archiver [with duct tape]
#
# Usage: ruby $0 command user [dir]
# command: "now" or "backup"
# "now" stores the present, "backup" the past
# user: user name to archive to dir
# dir: directory to store entries, defaults to "./friendfeed"
require 'httparty'
class Doc
class Base
def read; end
def destroy!; end
end
class File < Base
# operates on a file
end