Skip to content

Instantly share code, notes, and snippets.

View tmaximini's full-sized avatar

Thomas Maximini tmaximini

View GitHub Profile
@tmaximini
tmaximini / article_set.rb
Created July 14, 2011 22:30
carrierwave upload problem
require 'RMagick'
class ArticleSet < ActiveRecord::Base
validates_presence_of :name
validates_length_of :name, :minimum => 3
# creator
belongs_to :user
@tmaximini
tmaximini / test.rb
Created July 15, 2011 09:52
carrierwave trouble
# this doesn't throw error, but now file gets uploaded, nothing stored in the blog_image string field (that's my mounted uploader where carrierwave should store the image identifier in)
img_path = "#{RAILS_ROOT}/tmp/sets/"
img_name = "set_#{self.id}_#{Time.now.to_i}.png"
# save composite image to PNG
template.write(img_path + img_name) # this works, it generates the desired PNG
#save and upload to s3
tmp_image = File.open(img_path + img_name)
@tmaximini
tmaximini / gist:1211231
Created September 12, 2011 13:21
get all products from category tree
# category.rb
class Category < ActiveRecord::Base
acts_as_nested_set
attr_accessible :name, :description, :lft, :rgt, :parent_id
has_many :categorizations
has_many :products, :through => :categorizations
@tmaximini
tmaximini / gist:1334286
Created November 2, 2011 17:23
polymorphic association
# models/comment.rb
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :commentable, :polymorphic => true
end
# models/post.rb
class Post < ActiveRecord::Base
belongs_to :post_category
var gallery_item = Backbone.Model.extend({
defaults: {
tags : "",
project_id : null,
image_full_url: null,
image_medium_url: null
}
});
// Bindings to window obj
@tmaximini
tmaximini / main.js
Created September 25, 2012 10:48
backbone error
var gallery_item = Backbone.Model.extend({
defaults: {
tags : "",
project_id : null,
image_full_url: null,
image_medium_url: null
}
});
<% for line_item in cart.line_items %>
<!-- HTML omitted -->
<!-- This link actually removes not only the line_item from cart, but also deletes the product...? . -->
<%= link_to "remove", line_item, :confirm => 'Remove from cart?', :method => :delete %>
<% end %>
// $mq-mobile-portrait : 320px !default;
// $mq-mobile-landscape : 480px !default;
// $mq-tablet-portrait : 640px !default; -- changed because i want my blog content is around this wide, not 768. you should let content & design determine your breakpoints
// $mq-tablet-landscape : 1024px !default;
// $mq-desktop : 1382px !default;
$mq-mobile-portrait : 20em !default;
$mq-mobile-landscape : 30em !default;
$mq-tablet-portrait : 40em !default;
$mq-tablet-landscape : 64em !default;
define (require) ->
Backbone = require "Backbone"
Question = require "./Question"
QuestionStageList = require "./stage/QuestionStageList"
# load tranlations via requirejs i18n module
Locales = require "i18n!src/shared_views/nls/Locales"
require.config({
baseUrl: '/backbone-tests/',
paths: {
'jquery' : '/app/libs/jquery',
'underscore' : '/app/libs/underscore',
'backbone' : '/app/libs/backbone',
'mocha' : 'libs/mocha',
'chai' : 'libs/chai',
'chai-jquery' : 'libs/chai-jquery',
'models' : '/app/models'