This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ResultInner<T, E> = | |
| { type: 'OK', value: T } | |
| { type: 'ERROR', error: E }; | |
interface MatchHandlers<T, E, R> { | |
ok: (value: T) => R, | |
err: (error: E) => R, | |
} | |
class Result<T, E> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// USAGE EXAMPLE | |
render() { | |
const { currentUserState, nearEnv } = this.state; | |
return currentUserState.match({ | |
notAsked: () => <HomePage />, | |
loading: () => <HomePage />, | |
failure: (err) => <>Error occurred</>, | |
success: (user) => <AppRouter currentUser={user} nearEnv={nearEnv} />, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use lingua::LanguageDetectorBuilder; | |
use std::time::Instant; | |
const N: usize = 10_000; | |
fn main() { | |
let goethe = "Wir sollen eben nicht in Ruhe bleiben! Gleich wird uns, wenn wir zu genießen denken, Zur Übung unsrer Tapferkeit ein Feind, Zur Übung der Geduld ein Freund gegeben"; | |
let pushkin = "Я помню чудное мгновенье: Передо мной явилась ты, Как мимолетное виденье, Как гений чистой красоты."; | |
let detector = LanguageDetectorBuilder::from_all_languages().build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "securerandom" | |
require "digest/md5" | |
require "benchmark" | |
data1 = SecureRandom.random_bytes(5 * 1024 * 1024) | |
data2 = data1.dup | |
N = 500 | |
Benchmark.bm do |x| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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),*]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
NewerOlder