Skip to content

Instantly share code, notes, and snippets.

View dcchut's full-sized avatar

Robert Usher dcchut

  • Biarri Networks
  • New York
  • 01:30 (UTC -04:00)
View GitHub Profile
@dcchut
dcchut / Example.rs
Created August 4, 2019 16:19
serde_postgres example
use postgres::{Connection, TlsMode};
use std::error::Error;
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
struct Person {
name : String,
data : Vec<u8>,
}
@dcchut
dcchut / Example-async.rs
Last active December 16, 2020 12:25
Async version of serde_postgres
#![feature(async_await)]
/*
Cargo.toml dependencies:
serde = { version = "1.0", features = ["derive"] }
tokio = { git = "https://github.com/tokio-rs/tokio", default-features = false, features = ["io", "codec"] }
tokio-postgres = { git = "https://github.com/sfackler/rust-postgres", branch = "std-futures" }
futures-preview = { git = "https://github.com/rust-lang-nursery/futures-rs" , features = ["nightly", "async-await"] }
futures-util-preview = { version = "0.3.0-alpha.4", features = ["compat"] }
This file has been truncated, but you can view the full file.
fn main() {
let nums_to_benchmark : Vec<(i32,i32,i32)> = vec![(49678, 2494304, 7747),(38317, 544696, 43415),(6138, 2659002, 29553),(2761, 338174, 19280),(16260, 78580, 24388),(7576, 3054594, 37834),(32334, 4008762, 19146),(22045, 3207579, 33318),(42883, 487804, 40486),(18995, 509658, 14608),(15182, 1631279, 24483),(49246, 181390, 8540),(9158, 903907, 12252),(7215, 739887, 48418),(7347, 479129, 20363),(33335, 1497364, 34157),(33863, 4825516, 37049),(13283, 3981839, 42750),(7280, 2323910, 29865),(49897, 3384470, 24753),(11419, 1855585, 23851),(10664, 3490976, 21358),(9915, 1636069, 29726),(26380, 1180405, 11148),(42070, 3515997, 35383),(35350, 154947, 17576),(26585, 2964227, 32090),(27540, 1234725, 19336),(31423, 429598, 37633),(23281, 3820176, 12618),(45460, 2454214, 39841),(31879, 2542761, 26047),(47494, 5023626, 27881),(1993, 1528222, 13698),(10235, 2261742, 29463),(35487, 4672382, 18952),(16893, 1172318, 48633),(40461, 3312564, 22174),(22129, 2208894, 26222),(17775, 1236585, 22282),(22497, 3840819, 2334
This file has been truncated, but you can view the full file.
fn main() {
let nums_to_benchmark : Vec<(i64,i64,i64)> = vec![(49678, 2494304, 7747),(38317, 544696, 43415),(6138, 2659002, 29553),(2761, 338174, 19280),(16260, 78580, 24388),(7576, 3054594, 37834),(32334, 4008762, 19146),(22045, 3207579, 33318),(42883, 487804, 40486),(18995, 509658, 14608),(15182, 1631279, 24483),(49246, 181390, 8540),(9158, 903907, 12252),(7215, 739887, 48418),(7347, 479129, 20363),(33335, 1497364, 34157),(33863, 4825516, 37049),(13283, 3981839, 42750),(7280, 2323910, 29865),(49897, 3384470, 24753),(11419, 1855585, 23851),(10664, 3490976, 21358),(9915, 1636069, 29726),(26380, 1180405, 11148),(42070, 3515997, 35383),(35350, 154947, 17576),(26585, 2964227, 32090),(27540, 1234725, 19336),(31423, 429598, 37633),(23281, 3820176, 12618),(45460, 2454214, 39841),(31879, 2542761, 26047),(47494, 5023626, 27881),(1993, 1528222, 13698),(10235, 2261742, 29463),(35487, 4672382, 18952),(16893, 1172318, 48633),(40461, 3312564, 22174),(22129, 2208894, 26222),(17775, 1236585, 22282),(22497, 3840819, 2334
import random
from collections import Counter
def roll(die_size, die_count):
return (random.randint(1, die_size) for _ in range(die_count))
def is_good_roll(rolls, threshold):
c = Counter(rolls)
return any(x >= threshold for x in c.values())
#![feature(lang_items)]
#![feature(alloc_error_handler)]
#![no_std]
pub mod another_module;
extern crate alloc;
use alloc::boxed::Box;
use async_recursion::async_recursion;