Skip to content

Instantly share code, notes, and snippets.

Avatar

Antonio Antillon antillas21

View GitHub Profile
View client.rb
class Client < ActiveRecord::Base
scope :search, ->(term) {
clients_table = self.arel_table
column = clients_table[:name]
where(column.matches("%#{term}%"))
}
end
View rspec_model_testing_template.rb
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@antillas21
antillas21 / app.js
Last active Aug 29, 2015
ngResource config
View app.js
(function(){
var app = angular.module('myApp.api', ['ngResource']);
app.factory("Clinic", ['$resource', function($resource) {
var resource = $resource("http://domain.com/api/v1/clinics/:id/:action/",
{
id: "@id",
action: "@action"
},
{
@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
View Gruntfile.js
// Generated on 2013-08-13 using generator-angular 0.3.1
'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({ port: LIVERELOAD_PORT });
var mountFolder = function (connect, dir) {
return connect.static(require('path').resolve(dir));
};
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
// # Globbing
@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 / carrierwave.rb
Created Mar 12, 2014
Carrierwave initializer file
View carrierwave.rb
if Rails.env.development?
CarrierWave.configure do |config|
config.storage = :file
end
elsif Rails.env.test?
CarrierWave.configure do |config|
config.storage = :file
config.enable_processing = false
end
else # production
@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
You can’t perform that action at this time.