Skip to content

Instantly share code, notes, and snippets.

View maccman's full-sized avatar
🦜
gpu poor

Alex MacCaw maccman

🦜
gpu poor
View GitHub Profile
# Alex MacCaw
# info@eribium.org
# Paranoid Hash
# This is so you don't need to validate options on initialize - as you may not require all the options for every method.
# You can validate them as the program runs - so you don't get unexpected nils.
# I still haven't decided whether this is a good idea or not ;)
# class Foo
# attr_reader :options
# Installing a Rails Stack on EC2/Ubuntu
# based on ami-1c5db975 - see http://alestic.com/ for more info.
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install build-essential
sudo apt-get install ruby rdoc mysql-server libmysql-ruby ruby1.8-dev irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15off libnet-daemon-perl libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client-5.0 mysql-common mysql-server-5.0 ruby1.8 subversion rubygems libopenssl-ruby irb rake
# Advanced to_xml
#
# Alex MacCaw
# info@eribium.org
#
# Provide to_xml support to things like strings,
# so you can now actually do ['foo'].to_xml without
# it throwing an exception.
#
# One gotcha to look out for is Rails calls
# The first few steps I always make when creating a new Rails app
# Alex MacCaw
# info@eribium.org
# cd home
cd
# Setup your svn repo
svn mkdir your_svn_details/app_name
svn mkdir your_svn_details/app_name/trunk
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>twitter</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="Alex MacCaw">
<!-- Date: 2009-01-10 -->
class TwitterBinder < Binder::Collection
class << self
# What about filters - should they be implemented?
#
# I also feel this is lacking 'views'.
# There should be a view for the index, and the login
# There should also be an easy api in ruby/js for switching views
def index
self.items = twit.timeline(:user)
class UsersBinder < Binder::Collection
class << self
# self.items is a special method
# Basically it'll update users on the client side
def index
self.items = User.all
end
# def index(offset)
# self.items = User.all(:conditions => ['id > ?', offset])
require 'digest/sha1'
require 'net/http'
class GravatarFetcher
# Gravatar is a bit stupid, in that there's
# no way to tell if they're returning the default
# avatar - here's a hack to do that.
class << self
def fetch(email, size=60)
email_hash = Digest::MD5.hexdigest(email)
http = Net::HTTP.new("www.gravatar.com", 80)
# Simple application config.
# Create a file in config/application.yml
# with the following:
#
# :defaults: &defaults
# :app_name: MyApp
#
# :development:
# <<: *defaults
#
module ValidBrowser
# Browser restrictor
#
# You can choose whether to just display a warning,
# or disable access completely.
#
# You need to include ValidBrowser in application.rb
# You also need to install the UserAgent plugin - http://github.com/josh/useragent
#
# Example 1 - show warning: