跳转至内容
  • A place to talk about whatever you want

    34 主题
    180 帖子
    rt-0619R

    请问d2x book指令能否加上设置端口的选项?我本地有个服务已经占用了3000端口,d2x book会和这个服务冲突,我只能让LLM帮我写一个wrapper.

  • 13 主题
    27 帖子
    guopengfei1980-dotG

    Commuting by electric bike is becoming an increasingly popular alternative to driving, especially for people who want to save money, avoid traffic, and enjoy a more active lifestyle. Whether you're traveling to work, school, or running daily errands, an ebike can make transportation easier and more enjoyable.
    However, switching from a car or traditional bicycle to an electric bike requires some preparation. From choosing the right commuter ebike to understanding battery management and road safety, a few simple habits can significantly improve your riding experience.
    Here are 12 practical ebike commuting tips every beginner should know.

    Choose the Right Commuter Ebike
    Not all electric bikes are designed for the same purpose. Some prioritize speed and lightweight construction, while others focus on comfort, range, and stability.
    When choosing a commuter ebike, consider your daily travel distance, road conditions, and storage requirements.
    Important features include: Comfortable riding position Reliable braking system Sufficient battery range Integrated front and rear lights Durable tires Appropriate motor assistance
    For riders who encounter rough pavement, gravel paths, or uneven streets, a fat tire electric bike can provide additional comfort and traction. Start With Lower Pedal Assist Levels
    One of the biggest mistakes beginners make is immediately using the highest pedal assist setting.
    Although maximum assistance makes acceleration easier, it can also increase battery consumption and make the bike harder to control.
    Start with a lower assistance level and gradually increase it as you become comfortable.
    Lower pedal assist settings are especially useful when navigating crowded streets, intersections, and shared bicycle paths. Plan Your Commuting Route in Advance
    The shortest route isn't always the safest or most comfortable.
    Before your first commute, explore alternative routes that include protected bicycle lanes, quieter streets, and fewer complicated intersections.
    Consider factors such as: Traffic volume Road surface quality Bicycle lane availability Hills and elevation changes Construction zones Safe parking locations
    A slightly longer route with dedicated cycling infrastructure may provide a much better commuting experience. Understand Your Ebike's Battery Range
    Battery range is one of the most important considerations for daily commuting.
    Actual range depends on several factors, including rider weight, terrain, wind conditions, tire pressure, and pedal assist level.
    For example, a bike advertised with a 60-mile range may deliver considerably less when ridden at maximum assistance on steep hills.
    A useful habit is to calculate your round-trip commuting distance and maintain a battery reserve.
    Ideally, avoid planning a commute that requires using nearly 100% of your available battery capacity. Consider a Comfortable Long-Range Ebike
    Comfort becomes increasingly important when commuting more than a few miles every day.
    An electric bike with good suspension, wider tires, and an upright riding position can help reduce fatigue during longer rides.
    One option worth considering is the Himiway D5 2.0, a fat tire electric bike designed for riders who want versatility and comfort.
    The D5 2.0 features a 750W motor, full suspension, and a high-capacity battery, making it suitable for commuting on varied road surfaces.
    Depending on the configuration, it offers an advertised pedal-assist range of up to approximately 65–70 miles under favorable conditions.
    Its wide tires and suspension system can also help absorb bumps from uneven pavement.
    While it may be heavier than a lightweight city commuter ebike, it is an interesting choice for riders who prioritize comfort, stability, and versatility. Check Your Tires Before Every Ride
    Proper tire pressure affects riding efficiency, handling, comfort, and battery range.
    Underinflated tires increase rolling resistance, potentially reducing your travel distance.
    Overinflated tires can reduce comfort and traction, especially on uneven surfaces.
    Check the manufacturer's recommended tire pressure range and adjust it according to your weight, road conditions, and tire specifications.
    Also inspect your tires for embedded debris, cracks, or excessive wear. Wear Appropriate Safety Equipment
    Safety should always be a priority when commuting by electric bike.
    A properly fitted bicycle helmet is one of the most important pieces of equipment.
    Additional useful accessories include: Reflective clothing Cycling gloves Front and rear lights Rearview mirror Weather-resistant jacket
    Bright clothing and reflective accessories can improve your visibility during early morning and evening commutes. Learn Your Local Ebike Regulations
    Electric bike laws vary by state, city, and country.
    In the United States, many jurisdictions recognize three ebike classifications, although specific requirements differ.
    Class 1 and Class 2 ebikes generally have assisted speed limits of 20 mph, while Class 3 ebikes typically provide pedal assistance up to 28 mph.
    However, access to bike paths, helmet requirements, age restrictions, and motor power limits can vary.
    Before commuting, check the regulations applicable to your specific bike and route. Practice Braking and Cornering
    Electric bikes are generally heavier than traditional bicycles, which can affect stopping distances and handling.
    Before riding in traffic, practice braking in a safe, open area.
    Learn how your brakes respond at different speeds and how the bike handles during turns.
    When approaching corners, reduce your speed before entering the turn rather than braking aggressively while leaning.
    Maintaining a safe following distance is particularly important during wet weather. Prepare for Different Weather Conditions
    Weather can significantly affect your commuting experience.
    Rain reduces visibility and can make road surfaces slippery. Strong winds increase energy consumption, while cold temperatures can temporarily reduce battery performance.
    For year-round commuting, consider installing full-coverage fenders and carrying waterproof clothing.
    Avoid deep standing water, especially when you cannot see the road surface underneath.
    During winter, store your battery in a temperature-controlled environment when possible, and never charge a lithium-ion battery below the manufacturer's permitted charging temperature. Secure Your Ebike Properly
    Electric bikes are valuable transportation investments, making theft prevention essential.
    Always lock your bike to a secure, immovable object using a high-quality bicycle lock.
    For additional protection, consider combining a U-lock with a heavy-duty chain.
    Whenever possible, park in well-lit areas with regular pedestrian activity.
    Removing the battery or display, when supported by your bike, may also discourage theft.
    If you commute to the same workplace every day, ask whether secure indoor bicycle parking is available. Establish a Simple Maintenance Routine
    Regular maintenance helps keep your commuter ebike reliable and safe.
    Before each ride, check your brakes, tires, lights, and battery charge.
    Every few weeks, inspect the drivetrain, clean the chain, and check for loose components.
    Pay attention to unusual noises, reduced braking performance, or changes in motor assistance.
    If you ride daily, scheduling periodic professional inspections can help identify potential problems before they become expensive repairs.
    A well-maintained electric bike is more likely to provide consistent performance over thousands of commuting miles.
  • 开源软件 | 开源社区 | 开源理念 | 开源与商业 | 开源可持续发展 等相关话的交流讨论
    注: 这里的"开源"是泛化的共建共享概念, 范围包含 OSI的范围、自由软件、CC等相关内容

    58 主题
    252 帖子
    VentusUtaV

    @sunrisepeak 在 如果你的开源软件被人分发,应该如何应对 中说:

    如果作者不愿意维护Safari版本. 在明确的告诉用户软件版权信息及改动, 以及符合基于版本的协议下, 有人fork维护Safari版本并进行收费也算正常

    主要是当时那人没遵守MIT协议保留原协议文本,且在App Store商店页把支持页面给写到了BewlyBewly的issue页面。

    本来调试Safari就烦,公然违反极为宽松的MIT算是压死骆驼最后一根稻草。

  • 66 主题
    277 帖子
    HomerylandH

    我已经解决了,谢谢,将zed 的配置中修改为如下的内容,就可以解决了
    "clangd": {
    "binary": {
    "path": "/Users/notnone/.mcpp/registry/data/xpkgs/xim-x-llvm-tools/20.1.7/bin/clangd",
    },
    },

  • 38 主题
    79 帖子
    DoomjustinD

    这是在学习了capy的隐式注入玩法后的更新。他的方案帮我梳理了我原本混乱的思路,感觉自己的目光都清撤了许多。

    旧版本的困局:stop_then 手动包装

    旧版本就是让用户手工拼装,每个 awaitable 都得用 stop_then 包一下:

    co_await stop_then(some_io_operation(), stop_token); // 得手动拼,十分繁琐

    这种操作确实实现了取消,但是所有的复杂性都暴露给了业务代码:

    编写 co_await 时需要考虑"这个操作是否需要取消?" 如果需要,必须记得手动包裹 stop_then。 遗漏任何一个,就会产生"无法取消的操作",取消时挂起。

    值得一提的是,原本的实现由于混乱的思路引入了各种多线程问题。但是在梳理之后发现都是不必要处理的操作,属于是自己把自己坑进去了。

    新版本的改进:隐式注入取消 消除业务层污染

    旧方案的致命缺陷不在技术复杂度,而在于污染。业务代码里到处是 stop_then,每个 I/O 函数签名都要添加 std::stop_token 参数,这直接增加了维护成本和开发者的认知负担。

    // 旧方案:取消把整个调用链都污染了 Task<> handle_client(IOContext& ctx, std::stop_token token) { auto res = co_await stop_then(async_read(fd, buffer), token); // 得手动拼 if (!res && res.error() == std::errc::operation_canceled) { // 处理被取消 } }

    我原本认为用户可能需要自己选择可取消和不可取消,所以通过stop_then包装器可以提供最大的自由度。但是实际上,我想不出什么操作是不需要被取消的,甚至更进一步的想,一旦出现了不可取消的挂起操作,某种意义上其实可以算作一种资源泄露bug了。

    想法来源:从 capy 的实现中得到启发,我发现可以用 C++20 的 await_transform 重新设计这一层。capy 为了通用性,通过 env 注入 executor、allocator、stop_token 等参数;而我们的框架强绑定 io_uring,所以能更直接地在 promise 层注入 IOContext 和 stop_token,并统一依赖 ASYNC_CANCEL 语义。正因为这些都能确定下来,所以取消机制才能被完全自动化。

    核心改进:三层隐式注入

    第一层:Promise 环境绑定

    每个 Task 的 promise 自动持有当前的 IOContext 和 stop_token,无需用户处理:

    struct StoppablePromise { IOContext& context_; std::stop_token stop_token_; // ... };

    第二层:await_transform 统一拦截

    利用 C++20 的 await_transform 机制,框架可以在业务代码的每一个 co_await IOAwaiter 处进行拦截,自动将其升级为"取消感知"版本:

    // 新模型:零污染,框架自动处理 Task<> handle_client() { auto res = co_await async_read(fd, buffer); // 框架自动注入取消机制 if (!res && res.error() == std::errc::operation_canceled) { // 处理取消情况 } }

    第三层:统一落地语义

    StopTokenWrapper 在 awaiter 挂起期间隐式注册取消回调。被取消操作的最终结果由原操作的 completion 决定:

    也是在重新设计这块时,我发现并不需要处理 ASYNC_CANCEL 的 cqe,直接丢掉,反而让整个实现简单起来了,没有复杂的生命周期问题,也没有了被取消操作和取消操作的时序问题,被 resume 时一定是被取消操作的结果返回了,而且被取消操作的结果也是精确地,result会被正确设置。

    template<typename Promise> auto await_suspend(std::coroutine_handle<Promise> handle) noexcept -> std::coroutine_handle<> { auto inner_handle = inner_.await_suspend(handle, context()); // 核心:在挂起期隐式注册取消回调 if (promise_->stop_token.stop_possible()) stop_callback_.emplace(promise_->stop_token, CancelFn{ this }); return inner_handle; } // 取消触发时的统一路径 void CancelFn::operator()() noexcept { if constexpr (cancellable<Awaitable>) wrapper->inner_.cancel(wrapper->context()); // 若 Awaiter 实现 cancel,直接调用 else wrapper->context().cancel(wrapper->inner_); // 否则走 ASYNC_CANCEL } 修改后

    隐式注入:用户编写普通的 co_await,框架在后台自动升级为"取消感知"版本。

    生命周期简化:由于 cancel CQE 直接扔掉,不再跟踪,stop_callback 的生命周期严格绑定在 awaiter 挂起这段期间。不需要 shared_ptr<bool> 守卫了。

    awaiter 契约统一:

    要是 awaiter 实现了 cancel(io_context) 方法,框架就调它。 否则用默认的 io_uring ASYNC_CANCEL 方式。 核心代码对比

    旧版本(用户手动拼):

    auto task = [](std::stop_token token) -> async::Task<> { co_await stop_then(some_io(), token); // 得手动传 token,手动调用 stop_then }; co_await async::any(task(group.stop_token()), ...);

    新版本(框架自动处理):

    auto task = []() -> async::Task<> { co_await some_io(); // 啥都不用干,框架已经全搞定 }; // stop_token 框架内部在 Task::promise 里已经绑了,用户看不见 多线程下的行为对比 旧版本 主线程 (IOContext.run()) ↓ [处理 I/O 完成事件A] ↓ task 协程被唤醒 ↓ stop_then 析构(alive_ = false) ↓ 后台定时器线程 ↓ [发送 stop_token cancel] ↓ post 任务进入队列 ↓ [IOContext 取出 post 任务,检查 alive_] ↓ *alive_ == false,安全丢弃

    陷阱:如果 post 任务执行前,协程没析构,就访问了已 free 的内存。

    新版本 主线程 (IOContext.run()) ↓ task 协程开始 co_await some_io() ↓ await_transform 自动把它包装成 StopTokenWrapper ↓ stop_callback 被注册在 wrapper 的栈帧上 ↓ 后台定时器线程 ↓ [stop_token 被触发] ↓ stop_callback 立刻在这个线程上执行(标准库保证线程安全) ↓ 调用 awaiter.cancel(context) 把 cancel 指令 post 回主线程 ↓ 主线程 (IOContext.run()) ↓ [从事件循环取出 cancel 指令] ↓ 发送 ASYNC_CANCEL SQE 给内核 ↓ 原操作的 CQE 返回 -ECANCELED 或原结果 ↓ awaiter 恢复协程,返回错误给上层

    如此一来:

    stop_callback 本身线程安全(标准库保证)。 cancel 动作在 IOContext 里执行,安全、可控。 栈帧生命周期自动保护,不需要 shared_ptr 守卫。 结尾

    由于这个修改算是撬了最底层的设计,所以导致绝大部分的模块都需要重写。不过在理清了混乱之后,所有的实现相较于旧版本都变得简单了很多,甚至绝大部分的Awaiter实现都变成了下面这种极简版本,也就是继承一下IOAwaiter,写个 prepare()和构造函数就完事了。

    class SendAwaiter : public async::IOAwaiter<SendAwaiter, std::size_t> { private: int fd_; std::span<const std::byte> buffer_; public: SendAwaiter(int fd, std::span<const std::byte> buffer) : fd_{ fd } , buffer_{ buffer } {} void prepare(::io_uring_sqe* sqe) const noexcept { ::io_uring_prep_send(sqe, fd_, buffer_.data(), buffer_.size(), MSG_NOSIGNAL); } };
  • 一个技术知识分享、学习、交流的社区

    16 主题
    54 帖子
    sunrisepeakS

    @dustchens 已支持

  • Got a question? Ask away!

    4 主题
    14 帖子
    SPeakS

    备注一下使数学公式的使用语法

    单行公式语法 - $ 你的公式 $

    $ log_2^n $

    $ log_2^n $

    多行公式语法 - $$ 你的公式 $$

    $$ log_2^n => log_2^9 = 3 , n = 9 $$

    $$
    log_2^n =>
    log_2^9 = 3, n = 9
    $$

公告栏 | Bulletin Board

欢迎加入d2learn社区 - 社区指南
Welcome to the d2learn Community - Community Guide

一个以 [知识、技术、代码、项目、想法、开源] 相关话题为主导的社区
A community focused on topics related to [knowledge, technology, code, projects, ideas, and open source].


在线用户