Skip to content

Instantly share code, notes, and snippets.

!!!
%html
%head
%style(type="text/css")
:plain
body {
color: blue;
background: yellow;
}
%body
@bhauman
bhauman / minidress.rb
Created February 11, 2010 03:28 — forked from stephencelis/minidress.rb
Minidress a lightweight factory_girl which will work outside of Rails(I use it with jruby_appengine/Sinatra)
# the more proper miniskirt who doesn't have to walk the rails
class Minidress
@@factories = {}
class << self
def define(name, &block)
@@factories[name.to_s] = block
end
def build(name, attrs = {})
Debugger entered--Lisp error: (error "Command attempted to use minibuffer while in minibuffer")
execute-extended-command(nil)
call-interactively(execute-extended-command nil nil)
@bhauman
bhauman / image.rb
Created February 14, 2010 00:43
Adding Height and Width to paperclip uploads
class Image < ActiveRecord::Base
before_create, :set_width_and_height
has_attached_file :img,
:url => "/system/images/:attachment/:id/:basename.:extension",
:path => "#{Rails.root}/public/system/images/:attachment/:id/:basename.:extension"
def set_width_and_height
# this next line is the magic line
geo = Paperclip::Geometry.from_file(img.to_file(:original))
Factory.define :business_user, :parent => :user do |i|
def i.build_some_outlets
(1..5).collect {|x| Factory.build(:outlet_without_user) }
end
i.outlets { i.build_some_outlets }
i.sequence(:name) {|n| "Business User #{n}" }
i.is_business true
end
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
// This is a port of the prototype.js PeriodcialExecuter
// This should be framework independent
// Valuable if you like to/have to program in jQuery
function PeriodicalExecuter(callback, frequency) {
this.callback = callback;
this.frequency = frequency;
this.currentlyExecuting = false;
this.registerCallback();
}
require 'rubygems'
require 'amqp'
require 'mq'
AMQP.start(:host => 'localhost' ) do
q = MQ.new.queue('tasks')
q.subscribe do |msg|
puts msg
end
end
require 'rubygems'
require 'carrot'
q = Carrot.queue('tasks')
10.times {|x| q.publish('Message number ' + x.to_s) }
width = 200
height = 200
mag = MiniMagick::Image.from_file( file_path )
mag.combine_options do |i|
i.resize "#{width}x#{height}^"
i.gravity 'Center'
i.extent "#{width}x#{height}"
end