Skip to content

Instantly share code, notes, and snippets.

Avatar

包布丁 bdbai

  • Singapore Management University
  • 江苏苏州
View GitHub Profile
@bdbai
bdbai / bench_iter.rs
Created Feb 2, 2022
Bench Rust Iter func
View bench_iter.rs
use criterion::{black_box, criterion_group, criterion_main, Criterion};
const UPPER: u32 = 10_000;
pub fn is_odd(n: u32) -> bool {
n % 2 == 1
}
pub fn f1(upper: u32) -> u32 {
let mut acc = 0;
@bdbai
bdbai / dec_qq_number.rs
Created Dec 1, 2021
My QQ number Rust quiz
View dec_qq_number.rs
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3a2c2557cb1b7d0a313c1e011ba16844
use rand::prelude::*;
fn main() {
let mut rng = SmallRng::from_seed([0x56u8; 32]);
(0..10).for_each(|_| (rng.next_u32(), ()).1);
let key: [u8; 20] = [
70, 121, 148, 150, 158, 158, 73, 14, 197, 164, 232, 30, 239, 6, 112, 10, 130, 30, 55, 173,
];
@bdbai
bdbai / main.cc
Created Oct 13, 2021
SQLite multithread test
View main.cc
#include <array>
#include <atomic>
#include <cstdint>
#include <cstdio>
#include <memory>
#include <thread>
#include "sqlite3.h"
using std::atomic;
View ring-build-error.sh
cargo build -Z build-std=std,panic_abort --target thumbv7a-uwp-windows-msvc
Compiling core v0.0.0 (C:\Users\bdbai\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core)
Compiling ring v0.16.20
error: failed to run custom build command for `ring v0.16.20`
Caused by:
process didn't exit successfully: `D:\proj\ytflow\src\Maple\leaf\target\debug\build\ring-3b53a4a0d4ad7221\build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at '"C:\\Users\\bdbai\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\ring-0.16.20\\pregenerated\\aesv8-armx-linux32.obj": Os { code: 2, kind: NotFound, message: "系统找不到指定的文件。" }', C:\Users\bdbai\.cargo\registry\src\github.com-1ecc6299db9ec823\ring-0.16.20\build.rs:769:10
stack backtrace:
@bdbai
bdbai / main.cc
Last active Dec 26, 2019
Typed C++ event handler
View main.cc
#include <iostream>
#include <string>
#include <type_traits>
// 使用了 https://github.com/irrequietus/typestring (Mozilla Public License 2.0)
// https://github.com/irrequietus/typestring/blob/master/typestring.hh
#include "typestring.hh"
// 事件参数
struct PrivateMessageEvent {
@bdbai
bdbai / main.rs
Created May 30, 2019
Merge and sort N sorted vectors
View main.rs
use std::cmp::Ordering;
use std::collections::BinaryHeap;
use std::slice::Iter;
struct Item<'a> {
iter: Iter<'a, i32>,
elem: i32,
}
impl<'a> PartialEq for Item<'a> {
fn eq(&self, other: &Self) -> bool {
View DeviceList.jsx
class DeviceList extends Component {
initTable() {
$(this.refs.tableDom).bootgrid({
formatters:{
"operation":function(column , row){
return 'aaa';
}
}
});
}
@bdbai
bdbai / server.js
Last active Aug 16, 2016
A simple instant web crawler server
View server.js
var express = require('express');
var cheerio = require('cheerio');
var superagent = require('superagent');
var app = express();
app.get('/', (req, res) => {
Promise.all(Array.from(Array(42).keys()).map(i => // 从 0 到 41
new Promise((resolve, reject) => {
superagent.get('http://ipn.li/kernelpanic/' + (i+1).toString())
.end((err, sres) => {
@bdbai
bdbai / coreclr-debug
Last active Jun 30, 2016
.NET Core Debugger installation output
View coreclr-debug
Starting 'dotnet --info'
.NET Command Line Tools (1.0.0-preview2-003121)
Product Information:
Version: 1.0.0-preview2-003121
Commit SHA-1 hash: 1e9d529bc5
Runtime Environment:
OS Name: opensuse
OS Version: 42.1
@bdbai
bdbai / youku_speedup.cs
Created May 14, 2016
Youku speed up claiming
View youku_speedup.cs
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
namespace HttpWebRequestDemo
{
class Program
{
async static Task<int> Run(string user, string pass) {