Skip to content

Instantly share code, notes, and snippets.

View abyx's full-sized avatar

Aviv Ben-Yosef abyx

View GitHub Profile
// Why write this..
public static <T, V> Map<T, List<V>> defaultdict_list() {
return new MapMaker().makeComputingMap(new Function<T, List<V>>() {
@Override public List<V> apply(T unusedCrap) {
return Lists.newArrayList();
}
});
}
# When you just want this (Python)
@abyx
abyx / OuterClassTest.java
Created August 11, 2011 16:22
Reusing context with JUnit Enclosed runner
@RunWith(Enclosed.class)
public class OuterClassTest {
@Mock protected Dependency dependency;
protected SUT subject;
@Before
public void setUp() {
subject = new SUT(dependency);
}
@abyx
abyx / list_filter_collapse.js
Created June 9, 2011 20:09
java script trick to hide the "filter" in a django admin view
(function($){
ListFilterCollapsePrototype = {
bindToggle: function(){
var that = this;
this.$filterTitle.click(function(){
that.$filterContent.slideToggle();
that.$list.toggleClass('filtered');
});
},
init: function(filterEl) {
@abyx
abyx / 0001-Fix-SortedSet-to-ensure-objects-comparable-with.patch
Created June 8, 2011 08:24
Fix SortedSet to ensure objects comparable with <=>
From 9c168445300c6fda62173d37fbbbffa1a2136e03 Mon Sep 17 00:00:00 2001
From: Aviv Ben-Yosef <aviv.by@gmail.com>
Date: Wed, 8 Jun 2011 11:10:11 +0300
Subject: [PATCH] Fix SortedSet to ensure objects comparable with <=>
Fixes 2 failing specs for SortedSet:
- SortedSet#add takes only values which responds <=>
- SortedSet#initialize takes only values which respond to <=>
---
lib/set.rb | 1 +
@abyx
abyx / RetrierTest.java
Created March 31, 2011 20:51
Simple JUnit rule to make tests retry
public class RetrierTest {
private static int count = 0;
@Rule public RetryRule rule = new RetryRule();
@Test
@Retry
public void failsFirst() throws Exception {
count++;
assertEquals(2, count);
@abyx
abyx / cart_dsl.rb
Created March 23, 2011 05:18
Start of DSL for shopping cart and sales from SCIL #7 by @TzipiZnavot, @eladsof & @AvivBY
describe 'cart' do
it 'allows discount after purchasing certain amount' do
product = Product.new('Snickers', 3)
cart = Cart.new
6.times { cart << product }
cart.when_buying(product).times(5).get(1).free()
cart.total.should == 5*3
name "appserver"
description "An application server"
run_list(%w{
recipe[apache2]
})
class default_node {
package { 'apache2':
ensure => installed
}
service { 'apache2':
ensure => true,
enable => true,
require => Package['apache2'],
}
}
@abyx
abyx / gist:746606
Created December 18, 2010 15:46
Original MVP code
public void bind() {
display.getSaveButton().addClickHandler(
new ClickHandler() {
@Override public void click(ClickEvent e) {
// Magic happens here
}
});
}