Skip to content

Instantly share code, notes, and snippets.

View nthx's full-sized avatar

Tomasz Nazar nthx

View GitHub Profile
player = new Player()
player.assignGun (new Ak47())
console.log player.myGun().toStr()
class Player
constructor: (@name, @lives, @gun) ->
@guns = []
@currentGun = null
public void testModifyingRootAndResetingSystem()
{
assertEquals(0, getFilesNumberInRepo());
TestRoot root = new TestRoot();
assertEquals(1, getFilesNumberInRepo());
((Persisteble)root).takeSnapshot();
assertEquals(1, getFilesNumberInRepo());
assertEquals("000000000000000000000.snapshot",
public void setUp()
{
Pat.unload();
removeDatabaseFiles();
world = new World();
library = world.getLibrary();
}
public void testLendBookToReader()
{
public class ProlongCopy
extends IlybraAction
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
BookForm bookForm = (BookForm) form;
String prolongDate = bookForm.getReturnDate();
/** @@pat.transaction */
public void prolongCopy(Copy copy, DateRepresentation newReturnDate)
{
copy.returnDate = newReturnDate;
}
public Copy getCopyById(Long id) {
return (Copy) copies.get(id); //copies is java.util.Map
}
<bind pointcut="execution(* $instanceof{Action}->execute(*))"
cflow="(notInLoginAction AND notInLogoutAction)">
<advice aspect="AuthorizingAspect" name="checkUserLoggedIn"/>
</bind>
public class AuthorizingAspect
{
public Object checkUserLoggedIn(Invocation invocation)
throws Throwable
{
MethodInvocation mi = (MethodInvocation) invocation;
/** @@pat.transaction */
public void removeBook(Book book, DateRepresentation removalDate)
{
books.remove(book);
removedBooks.put(book.getId(), book);
book.setRemovalDate(removalDate);
...
}
<target name="pat_annotationc" depends="compile">
<taskdef name="annotationc"
classname="org.jboss.aop.ant.AnnotationC" classpathref="compile_classpath"/>
<annotationc compilerclasspathref="run_classpath"
classpathref="run_classpath"
bytecode="true">
<src path="src/"/>
<include name="**/*.java" />
</annotationc>
</target>
<target name="pat_aopc" depends="pat_annotationc">
<taskdef name="aopc"
classname="org.jboss.aop.ant.AopC" classpathref="compile_classpath" />
<aopc compilerclasspathref="run_classpath"
classpathref="run_classpath"
verbose="false">
<classpath path="run_classpath" />
<src path="${build.classes.dir}" />
<aoppath path="${etc.dir}/" />
</aopc>
@nthx
nthx / gist:1594592
Created January 11, 2012 13:12
DRY anti 1
#example of BAD code duplication among 2 controllers
#that could be at least extracted to 1 base controller
#and /:show game.name/ should be used
class A::Controller
before_filter :check_perms
def set_points
player.set_points params[:points]
redirect_to :action => :index
end