Skip to content

Instantly share code, notes, and snippets.

View matklad's full-sized avatar

Alex Kladov matklad

View GitHub Profile
extern crate clap;
extern crate csv;
struct TimeSerie {
data: Vec<f64>,
}
impl TimeSerie {
fn length(&self) -> usize {
trait Command {
fn cli(&self) -> clap::App;
fn execute(&self, config: &Config, args: &clap::Args);
}
trait WsCommand {
fn cli(&self) -> clap::App;
fn execute(&self, config: &Config, ws: &Workspace, args: &clap::Args);
@matklad
matklad / main.rs
Last active February 14, 2017 09:37
Adeven of code 2016 day 5
extern crate crypto; // [dependencies] rust-crypto = "0.2"
extern crate rayon; // [dependencies] rayon = "0.6"
use std::io::Cursor;
use std::io::Write;
use crypto::digest::Digest;
use rayon::prelude::*;
class Zn(private val modulus: Int) {
fun int(x: Int): ZnInt = ZnInt(x % modulus)
operator fun ZnInt.plus(rhs: ZnInt): ZnInt = int(this.value + rhs.value)
}
class ZnInt(val value: Int)
fun main(args: Array<String>) {
val ring = Zn(92)
@matklad
matklad / takeWhileInclusive.kt
Created December 24, 2016 21:03
An "inclusive" version of Kotlin's takeWhile
fun <T> Sequence<T>.takeWhileInclusive(pred: (T) -> Boolean): Sequence<T> {
var shouldContinue = true
return takeWhile {
val result = shouldContinue
shouldContinue = pred(it)
result
}
}
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <ctime>
#include <forward_list>
#include <iostream>
#include <list>
#include <unordered_set>
/**
* Executes long running tasks not faster then once in [delayMillis] and makes sure
* at most one tasks executes at a time. The task itself may take more than [delayMillis]
* to complete. Task may be asynchronous.
*/
private class DebouncingQueue(
private val delayMillis: Int,
parentDisposable: Disposable
) {
private val alarm = Alarm(Alarm.ThreadToUse.POOLED_THREAD, parentDisposable)
abstract class Query {
class Sum {
}
class Add {
}
@matklad
matklad / test.groovy
Last active December 1, 2016 10:17
Laconic test output for gradle
test {
testLogging {
events 'skipped', 'failed'
exceptionFormat = 'full'
}
beforeSuite { suite ->
if (suite.className != null) {
println()
println(suite.className)
@matklad
matklad / bfs.py
Last active November 11, 2016 10:28
def bfs(graph, start):
work = {start}
dist = {}
current_dist = 0
while work:
for u in work:
dist[u] = current_dist
work = {nb for u in work