Skip to content

Instantly share code, notes, and snippets.

View andyl's full-sized avatar
🎯
Focusing

andyl

🎯
Focusing
View GitHub Profile
require 'rubygems'
require 'parslet'
class Address < Parslet::Parser
# Single character rules
rule(:comma) { str(',') >> space? }
rule(:space) { match('\s').repeat }
rule(:space?) { space.maybe }
rule(:newline) { str("\n").repeat }
rule(:digit) { match('[0-9]') }
@andyl
andyl / address_parser.rb
Created June 4, 2011 16:34
Parslet Address Parser
#!/usr/bin/env ruby
# This script parses US mailing addresses.
#
# For development, execute this from the command line to run the test cases.
#
# For production, just require the file, then:
# address_hash = AddressParser.new.parse(input_string)
require 'rubygems'
#!/usr/bin/env ruby
# This script parses US mailing addresses.
#
# For development, execute this from the command line to run the test cases.
#
# For production, just require the file, then:
# address_hash = AddressParser.new.parse(input_string)
require 'rubygems'
<h2>Log In</h2>
<%= form_tag sessions_path do %>
<div class="field">
<%= label_tag :user_name %><br>
<%= text_field_tag :user_name, params['user_name'] %>
</div>
<p></p>
<div class="field">
<%= label_tag :password %><br/>
class SessionsController < ApplicationController
def new
if member = Member.find_by_password_digest(cookies[:digest])
session[:member_id] = member.id
redirect_to (session[:ref] || root_path), :notice => "Welcome back #{member.first_name}"
end
end
def create
class ApplicationController < ActionController::Base
protect_from_forgery
def current_ability
@current_ability ||= Ability.new(current_member)
end
rescue_from CanCan::AccessDenied do |exception|
flash[:alert] = "Access Denied."
redirect_to root_url
#!/usr/bin/env ruby
require 'rubygems'
require 'faye'
abort "Usage: #{$0} <url> <channel> <nick>" if ARGV.length != 3
$url, $channel, $nick = ARGV
$client = Faye::Client.new($url)
#!/usr/bin/env ruby
require 'rubygems'
require 'spreadsheet'
book = Spreadsheet.open 'input.xls'
sheet = book.worksheet 0
sheet[0,0] = "Changed Cell"
book.write 'output.xls'
#!/usr/bin/env ruby
require 'rubygems'
require 'spreadsheet'
book = Spreadsheet.open 'input.xls'
sheet = book.worksheet 0
sheet[0,0] = "Changed Cell"
book.write 'output.xls'
# The mail servers of many SMS gateways treat email as spam if the mails
# arrive too frequently. This has happened using the SMS-gateways managed
# by Verizon and Sprint.
#
# Maintains a queue of delivery addresses for a given carrier.
# Limits the sending frequency, to reduce the chance of being rejected as spam.
#
class CarrierQueue