Public Gists by jtrupiano

Gravatar
Mon Oct 26 13:24:12 -0700 2009
1
2
3
# Add method to get all setters for a given object. Useful when learning a poorly-documented library.
class Object
  def setters
Gravatar
Mon Oct 26 13:22:44 -0700 2009
1
2
3
# When prying into new libraries, I find this useful to quickly find out what top-level constants
# the given library introduces.
#
gist: 208916 A rack middleware for defin...
Gravatar
Mon Oct 12 19:33:28 -0700 2009
1
2
3
# This is actually available as a gem: gem install rack-rewrite
# Full source code including tests is on github: http://github.com/jtrupiano/rack-rewrite
 
Gravatar
Wed Oct 07 08:30:14 -0700 2009
1
2
# Find all files > 1M in or beneath the current directory
find . -size +1M -printf "%-10s %p\n"
gist: 127636 Shell Script to Upgrade Rub...
Gravatar
Wed Jun 10 18:14:15 -0700 2009
1
2
3
#!/bin/sh
# Author: John Trupiano
# Script to upgrade an REE installation on a hot server and maintain sane directory names
Gravatar
Sun May 17 12:00:37 -0700 2009
1
2
3
require 'mocha'
 
# Used such that the named_scope chain will return a count of 0 to allow us to test "empty" messages in views
Gravatar
Tue May 12 17:39:18 -0700 2009
1
2
3
1) Ensure apache is enabled
2) Edit /etc/apache2/users/<yourusername>.conf
  NameVirtualHost *:80
Gravatar
Mon May 04 07:27:18 -0700 2009
1
2
3
# Custom shoulda macro example -- validating POST data in a controller
 
# The macro -- note that it references a create_user() function. This function is included beneath the macro
Gravatar
Mon May 04 07:12:04 -0700 2009
1
2
3
// My common scenario is that I need to compare a single Patient to a set of Donors, basically performing the equiavalent to Enumerable#all? in Ruby.
 
// To fully understand this example, realize that the NodeData object contains a single Patient and one or more Donors. When looping, we're comparing one NodeData's Patient with a separate NodeData's list of Donors.
Gravatar
Mon Apr 20 17:16:04 -0700 2009
1
2
3
def flatten(lst: List[Any]): List[Any] = {
  lst match {
    case Nil => List[Any]()
Gravatar
Mon Apr 20 16:22:39 -0700 2009
1
2
3
def length(lst: List[Int]): Int = {
  lst match {
    case Nil => 0
Gravatar
Mon Apr 20 16:10:09 -0700 2009
1
2
3
def nth(n:Int, lst: List[Int]): Int = {
  if (n == 0) {
    return lst.head