Skip to content

Instantly share code, notes, and snippets.

View cannikin's full-sized avatar
🔨
Woodworking

Rob Cameron cannikin

🔨
Woodworking
View GitHub Profile
- if RAILS_ENV == 'development'
#debug
= link_to_function('Params Trace', "$('debug_params').toggle()")
#debug_params
%table
- params.keys.sort.each do |key|
%tr
%td= key
%td= params[key]
- if RAILS_ENV == 'development'
#debug
= link_to_function('Params Trace', "$('debug_params').toggle()")
#debug_params
%table
- params.keys.sort.each do |key|
%tr
%td= key
%td= params[key]
# Benchmarks the performance of ActiveRecord vs. Sequel for some common tasks.
# To make sure you have all the necessary gems:
#
# gem install active_record sequel faker
require 'active_record'
require 'sequel'
require 'faker'
require 'benchmark'
class Image < ActiveRecord::Base
belongs_to :user
belongs_to :attachment, :polymorphic => true
# validates_presence_of :url
before_save :check_for_defaults
default_scope :order => 'id asc'
def upload
file = params[:Filedata]
image = Image.new(:file => file,
:title => file.original_filename.split('.').first,
:description => '',
:attachment_type => 'Profile')
if image.upload
render :json => { :image => { :url => image.url, :path => image.image_path }}.to_json
else
$(document).ready(function() {
$("#uploadify").uploadify({
'scriptData':{'token':'#{user.uuid}'},
'uploader':'/media/uploadify.swf',
'script':'#{account_upload_path}',
'cancelImg':'#{image_path('icons/cancel.png')}',
'queueID':'file_queue',
'auto':true,
'multi':false,
'buttonText':'UPDATE IMAGE',
@cannikin
cannikin / code_statistics.rb
Created February 11, 2011 22:52
Modifications to railties's code_statistics.rb to include comment counting
class CodeStatistics #:nodoc:
TEST_TYPES = %w(Units Functionals Unit\ tests Functional\ tests Integration\ tests)
def initialize(*pairs)
@pairs = pairs
@statistics = calculate_statistics
@total = calculate_total if pairs.length > 1
end
@cannikin
cannikin / amazon_s3.yml
Created May 9, 2011 19:56
A sweet image model that uploads to S3 upon saving
# If this is a Rails app, put this into config/amazon_s3.yml and create an initializer with the commented code below
development:
bucket_name: dev.watchmemakethis.com
access_key_id: AKIAJVO23UDSUSXGO75Q
secret_access_key: 44UQ7QURc4u6PqtSEmNxp0xTlM+JpEKEjKXr9QIn
url: https://s3.amazonaws.com/dev.watchmemakethis.com
cdn: https://d33hnx0c6n9niy.cloudfront.net
@cannikin
cannikin / sample_node.js
Created June 8, 2011 22:05
Sample node server
var http = require('http');
var fs = require('fs');
var server = new http.Server();
server.listen(8000);
server.on('request', function(request, response) {
var url = require('url').parse(request.url);
if (url.pathname === '/test/delay') {
@cannikin
cannikin / gist:1015615
Created June 8, 2011 22:34
Rails 3.0.1.rc3 stack trace
activesupport (3.1.0.rc3) lib/active_support/core_ext/string/output_safety.rb:129:in `gsub!'
haml (3.1.1) lib/haml/compiler.rb:382:in `block in build_attributes'
haml (3.1.1) lib/haml/compiler.rb:358:in `each'
haml (3.1.1) lib/haml/compiler.rb:358:in `collect'
haml (3.1.1) lib/haml/compiler.rb:358:in `build_attributes'
haml (3.1.1) lib/haml/compiler.rb:407:in `prerender_tag'
haml (3.1.1) lib/haml/compiler.rb:119:in `compile_tag'
haml (3.1.1) lib/haml/compiler.rb:447:in `compile'
haml (3.1.1) lib/haml/compiler.rb:446:in `block (2 levels) in compile'
haml (3.1.1) lib/haml/compiler.rb:446:in `each'