Skip to content

Instantly share code, notes, and snippets.

Avatar

Antonio Antillon antillas21

View GitHub Profile
@antillas21
antillas21 / spec.rb
Last active Feb 6, 2019
Stubbing an ActiveRecord::Relation object
View spec.rb
# first we create an empty ActiveRecord::Relation object
relation = Model.where(attribute: value)
# then we make the relation stub the :[] method
# and return whatever values we need
relation.stub(:[]).and_return( Model.new({attrs: values})] )
# of course, we can make this too
# instead of the step above
record = double("Model", :foo => 'bar', :bar => 'baz')
@antillas21
antillas21 / admin_base_controller.rb
Last active May 28, 2017
An excersie in removing duplication on CRUD Rails controllers. Inspired by the book Growing Rails Application in Practice
View admin_base_controller.rb
# app/controllers/admin/base.rb
class Admin::BaseController
include Admin::CRUDMethods
class NotImplementedError < StandardError; end
def index
list_resources
end
@antillas21
antillas21 / Vagrantfile.rb
Created Apr 23, 2012
Sample Vagrantfile
View Vagrantfile.rb
Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "lucid64"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
@antillas21
antillas21 / transactional-tabular-email.html
Created Jan 17, 2014
Transactional Tabular Email Template
View transactional-tabular-email.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Facebook sharing information tags -->
<meta property="og:title" content="*|MC:SUBJECT|*" />
<title>*|MC:SUBJECT|*</title>
<style type="text/css">
@antillas21
antillas21 / gist:6832001
Created Oct 4, 2013
Basic JS Deferred object implementation
View gist:6832001
/*
** Solution proposed by: Chad Elliott (https://www.vizify.com/thethechad)
** at StackOverflow. Link to original: http://stackoverflow.com/a/18097040
*/
function Deferred(){
this._done = [];
this._fail = [];
}
Deferred.prototype = {
@antillas21
antillas21 / 1-random-ideas.md
Last active Dec 17, 2015
AndreBadi random ideas
View 1-random-ideas.md
  • customer has many transactions
  • transactions can be payments or purchases
  • transaction fields: [ customer_id, created_at, amount, transaction_type ]
  • purchases has many line_items
  • line_item fields: [ name, color, size, cost, price, qty: { default: 1}, item_total ]
  • customer has one balance ( difference between purchases and payments )

Reset option

  • customer transactions are not preserved forever
  • admin settings include a 'reset transaction data' feature that will delete
View gist:5632645
|root
|public/ (home of drupal install)
|drush-bkups
|fixtures (db dumps, legacy data to be imported)
View proposed.json
{
"catalog_product_id":4,
"created_at":"2013-03-06T19:52:18Z",
"entity_type":"Printable",
"id":14,
"live":true,
"properties": {
"Quantity":[
{
"option_name":"250",
View post_spec.rb
# spec/models/post_spec.rb
require 'spec_helper'
describe Post do
let(:post) { Post.new }
describe 'basic attributes' do
it 'needs a title, content and name' do
post.title = 'post title'
@antillas21
antillas21 / gist:3724857
Created Sep 14, 2012
Common Media Queries - 2012
View gist:3724857
/* SOURCE: http://www.stuffandnonsense.co.uk/blog/about/hardboiled_css3_media_queries/ */
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
You can’t perform that action at this time.