Skip to content

Instantly share code, notes, and snippets.

public class Looper {
public static void main(String[] args) throws Exception {
int five = 5;
Field field = Integer.class.getDeclaredField("value");
field.setAccessible(true);
field.set(five, 4);
for (Integer i = 0; i < 10; i++) {
System.out.println(i);
package nl.jqno.equalsverifier;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.junit.Test;
public class ApacheDoubleTest {
static final class Doubler {
private final double d;
public void waitAMinute() {
reallyReallyWait(60000);
}
public void reallyReallyWait(int millis) {
int before = System.currentTimeMillis();
try {
Thread.sleep(millis);
}
catch (InterruptedException | StackOverflowError e) {
@jqno
jqno / MyObjectTest.java
Created July 3, 2015 13:09
CGLib IntelliJ NonNull issue
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.NoOp;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
public class MyObjectTest {
@Test
public void shouldVerifyHashCodeEquals() {
Enhancer e = new Enhancer();
@jqno
jqno / SchoolTest.java
Created February 14, 2013 12:45
My answer to Cedric Beust's coding challenge ("Light" edition) http://beust.com/weblog/2013/02/13/coding-challenge-light-edition/
// My implementation of Cedric Beust's coding challenge:
//
// A School has either a name (“Stanford”) or a nickname (“UCSD”) or both.
//
// Your task is to write equals() and hashCode() methods for the School class
// that satisfy the following requirement: two Schools are identical if they
// either have the same name or the same nickname.
//
// http://beust.com/weblog/2013/02/13/coding-challenge-light-edition/
function _fancy_prompt {
local RED="\[\033[01;31m\]"
local GREEN="\[\033[01;32m\]"
local YELLOW="\[\033[01;33m\]"
local BLUE="\[\033[01;34m\]"
local WHITE="\[\033[00m\]"
local PROMPT=""
# Working directory
import org.parboiled.scala._
import org.parboiled.errors.ErrorUtils
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
import org.scalatest.matchers.ShouldMatchers
@RunWith(classOf[JUnitRunner])
class IsolationTest extends FlatSpec with ShouldMatchers {
val input = "abcdxyz"
# Add the following line to ~/.bashrc:
# . /path/to/this/script/run.sh script_folder
# For example:
# . ~/Dropbox/config/bash/run.sh session
# Don't forget the dot!
for f in `dirname ${BASH_SOURCE[0]}`/$1/*; do
. $f
done
@jqno
jqno / vimrc.local.vim
Created March 11, 2012 21:22
vimrc.local
if has('win32') || has('win64')
set runtimepath+=$HOME/Dropbox/config/vim
source ~\Dropbox\config\vim\vimrc.vim
else
set runtimepath+=~/Dropbox/config/vim
source ~/Dropbox/config/vim/vimrc.vim
endif
@jqno
jqno / BoxTest.scala
Created March 1, 2012 20:51
Symmetry of Box's equals method
package net.liftweb.common
import org.junit.runner.RunWith
import org.scalatest.FlatSpec
import org.scalatest.junit.JUnitRunner
import org.scalatest.matchers.ShouldMatchers
@RunWith(classOf[JUnitRunner])
class BoxTest extends FlatSpec with ShouldMatchers {
val foo = "foo"