Skip to content

Instantly share code, notes, and snippets.

View antillas21's full-sized avatar

Antonio Antillon antillas21

  • Mexicali, Mexico
View GitHub Profile
@antillas21
antillas21 / spec.rb
Last active April 22, 2024 16:56
Stubbing an ActiveRecord::Relation object
# 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 21:19
An excersie in removing duplication on CRUD Rails controllers. Inspired by the book Growing Rails Application in Practice
# 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 April 23, 2012 17:40
Sample Vagrantfile
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 January 17, 2014 00:26
Transactional Tabular Email Template
<!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 October 4, 2013 20:10
Basic JS Deferred object implementation
/*
** 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 December 17, 2015 22:09
AndreBadi random ideas
  • 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
@antillas21
antillas21 / gist:5632645
Created May 23, 2013 03:56
drupal example
|root
|public/ (home of drupal install)
|drush-bkups
|fixtures (db dumps, legacy data to be imported)
@antillas21
antillas21 / proposed.json
Last active December 15, 2015 00:19
Entity JSON
{
"catalog_product_id":4,
"created_at":"2013-03-06T19:52:18Z",
"entity_type":"Printable",
"id":14,
"live":true,
"properties": {
"Quantity":[
{
"option_name":"250",
@antillas21
antillas21 / post_spec.rb
Created January 27, 2013 10:02
Rspec Post spec
# 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 September 14, 2012 21:10
Common Media Queries - 2012
/* 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) ----------- */