Skip to content

Instantly share code, notes, and snippets.

View bhserna's full-sized avatar

Benito Serna bhserna

View GitHub Profile
@bhserna
bhserna / gist:1031867
Created June 17, 2011 17:33
Markdown handler
We couldn’t find that file to show.
@bhserna
bhserna / nesting.rb
Created January 5, 2012 20:22
Nesting
require "rspec"
def nesting(string)
opens = 0
string.each_char do |c|
case c
when "(" then opens += 1
when ")" then opens > 0 ? (opens -= 1) : (return 0)
end
end
<ul id="products" class="home-products">
<% @products.each do |product| %>
<% if Spree::Config[:show_zero_stock_products] || product.has_stock? %>
<%= content_tag_for :li, product do %>
<%= link_to product do %>
<div class="product-image">
<%= product_image(product) %>
</div>
<%= link_to truncate(product.name, length: 50), product, class: "title" %>
<%= product_tooltip(product) %>
@bhserna
bhserna / new_manage_product_categories.feature
Created May 12, 2012 23:25
Refactoring my old cucumber tests
Feature: Manage categories
In order to clasify the brand products
As an admin
I want to assign categories to a product
Scenario: Manage product categories
Given a brand with a category and a product
And I am an admin
When I add the brand category to the product
@bhserna
bhserna / index.html.erb
Created June 3, 2012 19:12
Your api in your views
<%= content_tag "div", class: "milestones",
data: {
milestones: render(template: "api/v1/milestones/index.json")
} do %>
<%= javascript_tag do %>
jQuery(function(){
App.init();
});
<% end %>
@bhserna
bhserna / routes.rb
Created July 7, 2012 22:22
User-centric Routing with Devise and Rails
authenticated do
root :to => 'users#home'
end
root :to => 'pages#home'
#= require "commentator_templates"
#= require "commentator_poster"
#= require "commentator_params"
class window.Commentator
constructor: (args) ->
params = new CommentatorParams(args)
@el = params.el()
@url = params.url()
@bhserna
bhserna / controllers.rb
Created November 27, 2012 02:06
Factory method using convention and ruby
class ApplicationController < ActionController::Base
# other stuff ..
def notify(*args)
Notifications::Notifier.new.notify(*args)
end
end
class CommentsController < ApplicationController
@bhserna
bhserna / where_is_the_app.markdown
Last active December 10, 2015 14:38
This are different examples to do the same thing, "mark a notification as read", and the pros and cons that I see in each example

Where is the app?

This are different examples of doing the same thing, "mark a notification as read", and the pros and cons that I see in each example

1. - Logic in the model

  • The user clicks the notification link
  • The system POSTs to the action "notifications/:id/mark_as_read"
  • The controller calls the method Notification#mark_as_read
  • The model updates the attribute "read" saves the Notification record
<script type="text/x-handlebars" data-template-name="tab">
<ul id="customer-tab">
{{#each tabItem in tabItems}}
<li>
<h3>
{{tabItem.food.name}}
<span><a href="#" {{action "removeFood" tabItem.food}}>x</a></span>
<span>${{money tabItem.total}}</span>
</h3>
</li>