Skip to content

Instantly share code, notes, and snippets.

View dabit's full-sized avatar

David Padilla dabit

View GitHub Profile
@dabit
dabit / digitos.rb
Created September 27, 2012 00:57
Digitos
#
# Uso:
#
# ruby digitos.rb 1980 1987
#
puts (ARGV[0]..ARGV[1]).select {|n| n.chars.to_a.uniq.size == n.size}.size
@dabit
dabit / force_ssl.rb
Created September 26, 2012 04:05
force_ssl comparison
#
# Rails 3.1
#
def force_ssl(options = {})
before_filter(options) do
if !request.ssl? && !Rails.env.development?
redirect_to :protocol => 'https://', :status => :moved_permanently
end
end
@dabit
dabit / jqueryac.rb
Created July 12, 2012 02:35
jquery-autocomplete hack
def json_for_autocomplete(items, method, extra_data=[])
items.collect do |item|
#
# Esta es la linea que importa, le estás diciendo a autocomplete que use nitprovedor como value
#
hash = {"id" => item.id.to_s, "label" => item.send(method), "value" => item.nitproveedor}
extra_data.each do |datum|
hash[datum] = item.send(datum)
end
@dabit
dabit / example.rb
Created February 26, 2012 21:17
autocomplete example
# Controller
class PostsController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :index]
autocomplete :tag, :name
end
# Routes:
resources :posts do
@dabit
dabit / alipayform.html
Created December 9, 2011 04:05
alipay form
<form accept-charset="UTF-8" action="https://www.alipay.com/cooperate/gateway.do" id="payment-form" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
<input id="out_trade_no" name="out_trade_no" type="hidden" value="123456" />
<input id="partner" name="partner" type="hidden" value="20887XXX910XXX97" />
<input id="total_fee" name="total_fee" type="hidden" value="0.01" />
<input id="seller_email" name="seller_email" type="hidden" value="[email protected]" />
<input id="notify_url" name="notify_url" type="hidden" value="http://127.0.0.1:3000/en-US?action=notify&amp;controller=store%2Fcheckout%2Falipay" />
<input id="return_url" name="return_url" type="hidden" value="http://127.0.0.1:3000/en-US?action=done&amp;controller=store%2Fcheckout%2Falipay" />
<input id="show_url" name="show_url" type="hidden" value="http://127.0.0.1:3000/en-US?action=show&amp;controller=store%2Fcheckout%2Falipay" />
%script{:type => "text/template", :id => "color_button_picker-template"}
%b
<%=name%>
%ul.colors.column.span-5
<% _.each(values, function(value) { %>
<li class="color_button">
<input id="value_<%=value.name%>" name="product[value_ids][<%=solr_name%>][]" type="checkbox" value="<%=value.id%>" data-value="<%=value.name%>"/>
<label for="value_<%=value.name%>">
<div class="<%=value.name.toLowerCase()%>"></div>
<span><%=value.name%></span>
@products.each_with_index do |p, i|
p.update_attribute(:date_available, i.minutes.ago)
end
- @shipping_methods.each do |method|
%p
= f.radio_button :shipping_method, method.service_code
= f.label :shipping_method, method.service_name, value: method.service_code
@dabit
dabit / alias.sh
Created October 7, 2011 16:00
Useful aliases
alias gs="git status"
alias gc="git commit"
alias gp="git push"
alias gpl="git pull"
alias r=rails
alias ga="git add"
alias gr="git rm"
alias clean="find . -name \"*.orig\" -print -exec rm {} \;"
alias be="bundle exec"
alias ber="bundle exec rake"
def display_item(item)
to_return = []
if item.upc?
if item.item
to_return << item.quantity
to_return << "<a href='#{edit_admin_product_path(item.item.product.id)}'>#{item.item.product.name}</a>"
to_return << item.item.product_attribute.name
to_return << item.item.size.name
end
else