Skip to content

Instantly share code, notes, and snippets.

View stympy's full-sized avatar

Benjamin Curtis stympy

View GitHub Profile
class ActiveRecord::Base
@@cache_store = nil
def self.cache_store
@@cache_store ||= ActionController::Base.cache_store
end
def self.caches(method_name, key = nil, options = {}, &block)
if key.is_a?(Hash)
options = key
key = nil
<table>
<thead>
<tr><th>Name</th></tr>
</thead>
<tbody id="specifications">
<% @specifications.each do |spec| %>
<tr id="spec-<%= spec.id %>"><td><%= spec.name %></td></tr>
<% end %>
</tbody>
</table>
(function($) {
$.extend($.fn, {
validate: function(options) {
var form = this;
this.submit(function(event) {
form.find('label.error').filter('[generated=true]').empty()
if ((req_fields = form.find('.required[value=""]')).length > 0) {
req_fields.after('<label class="error" generated="true">This field is required</label>')
class Attachment < ActiveRecord::Base
def scribd_url
"http://www.scribd.com/word/full/#{self.scribd_doc_id}?access_key=#{self.scribd_access_key}"
end
end
<% if attachments.any? %>
<ul class="attachments">
<% attachments.each do |att| %>
<li id="attachment_<%= att.id %>">
<%= link_to att.filename, attachment_url(att), :title => 'Download' %>
<%= link_to(image_tag('icons/page_white_magnify.png'), att.scribd_url, :id => att.scribd_doc_id, :rel => att.scribd_access_key, :class => 'scribd', :title => 'Preview') unless att.scribd_doc_id.blank? %>
</li>
<% end %>
</ul>
var scribd_doc;
function showScribd(link) {
scribd_doc = new scribd.Document(link.id, link.rel);
scribd_doc.addParam('height', 400);
scribd_doc.addParam('width', 620);
scribd_doc.addParam('page', 1);
scribd_doc.write('scribd_preview');
$('scribd').show();
}
class Submission < ActiveRecord::Base
def to_xml(options = {})
super({ :include => [:source, :attachments] }.merge(options))
end
end
Zip::ZipFile.open(zipfile, Zip::ZipFile::CREATE) do |zip|
submissions.each do |submission|
submission.attachments.each do |file|
zip.add(file.relative_path, file.full_filename)
end
end
zip.add('submissions.xml', xmlfile)
end
# This is an extension to ActiveMerchant to make the CIM gateway look a little more like the other gateways that
# support recurring billing. I wrote this code for the SaaS Rails Kit (http://railskits.com/saas), so if you are
# looking for a billing solution for your Rails application, feel free to check it out. :)
require 'digest/sha1'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class AuthorizeNetCimGateway < Gateway
@stympy
stympy / gist:154552
Created July 24, 2009 20:59
Script for running an ec2 instance based off a custom AMI, attaching an EBS volume, then associating an EIP
#!/usr/bin/env ruby
require 'rubygems'
require 'right_aws'
require 'net/ssh'
require 'open-uri'
# Git rid of ssl verification warning
class Net::HTTP
alias_method :old_initialize, :initialize