Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / splats.coffee
Last active December 10, 2015 00:58
CoffeScript Splats example
leaderboard = ["ERC", "AMY", "BOB", "AAA", "STU"]
[winner, others..., loser] = leaderboard
console.log """
First place: #{winner}.
Last place: #{loser}.
"""
package org.test;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
@ffbit
ffbit / Main.java
Created December 25, 2012 19:33
Removing from Java List by int and Integer idexes
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String... args) {
// Two identical list of fruit
final List<String> fruit = getFruit();
final List<String> fruit2 = getFruit();
@ffbit
ffbit / reverse.rb
Created January 30, 2013 15:00
Reverse an array with Ruby
def reverse(a)
half = a.size / 2
(0...half).each do |i|
j = a.size - i - 1
a[i], a[j] = a[j], a[i]
end
a
end
reverse([1, 2])
@ffbit
ffbit / binary_search.rb
Last active December 12, 2015 00:08
Binary search with Ruby
def binary_search(a, needle)
start = 0
finish = a.size - 1
while start <= finish do
middle = start + (finish - start) / 2
if a[middle] == needle
return middle
elsif a[middle] < needle
@ffbit
ffbit / BinarySearchSuite.scala
Last active December 12, 2015 00:18
Binary search with Scala
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FunSuite
import scala.annotation.tailrec
@RunWith(classOf[JUnitRunner])
class BinarySearchSuite extends FunSuite {
trait TestBinarySearch {
val v = Vector(1, 2, 4)
@ffbit
ffbit / CollectionsTest.java
Last active December 12, 2015 09:19
Unmodifiable list, set and collection if Java
package com.ffbit.collections;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;