Skip to content

Instantly share code, notes, and snippets.

View cakper's full-sized avatar
🎯
Focusing

Kacper Gunia cakper

🎯
Focusing
View GitHub Profile
cat ~/.ammonite/predef.sc
import java.time._
import scala.concurrent.duration._
import scala.concurrent._
import $ivy.`io.monix::monix:3.0.0`
import monix.execution.Scheduler.Implicits.global
import monix.eval._
import monix.execution._
private def send(records: Seq[ProducerRecord[String, V]]): Task[Seq[RecordMetadata]] =
Task.create[Seq[RecordMetadata]] { (s, cb) =>
val results = TrieMap.empty[Long, RecordMetadata]
val expectedSize = records.size
val asyncCb = Callback.forked(cb)(s)
val compositeCancelable = CompositeCancelable()
// Forcing asynchronous boundary
sc.executeAsync(() => {
records.foreach { record =>
implicit class TaskExtenstions[A](val task: Task[A]) extends AnyVal {
def timed(): Task[A] = {
for {
startTime <- Task.eval(nanoTime())
result <- task.doOnFinish {
case _ => logger.info(nanoTime() - startTime)
}
} yield result
}
}
trait CsvEncoder[A] {
def encode(value: A): List[String]
}
def createEncoder[A](func: A => List[String]): CsvEncoder[A] = {
new CsvEncoder[A] {
override def encode(value: A) = func(value)
}
}
@cakper
cakper / Palindrome.php
Last active August 29, 2015 14:18
Palindrome
<?php
class ListElement
{
/**
* @var ListElement
*/
private $next;
private $value;
@cakper
cakper / Statistics.swift
Created March 3, 2015 12:58
Statistics
class Statistics {
let minimum: Int
let maximum: Int
let average: Int
init(minimum: Int, maximum: Int, average: Int) {
self.minimum = minimum
self.maximum = maximum
self.average = average
}
### Keybase proof
I hereby claim:
* I am cakper on github.
* I am cakper (https://keybase.io/cakper) on keybase.
* I have a public key whose fingerprint is E49A 7AB1 A55F 7052 DA92 89B2 363A FBB6 6B77 9714
To claim this, I am signing this object:
@cakper
cakper / Board.swift
Last active September 15, 2017 11:49
Swift
protocol Board {
func isValidMove(move: (x: Int, y: Int)) -> Bool
}
<?php
namespace Dcwroc\TaskBundle\InMemory;
use Dcwroc\TaskBundle\Entity\Task;
use Dcwroc\TaskBundle\Entity\TaskRepository;
class InMemoryTaskRepository implements TaskRepository
{
/**
<?php
namespace Dcwroc\TaskBundle\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class Task
{
/**
* @Assert\NotBlank()