Skip to content

Instantly share code, notes, and snippets.

View wayslog's full-sized avatar
🌙
我可以吞下玻璃而不变成玻璃

WaySLOG wayslog

🌙
我可以吞下玻璃而不变成玻璃
  • example.com
  • Shanghai, China
View GitHub Profile
import random
import time
def main():
random.seed(time.time())
names = open("names.txt").read().split("\n")
items = ["iPad mini6 64G"] * 5 + ["iPad 9th 256G"] * 15 + ["apple watch 9 45mm al"]*3
random.shuffle(names)
for (name, item) in zip(names, items):
print(f"{name} {item}")
@wayslog
wayslog / max_constexpr.cc
Last active September 15, 2019 17:50
get max size of Type List in constexpr
#include <iostream>
struct A {
uint64_t f1;
};
struct B {
uint64_t f1;
uint64_t f2;
};
pub struct BufferInterval<T, S, I>
where
T: Stream<Item = I>,
S: Store<Item = I>,
I: Clone,
{
interval: Interval,
rx: T,
store: S,
}
@wayslog
wayslog / Lanaya Open API
Created December 4, 2017 06:10
lanaya open api v2
# Lanaya apiv2
## POST /api/v2/clusters
### json参数
| 参数名 | 参数类型 | 是否必须 | 备注 |
|--------------------|----------|----------|------------------------------------------------------|
#![feature(iterator_step_by)]
use std::time::SystemTime;
// 10! = 3_628_800
const TIMES: usize = 3_628_800 * 100;
fn lock_concurrency(worker: usize) {
use std::sync::{Mutex, Arc};
use std::thread;
@wayslog
wayslog / main.rs
Created July 17, 2017 08:28
rust locker and context switch
#![feature(test)]
extern crate test;
#[bench]
fn test_lock(b: &mut test::Bencher) {
use std::sync::Mutex;
let locker = Mutex::new(1u32);
b.iter(|| {
for _ in 0..1000 {
use std::time::SystemTime;
fn main() {
let letters: String = (b'a'..b'z' + 1).map(|c| c as char).collect();
let repeated = letters.repeat(1000_0000);
let now = SystemTime::now();
let mut rslt: Vec<_> = (0..26).map(|_| 0).collect();
for ch in repeated.chars() {
let pos = ch as usize - 'a' as usize;
import gevent.monkey
gevent.monkey.patch_all()
import time
from multiprocessing import Process
import gevent
import redis
from lanaya.invoker.bind import unwrap_bind
c = redis.StrictRedis()
def greenlet_func():
time.sleep(5)
from collections import namedtuple
class Parent(namedtuple("Parent",'name')):
def show(self):
print(self.name)
class Child(namedtuple("FirstChild", "sex"), Parent):
def show_sex(self):
use std::{ops, fmt};
#[derive(PartialEq, Debug)]
pub struct Matrix<T> {
data: Vec<T>,
row: usize,
col: usize,
}
impl<T: Copy> Matrix<T> {