Huffman Codes – How Do They Work?
https://two-wrongs.com/huffman-codes-how-do-they-work [two-wrongs.com]
2024-03-11 07:50
source: Dfly
tag: intro-programming
Huffman Codes – How Do They Work?
https://two-wrongs.com/huffman-codes-how-do-they-work [two-wrongs.com]
2024-03-11 07:50
source: Dfly
X's two ways to send events to X clients (more or less)
https://utcc.utoronto.ca/~cks/space/blog/unix/XTwoWaysToSendEvents [utcc.utoronto.ca]
2023-10-12 19:37
If you hang around people who automate things in their X session, you may have heard of xdotool. If you’ve tried it, you may have noticed that xdotool seems pretty successful in manipulating the windows of X programs, despite the general feelings about SendEvents, and so you might wonder what’s going on here. The answer is that xdotool (and other automation programs) use a second mechanism to inject synthetic events, the XTEST extension (protocol).
A love letter to Objective-C
https://thoughtbot.com/blog/a-love-letter-to-objective-c [thoughtbot.com]
2023-07-21 21:18
The nature of software is to always be evolving. COBOL jokes aside, it’s rare to find programming frameworks that reach a level of maturity and support that allow them to just exist without being supplanted by a newer language or a better abstraction. Which naturally is great. Who wants to find themselves writing software with the expectations of today while performing the tasks of manual memory management or manipulating strings that are just raw pointers in a block of memory terminating with a null (\0) character? But sometimes in this constantly evolving space, you find a framework that resonates, and you hold on to it tightly. I wanted to share how this happened for me, first with Ruby (no surprise) but then oddly with Objective-C.
source: L
Regex Isn't Hard
https://timkellogg.me/blog/2023/07/11/regex [timkellogg.me]
2023-07-12 00:01
Regex gets a bad reputation for being very complex. That’s fair, but I also think that if you focus on a certain core subset of regex, it’s not that hard. Most of the complexity comes from various “shortcuts” that are hard to remember. If you ignore those, the language itself is fairly small and portable across programming languages.
It’s worth knowing regex because you can get A LOT done in very little code. If I try to replicate what my regex does using normal procedural code, it’s often very verbose, buggy and significantly slower. It often takes hours or days to do better than a couple minutes of writing regex.
source: L
An interesting mistake with Go's context package that I (sort of) made
https://utcc.utoronto.ca/~cks/space/blog/programming/GoContextValueMistake [utcc.utoronto.ca]
2020-08-30 16:29
How can CharUpper and CharLower guarantee that the uppercase version of a string is the same length as the lowercase version?
https://devblogs.microsoft.com/oldnewthing/20200804-00/?p=104040 [devblogs.microsoft.com]
2020-08-05 00:49
The CharUpper function tries to convert the string in place, but if the uppercase and lowercase versions of a character are not the same length, then it panics and does something strange.
Also: https://devblogs.microsoft.com/oldnewthing/20200803-00/?p=104038
Let's build a Full-Text Search engine
https://artem.krylysov.com/blog/2020/07/28/lets-build-a-full-text-search-engine/ [artem.krylysov.com]
2020-07-30 16:48
Today we are going to build our own FTS engine. By the end of this post, we’ll be able to search across millions of documents in less than a millisecond. We’ll start with simple search queries like “give me all documents that contain the word cat” and we’ll extend the engine to support more sophisticated boolean queries.
source: L
Using Go build directives to optionally use new APIs in the standard library
https://utcc.utoronto.ca/~cks/space/blog/programming/GoBuildUsingNewAPIs [utcc.utoronto.ca]
2020-07-19 06:42
I mentioned recently that new APIs in the Go standard library were relatively easy to optionally support, because such new APIs only appear in new Go releases and you can conditionally build files based on the Go release that’s building your program. But that’s a pretty abstract description, so let’s make it concrete.
Why strace doesn't work in Docker
https://jvns.ca/blog/2020/04/29/why-strace-doesnt-work-in-docker/ [jvns.ca]
2020-05-04 14:43
But I wasn’t interested in fixing it, I wanted to know why it happens. So why does strace not work, and why does --cap-add=SYS_PTRACE fix it?
source: HN
Making Illegal States Unrepresentable
https://buttondown.email/hillelwayne/archive/making-illegal-states-unrepresentable/ [buttondown.email]
2020-04-19 14:43
It’s a concept I find very helpful. But if you look for examples online almost everything either “let’s prevent dividing-by-zero” or “let’s enumerate the cases in a data type”. We can more creative than that! Some examples of “illegal states unrepresentable” that I found useful but have not seen anyone else talk about online:
source: L
Rust Ownership Rules
https://www.geekabyte.io/2020/02/rust-ownership-rules.html [www.geekabyte.io]
2020-03-03 03:26
In this post, I took the opportunity to re-summarise what I consider to be the essence of this ownership rules in Rust.
source: L
Addressing of AF_INET, AF_INET6 and AF_UNIX sockets
https://idea.popcount.org/2019-12-06-addressing/ [idea.popcount.org]
2019-12-02 06:05
A freshly created socket isn’t very useful. We have to tell it to either listen for incoming data, or connect to a remote peer. To achieve anything useful we need to perform a syscall dance, which involves either bind() or connect() or both.
And some notes about the DNS resolver rabbit hole.
source: L
kill tail(1) when sh exits
https://dacav.roundhousecode.com/blog/2019-10/17-kill-tail-1-when-sh-exits.html [dacav.roundhousecode.com]
2019-10-17 17:24
As a solution, the POSIX shell provides a built-in named trap, documented here. In short it allows to define actions to be executed upon signaling, and that includes shell termination. It is similar to atexit(3) in POSIX C.
source: L
Function Currying in Go
https://medium.com/@meeusdylan/function-currying-in-go-a88672d6ebcf [medium.com]
2019-10-11 15:17
Go can be used to program in a functional style, previously I’ve written about how we can use this to implement Continuation Passing Style programming. As such, it is possible to implement currying in Go as well. Before we take a look at how we can implement this in Go, let’s take a practical look at what function currying actually is, and why we want this.
source: HN
Beginner Problems With TCP & The socket Module in Python
https://blubberquark.tumblr.com/post/186695350125/beginner-problems-with-tcp-the-socket-module-in [blubberquark.tumblr.com]
2019-08-12 00:15
Your operating system will deceive you and re-assemble the string you sock.recv(n) differently from the ones you sock.send(data). But here is the deceptive part. It will work sometimes, but not always. These bugs will be difficult to chase. If you have two programs communicating over TCP via the loopback device in your operating system (the virtual network device with IP 127.0.0.1), then the data does not leave your RAM, and packets are never fragmented to fit into the maximum size of an Ethernet frame or 802.11 WLAN transmission. The data arrives immediately because it’s already there, and the other side gets to read via sock.recv(n) exactly the bytestring you sent over sock.send(data). If you connect to localhost via IPv6, the maximum packet size is 64 kB, and all the packets are already there to be reassembled into a bytestream immediately! But when you try to run the same code over the real Internet, with lag and packet loss, or when you are unlucky with the multitasking/scheduling of your OS, you will either get more data than you expected, leftover data from the last sock.send(data), or incomplete data.
Not strictly a python problem, either.
source: Dfly
rustlings
https://github.com/rust-lang/rustlings [github.com]
2019-07-30 02:08
This project contains small exercises to get you used to reading and writing Rust code. This includes reading and responding to compiler messages!
source: L
Execute Program
https://www.executeprogram.com/ [www.executeprogram.com]
2019-07-23 21:08
Execute Program is for people who already know a programming language. We’ll help you to fill in gaps in your existing knowledge.
At least in the beginning, seems introductory. Not sure how advanced it goes.
A program to detect mojibake that results from a UTF-8-encoded file being misinterpreted as code page 1252
https://devblogs.microsoft.com/oldnewthing/20190701-00/?p=102636 [devblogs.microsoft.com]
2019-07-02 16:29
It is not uncommon to see UTF-8-encoded data misinterpreted as code page 1252, due to file content lacking an explicit encoding declaration, such as you might encounter with the Resource Compiler. So let’s write a program to detect that specific kind of mojibake.
Why you should learn just a little Awk: An Awk tutorial by Example
https://gregable.com/2010/09/why-you-should-know-just-little-awk.html [gregable.com]
2019-06-18 23:15
In grad school, I once saw a prof I was working with grab a text file and in seconds manipulate it into little pieces so deftly it blew my mind. I immediately decided it was time for me to learn awk, which he had so clearly mastered.
source: vermaden
Things I Learnt The Hard Way
https://blog.juliobiason.net/thoughts/things-i-learnt-the-hard-way/ [blog.juliobiason.net]
2019-06-12 04:25
This is a cynical, clinical collection of things I learnt in 30 years working with software development. Again, some things are really cynical, others are long observations on different jobs.
source: L