Skip to content

Instantly share code, notes, and snippets.

#![feature(async_await, await_macro, futures_api)]
use futures::task::SpawnExt;
use futures::io::{AsyncReadExt, AsyncWriteExt, AllowStdIo};
use romio::TcpStream;
async fn send_and_receive_request(id: i32) {
eprintln!("BEGIN send_and_receive_request #{}", id);
@frol
frol / auto-rc.rs
Created January 7, 2019 23:01
This is just an abuse of Not operator to get a shortcut syntax
#[derive(Debug, Clone)]
struct AutoRc<T>(pub std::rc::Rc<T>);
impl<T: Clone> std::ops::Not for &AutoRc<T> {
type Output = AutoRc<T>;
fn not(self) -> Self::Output {
AutoRc(self.0.clone())
}
}
@frol
frol / qq.kt
Last active February 28, 2019 22:18
// Simple
fun arrayManipulation(n: Int, queries: Array<Array<Int>>): Long {
val checkpoints = Array<Long>(n, { 0 })
for ((start, end, value) in queries) {
checkpoints[start - 1] += value.toLong()
if (end < n) {
checkpoints[end] -= value.toLong()
}
}
@frol
frol / qq.rs
Created February 28, 2019 22:26
// Simple
fn array_manipulation_simple(n: usize, queries: &[(usize, usize, isize)]) -> isize {
let mut checkpoints = vec![0; n];
for &(start, end, value) in queries {
checkpoints[start - 1] += value;
if end < n {
checkpoints[end] -= value;
}
}
/// This is a direct line-by-line translation from C++ solution:
/// https://github.com/LyashenkoGS/cpluplus_study/blob/master/test/Solution.cpp
///
/// The point is to show that Rust can save your ass.
struct Solution {}
impl Solution {
fn processParenthesis(stack1: &mut Vec<char>, item: char, openSign: char, closingSign: char) {
if item == openSign {
//! https://leetcode.com/problems/container-with-most-water/
//!
//! Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i,
//! ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0).
//! Find two lines, which together with x-axis forms a container, such that the container contains
//! the most water.
//!
//! Note: You may not slant the container and n is at least 2.
fn max_area_brute_force(height: Vec<i32>) -> i32 {
@frol
frol / habr-swift-vs-rust.rs
Created May 6, 2019 14:25
My refactored version of Rust implementation to the article "Swift против Rust — бенчмаркинг на Linux с (не)понятным финалом" https://habr.com/en/post/450512/
//[dependencies]
//serde_json = "1.0"
use serde_json::Value;
use std::collections::{HashMap, HashSet};
const FILE_BUFFER_SIZE: usize = 50000;
//source data
#[derive(Default)]
@frol
frol / qq.sql
Created June 17, 2019 17:19
DOTS queries
SELECT COUNT(*) FROM dots.`2018_users`;
SELECT COUNT(*) FROM dots.`2018_problems`;
SELECT COUNT(*) FROM dots.`2018_solutions`;
SELECT COUNT(*) FROM dots.`2018_messages`;
SELECT * FROM dots.`2018_problems` WHERE complexity > 1;
$ ./scripts/start_localnet.py
****************************************************
* Running NEAR validator node for Local TestNet *
****************************************************
Using default tag: latest
latest: Pulling from nearprotocol/nearcore
c64513b74145: Pull complete
01b8b12bad90: Pull complete
c5d85cf7a05f: Pull complete
@frol
frol / main.ts
Created September 22, 2019 12:38
Example of a chained smart-contracts in NEAR
import { context, storage, logging, ContractPromise, util } from "near-runtime-ts";
export class AddArgs {
a: i32;
b: i32;
};
export class MultiplyByArgs {
x: i32;
};