Skip to content

Instantly share code, notes, and snippets.

View guilhermesilveira's full-sized avatar

Guilherme Silveira guilhermesilveira

View GitHub Profile
@guilhermesilveira
guilhermesilveira / gist:3315116
Created August 10, 2012 15:40
heroku does not love me anymore
# updated from https://gist.github.com/3316290
rm -rf xpto
rails _3.2.8_ new xpto -d postgresql --skip-bundle
cd xpto
bundle install
git init
@guilhermesilveira
guilhermesilveira / gist:2378419
Created April 13, 2012 17:10
abusing _ scala in javascript
<script>
function next(a) {
return a + 1;
}
function map(els, f) {
var current = [];
for(var i in els) {
var el = els[i];
current.push(f(el));
}
@guilhermesilveira
guilhermesilveira / gist:2215876
Created March 27, 2012 13:30
monad lists, o basico do map
package br.com.caelum.example.monad;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
interface Monad<A> {
<B> Monad<B> map(Function<A, B> f);
}
@guilhermesilveira
guilhermesilveira / gist:2007714
Created March 9, 2012 17:43
biased? imagina...
import java.util.*;
void getTimeDiffGroupedByCat() {
Scanner sc = new Scanner(new File("textfile.txt"));
Map<String, Long> lastCatTime = new HashMap<String, Long>();
TreeMap<String, Vector<Long>> catTimeDiffs = new TreeMap<String, Vector<Long>>();
while (sc.hasNext()) {
Long thisTime = sc.nextLong();
String category = sc.next();
Long oldCatTime = lastCatTime.put(category, thisTime);
if(oldCatTime != null) {
class A {
int a(B b, C c) { return b.b1 + c.c1; }
}
on(b).b1(); returns(1)
on(c).c1(); returns(2)
assertEquals 2, a.a(b,c)
VERDE. maravilha
require 'rubygems'
require 'active_record'
class Client < ActiveRecord::Base
def to_s
"muhaha"
end
end
# well, this doesnt work...
@guilhermesilveira
guilhermesilveira / coupling.rb
Created March 25, 2011 19:00
show me how coupled I am
class BasicObject
def self.accept(who)
![BasicObject, ::Object, ::Kernel, ::Module, ::Enumerable, ::Comparable, ::Struct].include?(who)
end
def self.include(*types)
self.ancestors.each do |my|
types.each { |m|
m.ancestors.each { |k|
puts "\"#{k}\" -- \"#{m}\"" if accept(k) && accept(m) && k!=m
puts "\"#{my}\" -- \"#{k}\"" if accept(k) && accept(my) && k!=my
@guilhermesilveira
guilhermesilveira / avoid.rb
Created March 25, 2011 16:00
checking for coupling and encapsulation fails
class BasicObject
def self.include(m)
puts "#{m.ancestors} are coupling and breaking encapsulation of #{self}. are you sure you want to do that, my boy?"
super(m)
end
end
module B
end
module C
@guilhermesilveira
guilhermesilveira / gist:862677
Created March 9, 2011 18:20
dont repeat yourself
@Path("smooth")
@GET
public Response smooth(
@DefaultValue("2") @QueryParam("step") int step,
@DefaultValue("true") @QueryParam("min-m") boolean hasMin,
@DefaultValue("true") @QueryParam("max-m") boolean hasMax,
@DefaultValue("true") @QueryParam("last-m") boolean hasLast,
@DefaultValue("blue") @QueryParam("min-color") ColorParam minColor,
@DefaultValue("green") @QueryParam("max-color") ColorParam maxColor,
@DefaultValue("red") @QueryParam("last-color") ColorParam lastColor