Skip to content

Instantly share code, notes, and snippets.

View kylefox's full-sized avatar
🥊
programming

Kyle Fox kylefox

🥊
programming
View GitHub Profile
# Using Jamis Buck's routing tricks (http://github.com/rsl/routing_tricks)
ActionController::Routing::Routes.draw do |map|
# These routes only get loaded on exam_admin.com
map.namespace :admin, :path_prefix => '', :conditions => {:domain => "exam_admin.com"} do |admin|
admin.connect "/", :controller => "user"
admin.resources :exams
end
# From http://lojic.com/blog/2009/02/26/setup-shoulda-and-rcov-for-rails-222/
namespace :test do
desc 'Measures test coverage'
task :coverage do
rm_f "coverage"
rm_f "coverage.data"
rcov = "rcov -Itest --rails --aggregate coverage.data -x \" rubygems/*,/Library/Ruby/Site/*,gems/*,rcov*\""
system("#{rcov} test/unit/*_test.rb")
system("#{rcov} test/functional/admin/*_test.rb")
system("#{rcov} --html test/integration/admin/*_test.rb")
private function onImageLoaded ( e : Event ) : void
{
// get bitmap from loader;
var image : Bitmap = Bitmap( m_loader.content );
// get bitmap data from loaded image;
var bmd : BitmapData = image.bitmapData;
// create image from bitmap data;
m_image = new Bitmap( bmd );
def create
@upload = FileUpload.new(:site_id => @current_site.id, :upload => params[:Filedata])
if @upload.save
render :partial => 'file_upload', :object => @upload
else
render :text => @upload.errors.join(", "), :status => :invalid
end
end
class Photo < ActiveRecord::Base
belongs_to :user
belongs_to :blog :through => :user
has_attached_file :image,
:storage => :s3,
:styles => {
:large => "900x600",
:medium => "500x500",
:small => "240x240",
:square => "100x100#"}
It sounds like you have may have multiple Unfuddle accounts. Is this true? If so, you should
note that due to the way SSH and Git work, it is not possible to use a single public key for
multiple accounts. You may have been able to do this previously if your accounts were on
separate servers. However, we recently updated our servers which necessitated moving accounts.
In any case, you should be able to create a new SSH key easily. Be sure to give your new key
a unique name then add the following lines to your ~/.ssh/config file:
Host youraccount.unfuddle.com
User git
# Simple script to determine name, lat/long and timezone of a place name.
import urllib2
import pytz
import json
from geocoders.geonames import geocode
def get_timezone(lat, lng):
url = "http://ws.geonames.org/timezoneJSON?lat=%s&lng=%s" % (lat, lng)
data = urllib2.urlopen(url)
return pytz.timezone(json.load(data)[u'timezoneId'])
# A script to calculate some basic stats on Grant Hutchinson's haircuts.
# See http://splorp.com/about/haircut/
#
# Sample output:
# Number of haircuts since December 22, 1998: 53
# Average days between haircuts: 77
# Shortest time between haircuts was April 10, 1999 to May 25, 1999 (45 days)
# Longest time between haircuts was August 11, 2007 to December 09, 2007 (120 days)
# You'll probably want a haircut in about 63 days (March 08, 2010)
# Used like this in your model: validates_format_of :email, :with => RFC822::EmailAddress
#
# RFC822 Email Address Regex
# --------------------------
#
# Originally written by Cal Henderson
# c.f. http://iamcal.com/publish/articles/php/parsing_email/
#
# Translated to Ruby by Tim Fletcher, with changes suggested by Dan Kubb.
# Assume a Post belongs to a Blog.
# Django does this with one SQL statement:
posts = Post.objects.filter(blog__name="My Blog")
# Rails:
posts = Blog.find_by_name("My Blog").posts
# Rails?
posts = Post.where(:blog__name => 'My Blog')