Skip to content

Instantly share code, notes, and snippets.

View felipero's full-sized avatar
🐞
Debugging

Felipe Rodrigues felipero

🐞
Debugging
View GitHub Profile
class BracketsChecker
OPENING = ['[', '{', '(']
CLOSING_MAP = {'[' => ']', '{' => '}', '(' => ')'}
def valid?(input)
return false if input.empty?
open_brackets = []
input.each_char do |char|
open_brackets << char if OPENING.include? char
class ArrayTools
def self.flat_array(array = [])
array.each_with_object([]) do |item, flat_array|
next if item.kind_of? String
flat_array.push *(item.kind_of?(Array) ? flat_array(item) : item)
end
end
end
@felipero
felipero / short-version.rb
Last active September 11, 2017 17:08
Crafters Behavior For Team Member
while true
# ...
faça um comentário no cartão com link para o PR
mova o cartão para a coluna `PR Ready`
while ninguém revisou seu código
notifique
end
while seu PR não foi aprovado
tire_duvidas
while você não está satisfeito com o seu trabalho

This is a fork of a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

  • Ability to disable autoselect of first matched element.
  • Ability to automatically set the width of the dropdown to that of the text input.
  • Ability to fetch source element via AJAX
  • Ability to have a comma separated list of tags.

For the proper source, and other examples, please see the original gist.

Example showing off all the above features

@felipero
felipero / gist:1084997
Created July 15, 2011 16:15 — forked from juanplopes/gist:1084911
Sugestão de refactoring
# adapter = ConnectionAdapter.new(connection
# request = Request.new(registration, card)
# transaction = request.execute_at!(adapter)
module Integration
class Transaction
def initialize(data)
@data = data
end
@felipero
felipero / transaction.rb
Created July 15, 2011 07:08
Bad Single Responsibility Principle Example
module Integration
class Transaction
def initialize
@connection = Integration::Connection.new
end
def create!(registration, card)
message = xml_builder("requisicao-transacao") do |xml|
xml.numero registration.id
xml.valor registration.training_class.price.to_i * 100
xml.moeda "986"
@felipero
felipero / gist:765578
Created January 4, 2011 22:32
NHibernate Helper ninja fodastico
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FluentNHibernate;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Context;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName example.com
# ServerAlias *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
def self.get_top_picks(domain, type, category, level, page = 1)
results = SearchableListing.category(category.id, level).by_type(type).
domain(domain.id).lookup_page(page).
rating_no_less_than(0).star_rating_no_less_than(3).
lvs_not_null.one_per_user_highest_lvs.with_photos.
top_picks_with_join
ids = results.collect(&:listing_id).uniq
results = Listing.find(ids, :order => ids.to_id_sql_order, :include => :user)
results.reject! { |l| l.get_availability == AdvisorStatus::Status::AWAY || l.user.busy_on_call? }
def remote_setup
if branch.eql? "master"
checkout = ""
else
checkout = "&& $(git branch | grep -vq #{branch}) && git checkout -f -b #{branch} origin/#{branch}"
end
remote_run "cd #{path} && #{@sudo}git clone --depth 1 #{repository} #{application} && cd #{application} #{checkout}"
install_gems
remote_run "#{@sudo}rake inploy:setup environment=#{environment}"
end