Public Gists by pjb3

Gravatar
Thu Nov 19 19:24:11 -0800 2009
1
2
3
class LinkedList
  include Enumerable
  Node = Struct.new(:head, :tail)
Gravatar
Tue Nov 17 21:36:14 -0800 2009
1
2
3
irb(main):004:0> Enumerable.instance_methods.sort
=> ["all?", "any?", "collect", "detect", "each_with_index", "entries", "find", "find_all", "grep", "include?", "inject", "map", "max", "member?", "min", "partition", "reject", "select", "sort", "sort_by", "to_a", "zip"]
irb(main):005:0> RUBY_VERSION
Gravatar
Fri Nov 06 21:12:12 -0800 2009
1
2
3
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
Gravatar
Wed Oct 28 12:21:43 -0700 2009
1
2
3
def self.[](*args)
  if args.size > 1
    args.map{|e| self[e] }
Gravatar
Mon Oct 26 13:13:34 -0700 2009
1
2
3
$$('#listholder li').each(function(item, index){
  var url = item.getElement('a').get('href')
  item.addEvent('click', function() {
Gravatar
Mon Oct 12 09:44:07 -0700 2009
1
2
3
<html>
  <head>
    <title>JQuery and links - strange situation</title>
Gravatar
Fri Oct 02 22:10:41 -0700 2009
1
2
3
(defn
  #^{:test (fn []
      (assert (= {:x 1} (assoc-conj {} :x 1)))
Gravatar
Wed Sep 23 19:29:20 -0700 2009
1
2
3
run "cd public/javascripts; curl -L -o ext.zip http://www.extjs.com/products/extjs/download.php?dl=extjs3"
run "cd public/javascripts; unzip ext.zip"
ext_dir_name = File.basename(Dir["public/javascripts/ext-*"].first)
Gravatar
Sun Jul 26 13:17:02 -0700 2009
1
2
3
class WeblogController < ActionController::Base
  def index
    @posts = Post.find :all
Gravatar
Tue Jul 21 06:15:46 -0700 2009
1
2
3
module HashExtensions
  def symbolize_keys
    inject({}) do |acc, (k,v)|
Gravatar
Wed Jul 15 06:43:38 -0700 2009
1
2
3
def run_block
  yield(1,2,3,4)
end
Gravatar
Sat Jul 11 11:39:33 -0700 2009
1
2
3
package com.liftworkshop.model
 
import net.liftweb._
Gravatar
Mon Jul 06 21:31:35 -0700 2009
1
2
3
def format_time_interval(from_time, to_time)
  seconds = (to_time - from_time).abs.round
  minutes, seconds = seconds.divmod(60)
Gravatar
Sat Jul 04 07:45:37 -0700 2009
1
2
3
From 0f7a7fdef7ab63dc62b950ff7487d257a326cf8c Mon Sep 17 00:00:00 2001
From: Paul Barry <mail@paulbarry.com>
Date: Sat, 4 Jul 2009 10:35:59 -0400
Gravatar
Wed Jul 01 14:21:09 -0700 2009
1
2
3
class Object
  def call
    self
Gravatar
Sat Jun 27 19:27:19 -0700 2009
1
2
3
= f.cms_text_field :name
= f.cms_drop_down :handler, ActionView::Template.template_handler_extensions, :default => "haml"
= f.cms_text_area :template, :default_value => @block.class.default_template
Gravatar
Fri Jun 26 23:01:30 -0700 2009
1
2
3
namespace :load do
 
  ZIP_CODE_DATA_URL = 'http://www.census.gov/tiger/tms/gazetteer/zips.txt'
Gravatar
Sun Jun 14 13:55:32 -0700 2009
1
2
3
def rgb_hex_to_dec(rgb)
  if m = rgb.match(/#([a-zA-Z0-9]{2,})([a-zA-Z0-9]{2,})([a-zA-Z0-9]{2,})/)
    "%0.2f %0.2f %0.2f" % m.captures.map{|hex| hex.to_i(16) / 255.0}
Gravatar
Sat Jun 13 11:29:20 -0700 2009
1
2
3
class FooBar
  define_method("[GET] /") do
    "Apparently Ruby methods can have spaces and other weird characters in their name"
Gravatar
Mon Jun 08 20:14:46 -0700 2009
1
2
3
Prelude> let numberOfAttendeesToAnyGivenLanguageGroup totalNumberOfAttendeesAtTheFirstMeeting meetingNumber = round $ totalNumberOfAttendeesAtTheFirstMeeting ** (1/meetingNumber)
Prelude> map (numberOfAttendeesToAnyGivenLanguageGroup 16) [1..12]
[16,4,3,2,2,2,1,1,1,1,1,1]