Skip to content

Instantly share code, notes, and snippets.

View alinpopa's full-sized avatar

Alin Popa alinpopa

View GitHub Profile
@alinpopa
alinpopa / TestUdpServer.scala
Created December 16, 2010 05:50
Scala Multicast Server
import java.net.{DatagramPacket, InetAddress, MulticastSocket, SocketTimeoutException}
import java.lang.{Runnable, Thread}
object TestUdpServer {
class UdpServer(val address: String, val port: Int, val info: String) {
val socket = new MulticastSocket(port)
val multicastAddressGroup = InetAddress.getByName(address)
socket.joinGroup(multicastAddressGroup)
def execute: Unit = {
@alinpopa
alinpopa / TestMulticastClient.scala
Created December 16, 2010 14:43
Scala Multicast (UDP & TCP) client
import java.net.{DatagramPacket, InetAddress, MulticastSocket, SocketTimeoutException, ServerSocket, InetSocketAddress, Socket}
import java.io.{InputStreamReader, BufferedReader}
import java.util.{Timer, TimerTask, List, ArrayList, Date}
object TestMulticastClient {
class MulticastClient(val address: String, val port: Int) {
private val socket = new MulticastSocket(port)
private val group = InetAddress.getByName(address)
socket.joinGroup(group)
@alinpopa
alinpopa / TestMulticastServer.scala
Created December 16, 2010 14:43
Scala Multicast (TCP & UDP) server
import java.net.{DatagramPacket, InetAddress, MulticastSocket, SocketTimeoutException, ServerSocket, InetSocketAddress, Socket}
import java.io.{BufferedReader, OutputStreamWriter}
import java.lang.{Runnable, Thread}
object TestMulticastServer {
class MulticastServer(val address: String, val port: Int) {
val socket = new MulticastSocket(port)
val multicastAddressGroup = InetAddress.getByName(address)
socket.joinGroup(multicastAddressGroup)
val serverSocket = new ServerSocket()
object Wrappers {
private class ElvisWrapper[T](alt: T){
def ?:[A >: T](pred: A) = if (pred == null) alt else pred
}
implicit def elvisOperator[T](alt: => T) = new ElvisWrapper(alt)
}
@alinpopa
alinpopa / SplitStringToWords.scala
Created January 15, 2011 08:58
Guy Steele's Fortress demo implementation in scala
sealed trait WordState {
def +(other: WordState): WordState
def maybeWord(s: String) = if(s.isEmpty) List() else List(s)
def processChar(c: Char): WordState = if(c == ' ') Segment("",List(),"") else Chunk(c.toString)
def words(s: String) = {
val l = s.toList
l.map(c => processChar(c)).reduceLeft(_ + _) match {
case Chunk(s) => maybeWord(s)
case Segment(left, a, right) => maybeWord(left) ++ a ++ maybeWord(right)
public class Test {
@Test
public void shouldIncreaseSizeWhenAddingNewElement() throws Exception {
// Arrange
final ArrayList list = new ArrayList();
// Act
list.add("one");
public class ScannerTest {
@Test
public void shouldDisplayThePriceUsingTaxes() {
Display display = mock(Display.class);
Calculator calculator = mock(Calculator.class);
Repository repository = mock(Repository.class);
when(calculator.calculate("$100")).thenReturn("$119");
when(repository.getProductPrice("ABC123")).thenReturn("$100");
Scanner scanner = new Scanner(repository, calculator, display);
dyld: Library not loaded: /Users/alin/usr/local/homebrew/Cellar/glib/2.24.2/lib/libglib-2.0.0.dylib
Referenced from: /Users/alin/usr/local/homebrew/Cellar/gettext/0.18.1.1/bin/msgfmt
Reason: image not found
/bin/sh: line 1: 20373 Trace/BPT trap /Users/alin/usr/local/homebrew/Cellar/gettext/0.18.1.1/bin/msgfmt -o test.mo ./de.po
CCLD io-stream
cp: test.mo: No such file or directory
make[4]: *** [test.mo] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
You can install Homebrew anywhere you want, but some brews may only work
correctly if you install to /usr/local.
@alinpopa
alinpopa / .gitconfig
Created May 31, 2011 15:49
Git .gitconfig
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow bold