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 / client.rb
Created November 13, 2014 20:57
Client.search
class Client < ActiveRecord::Base
scope :search, ->(term) {
clients_table = self.arel_table
column = clients_table[:name]
where(column.matches("%#{term}%"))
}
end
# 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 August 29, 2015 14:06
ngResource config
(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 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
// 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 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 / carrierwave.rb
Created March 12, 2014 14:59
Carrierwave initializer file
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 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