Skip to content

Instantly share code, notes, and snippets.

View rbazinet's full-sized avatar

Rob Bazinet rbazinet

View GitHub Profile
-- data structure for RGBA, RGB & CMYK colors
data Color = RGBA Float Float Float Float
| RGB Float Float Float
| CMYK Float Float Float Float
deriving (Eq, Ord, Show)
-- list of colors
colors = [ RGBA 0.1 0.1 0.5 0.2
, RGBA 1 1 0 0.9
, RGB 0.5 0.5 0
# http://www.jamesbritt.com/2007/12/18/sending-mail-through-gmail-with-ruby-s-net-smtp
# http://d.hatena.ne.jp/zorio/20060416
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
# download, from_repo, and commit_state methods swiped from
# http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
class KeyGenerator
require "digest/sha1"
def self.generate(length = 10)
Digest::SHA1.hexdigest(Time.now.to_s + rand(12341234).to_s)[1..length]
end
end
# Use ApiKey.generate to generate a new API key
class ApiKey < ActiveRecord::Base
validates_presence_of :key
validates_uniqueness_of :key
def self.generate(description = "No description")
key = Digest::SHA1.hexdigest("--#{Time.now}--#{description}--")
ApiKey.create(:description => description, :key => key)
end
Rails CMS alternatives
======================
Active projects:
---------------
adva-cms
repo: http://github.com/svenfuchs/adva_cms/
site: http://adva-cms.org/
Last update: 11/24/09
"the cutting edge Rails CMS platform"
# Host based routing - enables routes like:
# map.connect '', :controller => 'blah', :action => 'blah', :conditions => {:host => 'blah'}
#
# Put this file in /config/initializers
module ActionController
module Routing
class Route
def recognition_conditions_with_host
result = recognition_conditions_without_host
public static class ListExtensions {
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> collection, Action<T> action) {
foreach (var item in collection) action(item);
return collection;
}
public static SelectList ToSelectList<T>(this IEnumerable<T> collection) {
return new SelectList(collection, "Key", "Value");
}
public static class ListHelpers {
public static void Repeater<T>(this HtmlHelper html
, IEnumerable<T> items
, Action<T> render
, Action<T> renderAlt) {
if (items == null)
return;
int i = 0;
# Everything you need to do to get started with Rails 2.3.8
#
# As of June 14th, 2010 @ 2:30 p.m. MST
#
# This gist now features instructions to get Rails 3 up and running with:
# - Ruby 1.8.7-p174
# - Bundler 0.9.26
# - Cucumber 0.8.0
# - Rspec 1.3.0 + Rspec-Rails 1.3.2
# - RVM