Skip to content

Instantly share code, notes, and snippets.

View matklad's full-sized avatar

Alex Kladov matklad

View GitHub Profile
@matklad
matklad / a.xml
Created July 19, 2017 22:49
How `catch` identifier is used in Rust
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>file://$PROJECT_DIR$/swf-tree-0.0.3/src/avm1/actions.rs</file>
<line>103</line>
<entry_point TYPE="file" FQNAME="file://$PROJECT_DIR$/swf-tree-0.0.3/src/avm1/actions.rs" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Anonymous function parameter</problem_class>
<description>Interesting name</description>
</problem>
<problem>
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)