SchemaSwift
Khanlou.com - Soroush Khanlou
by
1y ago
I’ve been doing a lot more server-side programming in the last few years. Being able to write Swift on both sides is a real joy. I have a client with whom I’ve built a reasonably full-featured social app in Vapor, and all my personal stuff has been using Meridian, which has been going great. (I will have some contracting availability for server-side Swift coming up soon, so definitely get in touch if you have a project!) However, one part of the process that I don’t enjoy much is using an ORM. There’s too much magic when working with them. I feel disconnected from the queries that are being ru ..read more
Visit website
Arbitrary Beautiful Colors
Khanlou.com - Soroush Khanlou
by
1y ago
RGB kind of sucks. RGB, not unlike ASCII, memory addresses, and having 86,400 seconds in day, is one of those things that makes programming a little simpler for a bit, until it doesn’t anymore. In theory, RGB is a group of color spaces that lets you tell the display how much voltage each subpixel needs. However, in practice, we now have phones with displays that let you show more than 100% red, which is a new type of red called super red. We have other displays that have twice as much blue as red or green. Your RGB values are not corresponding to display voltages and they probably haven’t for ..read more
Visit website
Which Collection?
Khanlou.com - Soroush Khanlou
by
1y ago
I recently had occasion to give my old Sudoku talk again. For those who haven’t seen the talk, I live-code my way through a Sudoku problem and together we write a solver that can solve any valid grid. It’s a very fun talk to give and I hope it’s enjoyable to watch as well. While preparing for the talk, I took the chance to update and modernize some of the code. I was able to use multi-line strings to represent the grid in a graphical way and get rid of an old helper that is now part of the standard library as allSatisfy(_:). More important than those changes, though, I was able to incorporate ..read more
Visit website
Name Your Colors!
Khanlou.com - Soroush Khanlou
by
2y ago
Here’s a fun experiment: if your app has a designer, ask them how many colors they think are in your app. Then, count the number of colors that you actually use in your app. The bigger the app, the more comical the difference will be. I’ve got a solution for this which is pretty fun to boot. You should name your colors. I find that a lot of people do a good job picking colors, but when it comes time to put those colors into practice, the names that get picked are somewhat boring. UIColor.gray40? .appRed? Where is the joy in that? Instead of really generic names, try to find short, unique, fun ..read more
Visit website
Download Progress With Awaited Network Tasks
Khanlou.com - Soroush Khanlou
by
2y ago
Async/await is here! Five (5!!) years ago, I wrote about what async/await might look like in Swift: async func getCurrentUsersFollowers() throws -> [User] { let user = try await APIClient.getCurrentUser() let followers = try await APIClient.getFollowers(for: user) return followers } I put the async keyword in the wrong place (it actually goes next to the throws), but otherwise, pretty close to the final feature! Today, I want to look at adopting some of the new async/await features. I have an app that’s already on iOS 15, so it’s a great testbed for these goodies. One of the p ..read more
Visit website
The Context And The Logic
Khanlou.com - Soroush Khanlou
by
3y ago
As a professional programmer, there are two main types of tasks you work on. I’ve started thinking about them as the context and the logic. The logic is what you think this job is going to be about when you first start. How do I slice this collection up? How do I find all the paid invoices for this client and sum up their amounts? How does this date get turned into a string to be displayed on the screen? What floor should this elevator go to next? The logic is what they grill you on in interviews. The logic is algorithms. The logic is sometimes specific to your business. The logic is sometimes ..read more
Visit website
Meridian
Khanlou.com - Soroush Khanlou
by
3y ago
“Telling a programmer there’s already a library to do X is like telling a songwriter there’s already a song about love.” - Pete Cordell Sometimes, it feels like questions that arise during my time programming take years to answer. In particular, my journey to a web framework that I vibe with has been a long one. A few years ago, I wrote about trying to squeeze the behavior I want out of Vapor. I (rather poorly) named the concept Commands, and I wrote a blog post about the pattern. Generally speaking, this style of routing, where you use a closure for each route, has been used in frameworks ..read more
Visit website
Moving my life to Dokku
Khanlou.com - Soroush Khanlou
by
3y ago
While it’s a bit passé to not blog for over a year, and then dive right back in by talking about your blog setup, I’m going to do it anyway. I recently moved all of my static sites and Swift services over to Dokku, and I am really enjoying it. Dokku is a collection of shell scripts that act as a self-hosted platform-as-a-service. Basically, it’s your own personal Heroku. Chris and I actually discussed it a few years ago on a (Patreon-only) episode of Fatal Error. I’ve wanted to move my stuff to it for a while, and finally spent some time over the break getting things moved over. First, I want ..read more
Visit website
Regexes vs Combinatorial Parsing
Khanlou.com - Soroush Khanlou
by
4y ago
Recently, I’ve been working on a music app that needs to get a musical sequence (like a melody) from the server to the client. To do this, we use a format called ABC. (You can read about how ABC music notation works here.) We chose ABC because it’s more readable than MIDI, it’s pretty concise, and it’s a standard, so we wouldn’t be re-inventing some format over JSON. ABC is a simple format, and it does a great job of representing music in strings. For example, here’s the little bit from Beethoven’s’ “Für Elise” that everyone knows: e ^d e d e B =d c A2 The letters correspond to specific ..read more
Visit website
Linear Probing
Khanlou.com - Soroush Khanlou
by
5y ago
A few years ago, I wrote Implementing Dictionary In Swift, which was a crash course on how to create something similar to Swift’s Dictionary type. Since our dictionary will be backed with an array, we need a way to convert the key that’s given into an integer, and then a way to force that integer into the bounds of our array. These two methods are the hashing function and the modulus operation, respectively. By hashing, we can consistently turn our key (usually a string, but can be any type that is Hashable) into a number, and by taking the modulus with respect to the length of the array ..read more
Visit website

Follow Khanlou.com - Soroush Khanlou on FeedSpot

Continue with Google
Continue with Apple
OR