Skip to content

Instantly share code, notes, and snippets.

View Looper.java
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);
View ApacheDoubleTest.java
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;
View WaitAMinute.java
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 Jul 3, 2015
CGLib IntelliJ NonNull issue
View MyObjectTest.java
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 Feb 14, 2013
My answer to Cedric Beust's coding challenge ("Light" edition) http://beust.com/weblog/2013/02/13/coding-challenge-light-edition/
View SchoolTest.java
// 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/
View fancy-prompt.sh
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
View IsolationTest.scala
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"
View run.sh
# 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
View vimrc.local.vim
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 Mar 1, 2012
Symmetry of Box's equals method
View BoxTest.scala
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"
You can’t perform that action at this time.