Skip to content

Instantly share code, notes, and snippets.

View fomkin's full-sized avatar
🎯
Focusing

Aleksey Fomkin fomkin

🎯
Focusing
View GitHub Profile
@fomkin
fomkin / ppr.py
Last active November 24, 2019 14:59
def PPR(ref, hyp):
def find_words_before_commas(tokens):
words_before_commas = set()
for i, token in enumerate(tokens):
if token == "," and i > 0:
word = tokens[i-1]
words_before_commas.add(word)
return words_before_commas
@fomkin
fomkin / BTree.scala
Last active December 25, 2017 05:25
Simple immutable B-tree with Scala
case class BTree[K, V](root: BTree.Node[K, V], order: Int)(implicit keyOrdering: Ordering[K]) {
import keyOrdering.mkOrderingOps
private type N = BTree.Node[K, V]
private type E = BTree.Entry[K, V]
def get(key: K): Option[V] = {
def aux(node: N): Option[V] = {
val mayBeEntry = node.entries.find(_.key == key)
val users = Vector(
"@demyanam1",
"@CipHuK",
"@sergey_samoylov",
"@ermakovolegs",
"@wouzar",
"@_sashashakun",
"@myBloodyScala",
"@lmnet89",
"@laughedelic",
final class JavaTimerScheduler {
private val timer = new Timer()
def scheduleOnce[T](delay: FiniteDuration)(job: => T)(implicit ec: ExecutionContext): JobHandler[T] = {
val promise = Promise[T]
val task = new TimerTask {
def run(): Unit = {
Future {
val result = job // Execute a job
case class Style(xs: Map[String, String]) {
def +(s: Style) = Style(xs ++ s.xs)
def mkString = xs
.map { case (k, v) => s"$k: $v;" }
.mkString(" ")
}
object Style {
@fomkin
fomkin / minscalaactors.scala
Last active July 10, 2017 12:10 — forked from viktorklang/minscalaactors.scala
Minimalist Scala Actors (typed version)
/*
Copyright 2012 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
import shapeless._
import shapeless.nat._
import shapeless.ops.nat.GT._
import shapeless.ops.nat.GTEq._
import shapeless.ops.nat._
import shapeless.syntax.sized._
import scala.collection.mutable
/**

Keybase proof

I hereby claim:

  • I am fomkin on github.
  • I am fomkin (https://keybase.io/fomkin) on keybase.
  • I have a public key whose fingerprint is 6BEE BA4C 8D4C 6826 0A5D 4253 1125 8561 B6FA 7169

To claim this, I am signing this object:

kevent(0x3, 0x0, 0x0) = 1 0
kevent(0x3, 0x0, 0x0) = 1 0
recvfrom_nocancel(0x4, 0x7FFF5996E6F0, 0x1C) = 28 0
recvfrom_nocancel(0x4, 0x7FFD117007A0, 0x32) = 50 0
select_nocancel(0x5, 0x7FFF5996E720, 0x0) = 0 0
kevent(0x3, 0x7FFF5996E1F0, 0x1) = 0 0
sendto_nocancel(0x4, 0x7FFD11700710, 0x1C) = 28 0
close_nocancel(0x3) = 0 0
getrlimit(0x1008, 0x7FFF5996E748, 0x1C) = 0 0
open_nocancel("/etc/hosts\0", 0x0, 0x1B6) = 3 0
var bb = new Blob([`
onmessage = function(e) {
postMessage('pong');
};
postMessage('started');
`]);
var worker = new Worker(window.URL.createObjectURL(bb));
var startTime = -1;