This file contains hidden or 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
#! /bin/sh | |
usage_error () { | |
echo 'Usage: sh migrator.sh <path to sqlite_to_postgres.py> <path to sqlite db file> <an empty dir to output dump files>' | |
echo | |
echo 'Example:' | |
echo '>sh migrator.sh sqlite_to_postgres.py ~/reviewboard.db /tmp/dumps' | |
echo | |
echo 'Tested on:' | |
echo 'Python 2.7.3' |
This file contains hidden or 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
require 'thread' | |
#This Class is just my exercise to try ConditionVariable | |
class BlockingQueue | |
def initialize | |
@queue = Queue.new | |
@semaphore = Mutex.new | |
@condition = ConditionVariable.new | |
end |
This file contains hidden or 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.Random; | |
public class Main { | |
private static final MyBlockingQueue<Integer> queue = new MyBlockingQueue<>(); | |
static class Producer extends Thread { | |
Producer(int i) { | |
super("Producer-" + i); | |
} | |
@Override |
This file contains hidden or 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
public int sumOfSquaresOfEvenElements(List<Integer> list) { | |
if (list == null) { | |
return 0; | |
} | |
int acc = 0; | |
for (int elem: list) { | |
if (elem % 2 == 0) { | |
acc += (elem * elem); | |
} | |
} |
This file contains hidden or 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
sealed trait MaybeDivideable { | |
def get: Int //Extraction | |
def flatMap(f: Int => MaybeDivideable): MaybeDivideable | |
} | |
object MaybeDivideable { | |
def apply(value: Int): MaybeDivideable = | |
if (value == 0) UnDivideable else Divideable(value) // Lifting | |
} |
This file contains hidden or 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
def divide1(a: Int, b: Int): MaybeDivideable = { | |
MaybeDivideable(a) match { | |
case UnDivideable => | |
UnDivideable | |
case Divideable(x) => | |
MaybeDivideable(b) match { | |
case UnDivideable => | |
UnDivideable | |
This file contains hidden or 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
def divide2(a: Int, b: Int): MaybeDivideable = { | |
val aMayBe = MaybeDivideable(a) | |
val bMayBe = MaybeDivideable(b) | |
aMayBe.flatMap { x => | |
bMayBe.flatMap { y => | |
MaybeDivideable(x / y) | |
} | |
} | |
} |
This file contains hidden or 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
sealed trait MaybeDivideable { | |
def get: Int | |
def flatMap(f: Int => MaybeDivideable): MaybeDivideable | |
/* New map method */ | |
def map(f: Int => Int): MaybeDivideable | |
} | |
case class Divideable(value: Int) extends MaybeDivideable { | |
require(value != 0, "value must not be 0") |
This file contains hidden or 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
def divide3(a: Int, b: Int): MaybeDivideable = { | |
for { | |
x <- MaybeDivideable(a) | |
y <- MaybeDivideable(b) | |
} yield (x / y) | |
} |
This file contains hidden or 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 scala.concurrent.duration.Duration | |
import scala.concurrent.{Await, Future} | |
val future = someFutureJob() | |
// NOO :( | |
val value = Await.result(future, Duration.Inf) | |
operate(value) |
OlderNewer