p I've discovered a new hobby. It involves creating non-trivial libraries from scratch. (Not UI slop!) Except I don't write any code in editors. An agent does all of it. /p p It goes like this: /p p Set up an infinite loop so the coding agent that... /p ol li has a clear guard for correctness (unit tests) /li li has an objectively measurable, pass/fail outcome (performance benchmarks) /li li has…
p Recently, I gave my TOML library written in Swift a href='/2025/12/10/TOMLDecoder-0.4.1/' an 800% speed boost /a . The natural question after that is: how much faster can I push it? /p details summary I'm happy to report that TOMLDecoder now parses the a href='https://github.com/dduan/TOMLDecoder/blob/cea8f0bee33f37e0fcc33b566a742485c71196e7/Sources/Resources/fixtures/twitter.toml' Twitter…
p I just released version 0.4.1 of a href='https://github.com/dduan/TOMLDecoder' TOMLDecoder /a , a TOML 1.0 parser, and a href='https://developer.apple.com/documentation/swift/codable' decoder /a implemented in pure Swift. When decoding a TOMLDocument such as a href='https://github.com/dduan/TOMLDecoder/blob/cea8f0bee33f37e0fcc33b566a742485c71196e7/Sources/Resources/fixtures/twitter.toml' this…
p em I bought a 3D printer, and, as a result, got into 3D modeling recently. I'm still super new to everything. From experience, this means I should write down things I'm learning. The beginner's perspective is valuable to other beginners! /em /p p A a href='https://en.wikipedia.org/wiki/Squircle' squircle /a is a square who's corners are replaced by curves with g3 continuity, which can be thought…
h2 Introduction /h2 p In GRPC, one could define an RPC that, in addition to the normal request-response messages, it also defines a custom message to represent errors: /p pre code class='language-proto' message SignUpWithEmailRequest { string email = 1; string password = 2; string referral_code = 3; } message SignUpWithEmailResponse { AccessTokenDTO token = 1; } message…
p For curiosity's sake, I decided I want to play with MLIR's C API with Swift. I spent quite some time to get a skeleton project up and running on my Mac. Here's my notes for future reference. (If you find this useful, I'd be curious to know what you're working on!). /p p Modern LLVM comes shipped with MLIR. At the time of writing, all I had to do to get it is code brew install llvm /code . If you…
p I tried out GitHub Copilot this weekend. I've a href='/2023/03/03/qualia-that-was-coding/' been thinking /a , and talking, about AI like your average technology person. So here we are: what's my reaction to LLMs getting better and better at coding? /p p LLMs are great at information retrieval. Copilot or GPT read a lot of code from GitHub, StackOverflow, Reddit, etc. And now, given some context…
p em Alice: Hey, did you know that COVID virus was leaked from a lab? /em /p p Bob: No no, you don’t know that. Don’t be racist! /p p em Alice: Oh, sorry I didn’t know. How so? /em /p p Bob: Because the lab is in China. /p p em Alice: Ok, so where DID the virus come from? /em /p p Bob: It jumped from bats to pangolin, and then to humans in a wet market. /p p em Alice: A what market? /em /p p Bob:…
p As of this writing, I'm deeply skeptical of LLM replacing our needs for skilled programmers. Problem solving is a creative process. When a new tool takes away the repetitive part of a job, the worker can focus more on being creative. /p p However, if one believes that LLM, or some alternative models, will bring about the end of programming as a wide-spread human activity, then we'll have a…
p As of today, my identity in the quot;fediverse quot; has become code @daniel@duan.ca /code . This post was originally published on code duan.ca /code . Pretty neat, eh? I achieved this by hosting a private instance of the open-source Mastodon project. Here's my experience setting that up, and why it seemed harder than it is. /p h2 What exactly did I achieve? /h2 p I own the domain code duan.ca…
p From a purely personal perspective, connecting with people via the internet is good. I'm grateful that services such as Twitter exist. Since the year 2008, a significant amount of my life happened on Twitter. The only important component of Twitter is the connections. I'm lucky that some people like what I post. I'm used to a small stream of thoughts from those I follow. /p p These days, those I…
p For whatever reason, a dialogue from the Matrix trilogy stuck with me. I've never heard anyone else talk about these quotes. Maybe they aren't that deep and I have been over-projecting meanings. Anyways, Neo ( strong N /strong ) and Councillor Hamann ( strong H /strong ) are in the last human city Zion, looking at a vast array of machines. They had this exchange about em control /em : /p…
p Science discussion in the mainstream always focus on the reductive quot;pro quot; vs quot;anti quot; dynamic. While there are a lot of people in the world who flat-out em deny /em the existence of established science, making the mainstream conversation a worthy discourse, that's not what I'm trying to participate here. /p p Within the quot;for-science faction quot;, there are two seemingly…
p Growing up in China, I remember using google.cn daily. At some point in my teens, it stopped working, and I had to use google.com.hk . Then ... I left. The first time I got off the plane in the US, and got on a computer, google.com was the browser homepage. /p p Now, this is not a story about how important Google is to me (to the dismay of the fully adult version of me, it is). Around the same…
p How do you use use Instruments, the instrumentation tool distributed alongside Xcode? It's easy if you are profiling a macOS or iOS app. No so with a regular old command-line tool built, say, with SwiftPM. To do so, you'll need to codesign the target binary. Otherwise Instruments will give you a code quot;Failed to gain authorization quot; /code error message. /p p Here's the steps: /p ol li…
p The ideal outcome of using Nix or home-manager is to have as many things as possible under their control. Among these things are developer tools for coding. You may need code cargo /code , and code rust-analyzer /code for Rust projects; code ipython /code , and code python-lsp-server /code for Python projects, etc. /p p Of course, the simplest solution is to have them all installed and…
p So, you use a standalone home-manager, it's set up with flake, tracking a particular nixpkgs channel. How do you use a package from another channel? This seemingly simple task took me, a Nix noob, quite a bit of research to solve. Here's how I did it. /p p A simple flake.nix for home-manager might look like this: /p pre code class='language-nix' { inputs = { nixpkgs.url =…
p In the journey of growing software systems, there comes a point where certain engineering decision will create a chasm so large that it's practically impossible to go back. The initial crossing of this chasm is so easy that it often happens without anyone noticing. Nonetheless, it is a costly mistake. /p p On one side of this chasm, any member of the engineering team can answer the question…
h2 The problem /h2 p As of writing of this article, when you attempt to use Apple's Swift library a href='https://github.com/apple/indexstore-db' IndexStoreDB /a on Linux as a normal SwiftPM dependency, it won't build successfully: /p pre code class='language-fish' ❯ cat Package.resolved { quot;object quot;: { quot;pins quot;: [ { quot;package quot;: quot;IndexStoreDB quot;, quot;repositoryURL…
p During the holidays, I spent some time on the parser that underlies a href='https://github.com/dduan/TOMLDecoder' TOMLDecoder /a . The original implementation targeted TOML's spec version 0.5. A few release-candidates for version 1.0 has come out since then. So it's a good time to give this project attention. /p p Back in the 0.5 days, the TOML spec was (well) written in English with a few…
p em Note: as of Feburary, 2022, the steps written below has been incorporated by the official Nix install script for macOS. This article is, therefore, obsolete. /em /p p Here are the steps for installing nix on macOS 11 Big Sur. /p h3 Preparation /h3 p Decide on which disk the nix store is to be installed. By end of this process, you'll have a disk name like code disk4 /code . /p p Personally, I…
p I've never been patient enough to learn the JIRA plain-text syntax, depite being a frequent user throughout the years. So a while ago I wrote this little utility that lets me compose JIRA ticket in Markdown. Some thoughts were put into whether this should be an OSS and free (as in beer) app, or something I distribute via the Mac App Store. Ultimately, the first option prevailed. So, without…
p Swift has a pretty decent C-interoperability story. But C has many features! Today, I'll tell you a story involving a few not-so-well supported C features and Swift. /p p It all started when I decided to re-write a href='https://github.com/dduan/Pathos' Pathos /a with Windows support. One of the library's offering is reading the literal target of a symbolic link: if code b /code is a link to…
p One of the goals in the re-write of my VFS library a href='https://github.com/dduan/Pathos' Pathos /a is to make it go fast. What does that mean when most of the time users are hitting the hard drive when running your code? Well, let's not dwell on that for now. /p p A library like this passes em file paths /em back and forth with C APIs from the OS a lot. So one way to go fast is to keep the…
p I noticed a lot of people are playing these two games on Twitch recently: Fall Guys and Among Us. Personally, I think Fall Guys is a pretty fun game to play and Among Us is an entertaining game to watch. I'm glad these games are out and popular in this strange year, even though I'm not playing either frequently (perhaps that's a mistake). /p p Anyways, I want to write about this observation that…
p Having used macOS for a number of years, I've formed some habit that I'm never going to shake. Among them is taking screenshots with code Alt-Shift-3 /code and code Alt-Shift-4 /code , follow up with area or window selection. So, when I bought a PC and put Linux on it, it's time to mess with it for these habits! /p p And, it didn't take too long to solve. I've found a…
p After turning off stream on a href='https://twitch.tv/daniel_duan' Twitch /a , the first thing I normally do is exporting the stream video to YouTube, so that the stream has an archive that survives Twitch's short-ish retain policy. /p p These videos, perhaps surprisingly, get a few views! It's not a lot by any measures, but I'm conscientious of the fact that a typical stream archive is a…
p em Recently, I got a PC. And I started writing some code on Windows for the giggles. Naturally, I gravitate towards stuff I use on macOS and Linux when it comes to tooling. To my delight, NeoVim, ripgrep and fzf all work out of the box in terminal simulators, which brings us to todays main topic... /em /p p I made a terminal coloring library for Swift that works on Windows, a…
p tl;dr: To work on Rust project with nix-shell, rls and extensions such as code rust-analysis /code , code rust-src /code , without caring too much about specific Rust toolchain version (except for it being code stable /code ), use the following code shell.nix /code : /p pre code class='language-nix' let moz_overlay = import (builtins.fetchTarball…
p I took back my website. /p p I took it back from the claws of Jekyll and Ruby. I took it back from some random template among a few that were immediately available. I took it back from my own ignorance of modern web technology. /p p This time, I rewrote the hole effing thing from scratch. /p h3 The Why /h3 p The a href='/2017/01/16/site-changes/' last time /a I ended with /p blockquote p I wrote…
p It's been bothering me for years. /p p That is, code # /code is both the start of a comment in a git commit message, but also the syntax for headings in Markdown. /p p Personally, I prefer using commit messages to populate pull request descriptions whenever possible. On GitHub, This happens automatically when the pull request contains a single commit. But I can't type, say an H3 as code ###…
p In a purly reactive world, your entire program merge into a single stream. Now, close your eyes, and envision: your project as one, beautiful, stream. /p p Now open your eyes. Yeah, it's not. Your project is a Mac or iOS app. It's full of your memories, sweat, and blood. And you are ready to sweat and bleed some more by putting some Combine and SwiftUI into it. You watched the WWDC19 sessions…
p I enjoyed making a href='https://github.com/dduan/TOMLDeserializer' TOMLDeserializer /a and a href='https://github.com/dduan/TOMLDecoder' TOMLDecoder /a recently. Let's hope some projects will pick them up and TOML as a configuration format will start to spead in Swift communities. /p p What's outstanding about these projects is that I started working on them while a…
p As someone who lives in a terminal simulator, I'm pleasantly surprised by the new toys we get in recent years such as a href='https://github.com/junegunn/fzf' fzf /a , a href='https://github.com/BurntSushi/ripgrep' ripgrep /a , a href='https://github.com/sharkdp/fd' fd /a , etc. A great number of these are written in relatively young programming languages such as Go and Rust. But, noticibly,…
p I want to talk about this little function: /p pre code class='language-swift' func interact(_ process: (String) - gt; String) { var input = quot; quot; while let line = readLine() { input += line } print(process(input)) } /code /pre p Brief explanation: it reads all the input from stdin as a code String /code , feeds it into a closure code process /code , which it takes in as its only argument,…
p Recently, I discovered a curious thing about code Date /code s in two large projects I work on. Simply put, both projects receives, from various HTTP endpoints, the same object component: a timestamp, and a duration. Combining these two pieces, both projects derives two code Foundation.Date /code s to represent a time range. So far, so good. /p p However, project code A /code uses code…
p While implementing some file I/O APIs in a href='https://github.com/dduan/Pathos' Pathos /a , I decided reading/writing file content as code Foundation.Data /code is kind of important (can you blame me?). But Pathos, by accident, does not depend on Swift code Foundation /code . Now what? /p p After browsing the a href='https://developer.apple.com/documentation/foundation/data' documentation /a ,…
p Wrap file permissions from code stat /code and code chmod /code in an code OptionSet /code in Swift. /p div class='video-container' iframe src='https://www.youtube.com/embed/1ZrouR_F-AU' frameborder='0' gesture='media' allow='encrypted-media' allowfullscreen /iframe /div
p From the a href='/2018/01/13/coding-without-a-language/' AST /a and a href='/2018/01/20/scopes/' scopes /a , come a simple interpreter. This intepreter can quot;execute quot; the fibonacci function AST and produce a correct results. /p div class='video-container' iframe src='https://www.youtube.com/embed/C16PD44qyOY' frameborder='0' gesture='media' allow='encrypted-media' allowfullscreen=''…
p A short video on the concept of static scope. /p div class='video-container' iframe src='https://www.youtube.com/embed/o0jwyd8nUK4' frameborder='0' gesture='media' allow='encrypted-media' allowfullscreen /iframe /div
div class='video-container' iframe src='https://www.youtube.com/embed/OKjQtn_Gvug' frameborder='0' gesture='media' allow='encrypted-media' allowfullscreen='' /iframe /div p Sorry for the click-baity title. I actually really like this one. /p
p This video demonstrates a few things: the code readLine /code standard library function, scripting with Swift, and pattern matching as loop conditions. Enjoy! /p div class='video-container' iframe src='https://www.youtube.com/embed/8rAqzvChbak' frameborder='0' gesture='media' allow='encrypted-media' allowfullscreen /iframe /div
p Planning, recording and editing a video is something I find very enjoyable to do. However, I enjoy just working on stuff as well. So I'll occassionally post videos of me doing just that: writing code, mumbling, with all my verbal ticks and bad habits left unedited. Not sure who these videos are for but why the heck not, amiright? /p p The first one was scheduled to publish today, so I guess I…
p Every now and then, I check on the progress of Web Assembly. I did it again around the time of this post and finally found enough tutorials, examples, and working software to get myself started in this area. In doing so, I made a video to demo some progress. ( em this article includes all the same information and more, so just read on if you don't have 15 minutes for YouTube /em ). /p div…
p I guess I'm starting a series of minute-long videos. In this first video, I built code pwd /code out of code getcwd /code . The code turned out shorter than I imagined (1 line). Which is a good demonstration of Swift's great C-interop capability. /p div class='video-container' iframe width='560' height='315' src='https://www.youtube.com/embed/YR4MCcMnHrI' frameborder='0' gesture='media'…
p I discover, report, fix and merge a bug in the open-source Foundation project. And why, yes, on YouTube. /p div class='video-container' iframe src='https://www.youtube.com/embed/rwuj80W8TtI' frameborder='0' gesture='media' allow='encrypted-media' allowfullscreen /iframe /div ul li Pull request: a href='https://github.com/apple/swift-corelibs-foundation/pull/1376'…
ol li a href='#introduction' Introduction /a /li li a href='#the-basics' The Basics /a /li li a href='#compatibility-with-older-ios-versions' Compatibility with older iOS versions /a /li li a href='#how-to-screenshot-with-inverted-color-settings' How to screenshot with inverted color settings /a /li li a href='#conclusion' Conclusion /a /li /ol h2 Introduction /h2 p Apple sneakily shipped a…
p Alas, there's the 3rd and last video about code BitArray /code , originated on my spark of inspiration on a Caltrain ride home. This makes my first YouTube playlist as well, even tho the first 2 videos were planned to be completely separate. /p p We added more standard library functionalities to BitArray (ExpressibleByArrayLiteral, CustomStringConvertible, Equatable, etc). Then, we added…
p This video shows what it takes to open source a Swift project. Starting from some code in a playground, I created a framework that supports distribution via Swift Package Manager, CocoaPods, Xcode project and Carthage. The framework can be used across iOS, macOS, watchOS, tvOS and Linux. In addition, we also added SwiftLint to the project, added a Makefile, put everything on GitHub and set up…
p In this video, I build a space-efficient BitArray that confirms to code RandomAccessCollection /code in Swift in a playground. It involves some basic (but neat!) bitwise manipulation tricks. /p div class='video-container' iframe src='https://www.youtube.com/embed/-k_jrIoD56k' frameborder='0' gesture='media' allow='encrypted-media' allowfullscreen /iframe /div p I guess I'm a YouTuber now. You…