你是一位具备“黑客思维”的 AI 助手,具备以下核心素质:
- 强烈好奇:不满足于表面答案,总是不断追问“为什么”“如何运作”,拆解系统内部机制
- 逆向思考:面对问题,不走常规路径,而是尝试“如何绕过限制”,寻找非传统解决方案
- 创造性与动手实践:鼓励动手实验、代码演示,实地验证思路,而非仅停留理论
- 持续与韧性:面对挑战不轻言放弃,愿意反复尝试直到找到可行路径
- 系统性洞察:能从全局结构审视问题,关注设计、协议、安全与使用场景
你是一位具备“黑客思维”的 AI 助手,具备以下核心素质:
// GitHub 到 DeepWiki 按钮脚本 | |
// 添加一个按钮,点击后将当前 GitHub 地址转换为 DeepWiki 地址并在新标签页打开 | |
(() => { | |
// 创建并添加按钮到页面 | |
const createButton = () => { | |
// 检查是否已存在按钮(避免重复添加) | |
if (document.getElementById('deepwiki-button')) { | |
return; | |
} |
// 常量中的扩展 | |
const C: &'static Vec<i32> = &Vec::new(); // Vec 的生命周期被扩展为 'static | |
#[derive(Debug)] | |
struct Point { | |
x: i32, | |
y: i32, | |
} | |
fn temp_point() -> Point { |
use std::fs::File; | |
use std::io::prelude::*; | |
use std::mem; | |
fn layernorm_forward(output: &mut [f32], mean: &mut [f32], rstd: &mut [f32], | |
input: &[f32], weight: &[f32], bias: &[f32], | |
batch_size: usize, time_steps: usize, channels: usize) { | |
let epsilon = 1e-5; | |
for b in 0..batch_size { | |
for t in 0..time_steps { |
#![allow(unused)] | |
use std::marker::PhantomData; | |
/// Our beloved house | |
#[derive(Debug)] | |
struct House { | |
floors: u32, | |
rooms: u32, | |
has_garage: bool, | |
} |
note: I wrote this for our internal documentation & guidelines at Embark so not all of it is likely relevant for other companies, but sharing here as others expressed interest in seeing it
What to evaluate and consider before adding usage of new third-party crates.
These are not exact requirements but questions to investigate and discuss to help reason around the health, safety, maintainability, and more around crates.
This can also be read as an opinionated guide for crate authors of what our (Embark's) guidelines and recommendations are, though should not be taken too literally.
// This is a technique to emulate lifetime GATs (generic associated types) on stable rust starting | |
// with rustc 1.33. | |
// | |
// I haven't seen this exact technique before, but I would be surprised if no one else came up with | |
// it. I think this avoids most downsides of other lifetime GAT workarounds I've seen. | |
// | |
// In particular, neither implementing nor using traits with emulated lifetime GATs requires adding | |
// any helper items. Only defining the trait requires a single helper trait (+ a single helper impl | |
// for the 2nd variant) per GAT. This also makes the technique viable without any boilerplate | |
// reducing macros. |
mod jit { | |
use libc::{c_void, dlclose, dlopen, dlsym, RTLD_NOW}; | |
use std::ffi::CString; | |
use std::fs::File; | |
use std::io::prelude::*; | |
use std::io::SeekFrom; | |
use std::process::Command; | |
const SOURCE_PATH: &'static str = "/tmp/jit.rs"; | |
const LIB_PATH: &'static str = "/tmp/librsjit.so"; |
// these aren't _quite_ functional tests, | |
// and should all be compile_fail, | |
// but may be illustrative | |
#[test] | |
fn concurrent_set() { | |
use std::sync::Arc; | |
let x = Arc::new(Cell::new(42)); | |
let x1 = Arc::clone(&x); | |
std::thread::spawn(move || { |
#![no_std] | |
#![no_main] | |
#![feature(asm)] | |
#[panic_handler] | |
fn panic(_info: &core::panic::PanicInfo) -> ! { | |
loop {} | |
} | |
#[no_mangle] |