Coding practices are a source of a lot of arguments among programmers. Coding standards, to some degree, help us to put certain questions to bed and resolve stylistic debates. No coding standard makes everyone happy. (And even their existence is sure to make some unhappy.) What follows are the standards we put together on the Core team, which have become the general coding standard for all programming teams on new code development. We’ve tried to balance the need for creating a common, recognizable and readable code base with not unduly burdening the programmer with minor code formatting concerns.
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
full_query = "I love paris and new york with my friends " | |
length = 1 | |
local char_to_hex = function(c) | |
return string.format("%%%02X", string.byte(c)) | |
end | |
local function urlencode(url) | |
if url == nil then | |
return |
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::{io, marker, str}; | |
use std::borrow::Cow; | |
use zerocopy::{LayoutVerified, AsBytes, FromBytes}; | |
use serde::{Serialize, Deserialize, de::DeserializeOwned}; | |
// Do not forget to patch zerocopy to make it support str | |
// by using the `trivial_bounds` feature | |
pub trait EPAsBytes { | |
fn as_bytes(&self) -> Cow<[u8]>; |
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/bash | |
while true; do | |
ps -p $1 -o\%cpu,rss | awk 'NR>1 { gsub(",",".",$1); print $1","$2}' | |
sleep 0.2 | |
done |
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
#!/usr/bin/env bash | |
# usage: memlog.sh $(pidof PROCESS_NAME) [ PATH_FOLDER ] | |
# on osx pidof can be replaced by pgrep | |
# usage: memlog.sh $(pgrep PROCESS_NAME) [ PATH_FOLDER ] | |
set -e | |
PID=$1 |
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
fn linear_group(&self) -> LinearGroupBy<T, fn(&T, &T) -> bool> | |
where T: Ord | |
{ | |
LinearGroupBy::new(self, |a, b| a == b) | |
} |
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
fn all_eq<T: Eq>(slice: &[T]) -> bool { | |
match slice.split_first() { | |
Some((first, others)) => others.iter().all(|x| x == first), | |
None => true, | |
} | |
} | |
#[test] | |
fn all_eq_easy_eq() { | |
assert!(all_eq(&[1, 1, 1, 1, 1])); |
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
// prefer using IntoIterator ? | |
fn split_first<T, I>(mut iter: I) -> Option<(T, I)> | |
where I: Iterator<Item=T> | |
{ | |
match iter.next() { | |
Some(first) => Some((first, iter)), | |
None => None, | |
} | |
} |
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
pub enum Arg { | |
Int(i32), | |
Float(f32), | |
String(String), | |
Ptr(isize), | |
} | |
pub enum KernelError { | |
KernelInvalid, | |
} |
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
test async ... bench: 25,129,522 ns/iter (+/- 1,948,456) | |
test async_cpupool ... bench: 13,895,220 ns/iter (+/- 2,412,441) | |
test async_cpupool_cpus ... bench: 16,449,300 ns/iter (+/- 7,062,024) | |
test async_cpupool_many ... bench: 14,118,352 ns/iter (+/- 3,170,100) | |
test async_cpus ... bench: 11,057,663 ns/iter (+/- 1,546,785) | |
test async_many ... bench: 14,304,595 ns/iter (+/- 1,966,185) | |
test corona ... bench: 34,898,721 ns/iter (+/- 204,006,257) | |
test corona_blocking_wrapper ... bench: 35,851,174 ns/iter (+/- 76,716,240) | |
test corona_blocking_wrapper_cpus ... bench: 12,601,478 ns/iter (+/- 1,368,466) | |
test corona_blocking_wrapper_many ... bench: 20,098,071 ns/iter (+/- 84,982,750) |