Skip to content

Instantly share code, notes, and snippets.

View edison's full-sized avatar
🏠
Working from home

Edison Machado edison

🏠
Working from home
View GitHub Profile
@edison
edison / classify.rb
Created May 6, 2018 07:33
Benchmarking de Métodos de Classificação - Estrutura de Dados
def bubble_sort(array)
n = array.length
swapped = true
while swapped do
swapped = false
(n - 1).times do |i|
if array[i] > array[i + 1]
array[i], array[i + 1] = array[i + 1], array[i]
@edison
edison / controller.rb
Created January 28, 2015 01:11
Devise Sessions Controller for Ajax
class Website::SessionsController < ::Devise::SessionsController
respond_to :js
layout false
# POST /resource/sign_in
def create
self.resource = warden.authenticate(auth_options)
if resource && resource.active_for_authentication?
sign_in(resource_name, resource)
# Amount should be a decimal between 0 and 1. Lower means darker
def darken_color(hex_color, amount=0.4)
hex_color = hex_color.gsub('#','')
rgb = hex_color.scan(/../).map {|color| color.hex}
rgb[0] = (rgb[0].to_i * amount).round
rgb[1] = (rgb[1].to_i * amount).round
rgb[2] = (rgb[2].to_i * amount).round
"#%02x%02x%02x" % rgb
end
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
@edison
edison / localizacao.md
Created September 8, 2012 20:23
localicazao

Estrutura do arquivo .yml de localizacao:

  pt:
    produtos:
      cadastro:
        salvar: Salvar produto

Utilizando o helper t para traduzir nas views:

@edison
edison / errors.yml
Created September 8, 2012 20:13
errors
pt:
activerecord:
attributes:
quote:
content: Frase
author: Autor
errors:
models:
quote:
@edison
edison / pt.yml
Created September 8, 2012 20:04
locale
pt:
activerecord:
attributes:
quote:
content: Frase
author: Autor
@edison
edison / index.erb
Created September 8, 2012 19:55
index
<% if @quotes.any? %>
<table class="table table-striped">
<tbody>
<% @quotes.each do |quote| %>
<tr>
<td><%= quote.content %></td>
<td><%= link_to 'Excluir', quote_path(quote), method: :delete, confirm: 'Tem certeza?', class: 'btn' %></td>
</tr>
<% end %>
</tbody>
@edison
edison / _quote.erb
Created September 8, 2012 19:54
_quote
<div class="hero-unit">
<% if @quote %>
<blockquote>
<p><%= @quote.content %></p>
<small><%= @quote.author %></small>
</blockquote>
<% else %>
<p>Nenhuma frase cadastrada.</p>
<% end %>
</div>
@edison
edison / controller.rb
Created September 8, 2012 19:53
controller
class QuotesController < ApplicationController
def index
@quotes = Quote.all
respond_to :html
end
def home
@quote = Quote.all.sort_by{rand}.slice(0,10).first
respond_to :html
end