Skip to content

Instantly share code, notes, and snippets.

View greyblake's full-sized avatar
🇺🇦
#StandWithUkraine

Serhii Potapov greyblake

🇺🇦
#StandWithUkraine
View GitHub Profile
extern crate rand;
use rand::Rng;
const WIDTH : usize = 80;
const HEIGH : usize = 40;
const SIZE : usize = WIDTH * HEIGH;
type MatrixLine = [bool; WIDTH];
use std::cell::Cell;
#[derive(Debug)]
struct Ab {
a: i32,
b: i32,
cache: Cell<Option<i32>>
}
impl Ab {
trait A {
fn a(&self);
}
trait B {
fn b(&self);
}
trait C {
fn c(&self);
extern crate hyper;
extern crate tokio_core;
extern crate hyper_tls;
extern crate futures;
extern crate serde_json;
extern crate serde;
#[macro_use]
extern crate serde_derive;
use hyper::header;
macro_rules! list_enum {
( $type:ident, { $($el:ident),* } ) => {
#[derive(Debug,Clone,Copy)]
enum $type{
$($el),*
}
impl $type {
pub fn list() -> &'static[$type] {
const LIST : &'static[$type] = &[$($type::$el),*];
@greyblake
greyblake / log_exec.rs
Created January 17, 2018 21:09
Log exec
use std::time::Duration;
use std::time::Instant;
// Executes `func` and logs warning or error message if it takes longer than specified.
pub fn log_exec<F, T>(label: &str, warn_millis: u64, error_millis: u64, func: F) -> T where F: FnOnce() -> T {
let warn_duration = Duration::from_millis(warn_millis);
let error_duration = Duration::from_millis(error_millis);
let start = Instant::now();
let output = func();
require "securerandom"
require "digest/md5"
require "benchmark"
data1 = SecureRandom.random_bytes(5 * 1024 * 1024)
data2 = data1.dup
N = 500
Benchmark.bm do |x|
@greyblake
greyblake / .travis.yml
Created September 15, 2018 14:40
Minimal rust setup for travis ci
language: rust
rust:
- stable
install:
- rustup component add rustfmt-preview
- rustup component add clippy-preview
script:
- cargo fmt -- --check
- touch ./src/main.rs && cargo clippy -- -D warnings
- cargo test
@greyblake
greyblake / http-poll.spec.ts
Last active December 2, 2018 21:23
http-poll
import { throwError, of, interval, Observable } from 'rxjs';
import { take, filter, map, concatMap, catchError } from 'rxjs/operators';
import { httpPoll, isNotReady } from './http-poll';
function buildError(code) {
return {
error: {
errors: [{ code }]
}
@greyblake
greyblake / rust-playground.sh
Last active March 12, 2021 16:56
Creates new rust project and runs `cargo watch` with vim in tmux
#!/bin/sh
PLAYGROUNDS_DIR="/tmp/rust-playgrounds"
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
PROJECT_DIR="${PLAYGROUNDS_DIR}/playground${TIMESTAMP}"
cargo new $PROJECT_DIR
cd $PROJECT_DIR
# Add dependencies