Tymon Tobolski (@iteamon) header
Tymon Tobolski (@iteamon) profile picture

Productivity Made Easy with Slack ⏳ Queue, 🔔 Todo, 💸 Expenses, 📝 Memo → https://teapaw.org/t.co/7sfj5jEyI9

🇵🇱 Poland
Joined February 2010
I wanted to see current Claude usage limits in macOS menubar, so I've asked Claude to do it. All you need is SwiftBar and this script gist.github.com/teamon/e862a…
2
127
There is this perfect connection between business and climbing: more vertical = faster progress When it gets horizontal it's easy to fall.
3
359
What’s left is to replace the standard JSON middleware with the custom one.
1
1
231
We can’t change the already implemented protocol for Decimal - we need a little trick. We can create a custom JSON middleware that will wrap every Decimal in into a new struct. When Jason sees that struct it will run our encode implementation that returns skips the quotes
1
115
Jason library already defines encoder for Decimal struct, but it’s not exactly what we need. The decimal will be encoded as string “1.01” instead of just 1.01. This is a very good default, but unfortunately we need to encode it as float.
2
1
212
Now we get price as a Decimal and we can perform safe math on it. What about sending a decimal encoded as float?
1
1
141
Fortunately, solving this is pretty straightforward. All we need to do is to instruct Tesla’s JSON middleware underlying library Jason to use correct options. (NOTE: You need to have `decimal` package added as a dependency to your project.)
1
4
156
Let’s the the price of 1.01 as an example. When using the default JSON middleware it will be parsed as float. It might look good at first sight, but just multiplying it by 3 uncovers the problem.
1
1
219
When dealing with money one should always stick to precise arithmetic and use integers or decimals, never floats. But what if some API decides to return and accept JSON with values technically encoded as floats? #MyElixirStatus
1
2
1
15
1,505
The implementation fits in a tweet. Fully working example: github.com/teamon/tweets/blo…
1
5
263
The interface is pretty straightforward. If the "mode" argument is :real all database operations inside the function will be processed as usual. But if it's :dryrun all changes will be rolled back and database will be left untouched.
1
1
147