Skip to content

Instantly share code, notes, and snippets.

View bltavares's full-sized avatar
💭
I may be slow to respond.

Bruno Tavares bltavares

💭
I may be slow to respond.
View GitHub Profile
@bltavares
bltavares / estados.rb
Created September 21, 2011 03:14
Lista de estados brasileiros em um array do ruby
ESTADOS_BRASIL = %w[AC AL AP AM BA CE DF ES GO MA MT MS MG PA PB PR PE PI RJ RN RS RO RR SC SP SE TO]
@bltavares
bltavares / Memoizer.cs
Created October 4, 2011 16:00
C# Memmoizer
namespace Memoizer
{
/// <summary>
/// Store a value so you don't run it twice
/// </summary>
public class Memoizer
{
private IDictionary<string, object> _frozenValues = new Dictionary<string, object>();
/// <summary>
@bltavares
bltavares / Gemfile
Created October 15, 2011 21:06
Problem with bourbon 1.0.4
source 'http://rubygems.org'
gem "rake", "0.8.7"
gem 'rails', '3.1.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'mysql2', "~> 0.3.0"
gem "pg"
@bltavares
bltavares / gist:1417981
Created December 1, 2011 16:28
RAndom values on updates
-- T-SQL
select
(CONVERT([tinyint],(1)+rand(checksum(newid()))*(28),(0)));
@bltavares
bltavares / oh.js
Created December 29, 2011 00:04
How come?!
var foo = [0];
console.log(foo == !foo);
console.log(foo == foo);
@bltavares
bltavares / DelegateWholeClass.rb
Created January 26, 2012 01:50
Lets play with decorators
require "delegate"
class A
def self.class_meth
"class method"
end
def self.class_meth_with_args a, b
"class method args: " + a + b
end
@bltavares
bltavares / gist:1682339
Created January 26, 2012 11:26
DelegateStuff
#pseudo code
class User < ActiveRecord::Base
named_scope :actives, where(:actived => true)
end
class BrunoUserClass < SomeDelegateClass(User)
def self.actives
super.where(name => "Bruno")
end
@bltavares
bltavares / gist:1754068
Created February 6, 2012 18:57
RAnking functions extension methods - C# Enumerable
public static class EnumerableExt {
public static IEnumerable<U> Rank<T, TKey, U>(
this IEnumerable<T> source,
Func<T, TKey> keySelector,
Func<T, int, U> selector)
{
if (!source.Any())
{
yield break;
}
@bltavares
bltavares / TestTransactionClass.cs
Created March 9, 2012 20:30
C# Trasactional Tests
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Test
{
[TestClass]
public class TestTransactionClass : TransactionalTest
@bltavares
bltavares / Rectangle.java
Created April 6, 2012 05:55
Rectangle Code
public class Rectangle {
private final int width;
private final int height;
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
}