Skip to content

Instantly share code, notes, and snippets.

View rdammkoehler's full-sized avatar

Rich Dammkoehler rdammkoehler

View GitHub Profile
@rdammkoehler
rdammkoehler / partial.rb
Created May 29, 2014 15:50
There must be a better way to do this. The cards(...) method is kinda ugly as is lists_in(...) But for the life of me I cannot see a way to make it prettier
#where the json content is a trello board that has been sucked into jsoncontent
def lists_in(jsoncontent)
lists = jsoncontent['lists']
[Hash[ lists.collect { |list| [ list['id'], list['name'] ] } ], lists.map { |list| list['id'] if list['closed'] }.to_set]
end
def id_for(card)
card['idList']
end
@rdammkoehler
rdammkoehler / BogoServlet.java
Created December 1, 2010 22:15
A Bogus Servlet using Jersey and Guice
package jerseyandguice;
import javax.servlet.http.HttpServlet;
import javax.ws.rs.Path;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@Path("/jg")
@Singleton
package jerseyandguice;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
public class JGServletContextListener extends GuiceServletContextListener {
private final ServletModule customServletModule = new ServletModule() {
package jerseyandguice;
import com.google.inject.AbstractModule;
import com.google.inject.servlet.RequestScoped;
public class DependancyModule extends AbstractModule {
@Override
protected void configure() {
bind(Dependancy.class).to(DefaultDependancy.class).in(RequestScoped.class);
1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped object. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
while locating jerseyandguice.Dependancy
1 error
at com.google.inject.InjectorImpl$4.get(InjectorImpl.java:767)
at com.google.inject.InjectorImpl.getInstance(InjectorImpl.java:793)
at jerseyandguice.GuiceWiringTest.shouldFailToGetDependancyBecauseOfScope(GuiceWiringTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
package jerseyandguice;
import static jerseyandguice.GuicedServletAssertion.assertInstantiablity;
import static jerseyandguice.GuicedServletAssertion.assertProvisioningType;
import static jerseyandguice.GuicedServletAssertion.expose;
import static org.testng.Assert.assertNotNull;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
package jerseyandguice;
public class DefaultDependancy implements Dependancy {
}
package jerseyandguice;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.FilterChain;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@rdammkoehler
rdammkoehler / GoodCompromiseInGOL.java
Created January 20, 2011 21:25
This is a good compromise, even though it has redundancy, less DRY, more intent revealing.
public boolean willBeAliveInTheNextGeneration() {
return shouldLiveOnToNextGeneration() || shouldBeCreatedByReproduction();
}
private boolean shouldLiveOnToNextGeneration() {
return cell.isAlive() && ( cellHasTwoNeighbors() || cellHasThreeNeighbors());
}
private boolean shouldBeCreatedByReproduction() {
return cell.isDead() && cellHasThreeNeighbors();
@rdammkoehler
rdammkoehler / GameOfLifeOOX.java
Created January 30, 2011 03:43
Part of Conway's Game of Life in Java pushing on the OO boundary
protected Map<Cell, State> captureStateTransitions(Ecosystem ecosystem) {
Map<Cell, State> stateTransitions = createSelfMinimizingMap();
for (Cell cell : ecosystem.getCells()) {
stateTransitions.put(cell, getRules().evaluate(ecosystem, cell));
}
return stateTransitions;
}
package gol.impl;