Skip to content

Instantly share code, notes, and snippets.

@ffbit
ffbit / JettyConnectorTest.java
Created November 16, 2012 20:58
Jetty Connector Port unit test
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@ffbit
ffbit / mvn-download-sources-and-javadocs.md
Created November 16, 2012 17:36
Apache Maven - Download sources and javadocs

Download sources

mvn dependency:sources

or

mvn dependency:resolve -Dclassifier=sources

Download javadocs

@ffbit
ffbit / building-offline-with-maven.md
Created November 7, 2012 10:29
Building Offline with Maven

If you are temporarily disconnected from the internet and you need to build your projects offline you can use the offline switch on the CLI:

mvn -o package

@ffbit
ffbit / dump.sh
Created October 15, 2012 14:26
PostgreSQL dump
#!/bin/bash
DB="dbname"
HOST="127.0.0.1"
UNAME="uname"
pg_dump --host=$HOST --port=5432 --username=$UNAME $DB | gzip -c > $DB.backup.gz
@ffbit
ffbit / gist:3881193
Created October 12, 2012 20:01
Mapping SSD on linux
ls -l /dev/disk/by-uuid
sudo nano /etc/fstab
UUID=aaaaaaaa-aaaa-aaaa-aaaa-c5d849f7592c /ssd ext4 noatime,nodiratime,discard,errors=remount-ro 0 1
sudo mount -a
@ffbit
ffbit / create-project
Created September 2, 2012 17:09
Java SE 6.0 Maven scaffolding
#!/bin/bash
SCRIPT_DIR=`dirname $0`
if [ -z $1 ]
then
echo "ERROR: Provide an artifact id"
exit -1
fi
@ffbit
ffbit / 100-dwarfs-and-candles.py
Created September 2, 2012 11:38
100 dwarfs and candles
n = 100
candles = [False] * n
offset = 1
for dwarf in xrange(n):
dwarf_num = dwarf + offset
for candle in xrange(n):
candle_num = candle + offset
if not candle_num % dwarf_num:
candles[candle] = not candles[candle]
@ffbit
ffbit / time.py
Created August 22, 2012 21:54
Calculating time for the Algorithm course
import math
time = (3.3E-4, 5.0E-9, 6.25E-9)
data = (1, 2, 4, 8, 16, 32, 64)
for t in time:
print("== %s ==" % t)
for d in data:
result = math.pow(d * 1000, 2) * t
print("%s %f" % (d, result))
@ffbit
ffbit / before (JUnit 4)
Last active October 9, 2015 02:58
Eclipse Preferences -> Java -> Editor -> Templates
@Before
public void ${setUp}() throws Exception {
${import:import('org.junit.Before')}${cursor}
}
@Test
public void itShould${DoSomething}() throws Exception {
${import:import('org.junit.Test')}${cursor}
}
@ffbit
ffbit / gist:3427773
Last active October 9, 2015 02:57
Eclipse Preferences -> Java -> Editor -> Code Assist -> Favorites
org.hamcrest.CoreMatchers
org.junit.Assert
org.junit.matchers.JUnitMatchers
org.mockito.Mockito