Skip to content

Instantly share code, notes, and snippets.

@ffbit
ffbit / scopes.txt
Last active December 13, 2015 17:09
Request and Page scopes
{
Request scope
{
Page scope 1
}
{
Page scope 2
}
@ffbit
ffbit / SortTest.java
Last active December 12, 2015 10:39
Sorting in Java
package com.ffbit.fun.array;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import static org.hamcrest.CoreMatchers.is;
@ffbit
ffbit / ArrayAndArraysAsListTest.java
Created February 10, 2013 22:01
Array and its Derived List in Java
package com.ffbit.collections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
@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;
@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 / 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 / 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 / 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();
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 / 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}.
"""