This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(evaluator_utils). | |
-export([eval_string/1]). | |
eval_string([]) -> []; | |
eval_string(String) -> | |
{ok, Tokens, _} = erl_scan:string(lists:concat([String, "."])), | |
{Status, Term} = erl_parse:parse_term(Tokens), | |
case Status of | |
ok -> {ok, Term}; | |
error -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ZipUtils{ | |
def zipWith(f:(Int,Int) => Int, l1:List[Int], l2:List[Int]):List[Int] = { | |
l1.zip(l2).map{ | |
x:(Int,Int) => f(x._1, x._2) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object LazyFib { | |
implicit def wrapStreamInt(s:Stream[Int]) = new StreamWrapper[Int](s) | |
def apply(n:Int):List[Int] = fibs().takeN(n) | |
def zipWith(f:(Int,Int) => Int, l1:Stream[Int], l2:Stream[Int]):Stream[Int] = { | |
l1.zip(l2).map{x:(Int,Int) => f(x._1, x._2)} | |
} | |
def fibs():Stream[Int] = Stream.cons(0, Stream.cons(1, zipWith((x:Int,y:Int) => x+y, fibs, fibs.tail))) | |
} | |
class StreamWrapper[A](val value:Stream[A]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(consumers). | |
-export([start/0, consumer1/0]). | |
start() -> | |
loop([]). | |
loop(Consumers) -> | |
receive | |
{subscribe, Consumer} -> | |
ConsExits = lists:member(Consumer, Consumers), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(pc_queue). | |
-export([start/0,produce/2,consume/1,status/1]). | |
start() -> | |
Queue = queue:new(), | |
spawn(fun() -> loop(Queue) end). | |
loop(Q) -> | |
receive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Second(value: Long) | |
case class Minute(value: Long){ | |
def seconds = Second(value * 60) | |
} | |
case class Hour(value: Long) { | |
def minutes = Minute(value * 60) | |
} | |
case class Day(value: Long){ | |
def hours = Hour(value * 24) | |
def minutes = hours.minutes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.{Map,HashMap} | |
trait Fruct | |
case object Mar extends Fruct | |
case object Par extends Fruct | |
class Persoana { | |
private var numarDeFructe = 0 | |
private var fructe = new HashMap[Fruct,Int]() | |
def are(numarDeFructe: Int): Persoana = { | |
this.numarDeFructe = numarDeFructe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ca.jbrains.pos.test; | |
import static org.junit.Assert.*; | |
import java.util.*; | |
import org.junit.*; | |
public class SellOneItemTest { | |
public static class Sale { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.test.android.multicast | |
import _root_.android.app.Activity | |
import _root_.android.os.Bundle | |
import _root_.android.widget.TextView | |
import _root_.android.app.Dialog | |
import _root_.android.util.Log | |
import _root_.android.net.wifi.WifiManager | |
import _root_.android.content.Context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.{DatagramPacket, InetAddress, MulticastSocket, SocketTimeoutException} | |
import java.lang.{Runnable, Thread, StringBuilder} | |
import java.util.{Timer, TimerTask, List, ArrayList} | |
object TestUdpClient { | |
class UdpClient(val address: String, val port: Int) { | |
private val socket = new MulticastSocket(port) | |
private val group = InetAddress.getByName(address) | |
socket.joinGroup(group) |
OlderNewer