Skip to content

Instantly share code, notes, and snippets.

boxdot

Block or report user

Report or block boxdot

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gitlab_hook.rs
use gitlab::webhooks::WebHook;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Request, Response, Server};
use log::{log_enabled, Level};
async fn gitlab_webhook(req: Request<Body>) -> Result<Response<Body>, hyper::Error> {
log::debug!("< {:?}", req);
let body = hyper::body::to_bytes(req.into_body()).await?;
let event: Result<WebHook, _> = serde_json::from_slice(&body);
match event {
@boxdot
boxdot / num-stable-crates.rs
Created Nov 7, 2019
Calculate number of stable crates on crates.io
View num-stable-crates.rs
use std::cmp::Reverse;
use std::collections::HashMap;
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use walkdir::WalkDir;
fn get_version(entry: walkdir::Result<walkdir::DirEntry>) -> Option<String> {
let entry = entry.ok()?;
let path = entry.path();
View leaked_thread.rs
use actix::prelude::*;
use actix_web::{middleware, web, App, HttpResponse, HttpServer};
use log::info;
use std::io;
use std::thread;
use std::time::Duration;
fn my_handler() -> HttpResponse {
"Hello".into()
View test.rs
fn some_test -> Result<(), Error> {
let mut rt = tokio::runtime::Runtime::new().unwrap();
rt.spawn(microservice_1.map_err(|e| panic!(e)));
rt.spawn(microservice_2.map_err(|e| panic!(e)));
rt.spawn(microservice_3.map_err(|e| panic!(e)));
rt.spawn(microservice_4.map_err(|e| panic!(e)));
// do testing and do not touch rt anymore
}
View nom_error.rs
#[macro_use]
extern crate nom;
use nom::alpha;
use nom::types::CompleteStr;
use nom::ErrorKind;
named!(block<CompleteStr, Vec<(CompleteStr, CompleteStr)>>,
do_parse!(
tag!("BEGIN") >>
@boxdot
boxdot / Cargo.toml
Last active Oct 9, 2018
Example of a hyper service/server with rate limiting of requests
View Cargo.toml
[package]
name = "ratelimiting-server"
version = "0.1.0"
[dependencies]
futures = "0.1"
tokio = "0.1"
hyper = "0.12"
View elm-time.rs
#![allow(dead_code)]
extern crate futures;
extern crate time;
use futures::prelude::*;
use futures::sync::mpsc::{channel, Receiver};
use time::{Tm, now_utc};
use std::{thread};
View client.rs
impl Client {
pub fn connect(
handle: &Handle,
uri: hyper::Uri,
framework_info: mesos::FrameworkInfo,
) -> Box<Future<Item = Self, Error = failure::Error>> {
// Mesos subscribe essage
let mut call = scheduler::Call::new();
let mut subscribe = scheduler::Call_Subscribe::new();
subscribe.set_framework_info(framework_info);
View csv.rs
use std::fs::File;
use std::io::BufRead;
use std::io::Write;
use std::path::PathBuf;
#[derive(Debug)]
struct Args {
input: PathBuf,
column: String,
replacement: String,
View before_after.rs
// before
fn parse_args<Iter>(mut args: Iter) -> Result<Args, &'static str>
where Iter: Iterator<Item = String>
{
let hostname = match args.next() {
Some(s) => s,
None => return Err("argument 'hostname' missing"),
};
let port: u16 = match args.next() {
You can’t perform that action at this time.