Skip to main content

Posts

Swift, architecture, asynchronousness

Asynchronous calls are one of the elements that have a strong influence on the structure of the whole application. However, they are often treated as a necessary evil or even avoided, if possible. At the same time, iOS itself and the swift language syntax provide tools to make asynchronous calls easier to use.

Swift, like JavaScript asynchronous calls are based on callbacks. This means that when calling an asynchronous function, one of the arguments is another function (or code block) to be called when the asynchronous work is finished. Although the action is different from a synchronous call, the code is nevertheless similar. For example:


func syncFunction() -> String { //some work here return "result" } //call sync let x = syncFunction() print(x) func asyncFunction(callback: @escaping (String) -> Void) { DispatchQueue.global().async { //some work callback("result") } } //async call asyncFunction() { res in …

Repairing Foscam camera

Since one incident, I've bought cameras to observe the area around my house. One of them (the first one I bought) is produced by Foscam, model FI9900P V1. Unfortunately, my camera broke on the last day of warranty. I packed it quickly and sent it to get the warranty repair. The repair lasted over a month, but the camera didn't work anyway, was as broken as before sending it.  I decided to face the repair myself. With no experience in repairing similar things, it is really hard to find the point where to start.

In my case, I've been plugging the camera and watching the wireshark network traffic to see if the camera is trying to retrieve an address from dhcp (there was not a single packet), if it will configure itself on APIPA addresses in the absence of dhcp, or if I can finally connect to it on the default ip. Nothing.

The next step was to update the firmware. I contacted foscam company, described my problem and asked for help. I got a file with the firmware and instructi…

Wear out or Rust out ?

“We must all either wear out or Rust out, every one of us. My choice is to wear out.” — Theodore Roosevelt.
I've wanted to do this for a long time. I have watched online courses, read books, but somehow I couldn't get down to anything concrete. I had no idea, and writing another hello world is not as fun as it used to be. Fortunately, there was a problem to solve. I have a large collection of photos. It comes up to 1TB and still contains a lot of duplicates. I remove them "on the fly", which means in practice that if you remind me, I look for them and remove them until I get bored, which is quite fast. I even have an automated script in python that catalogues them and also (at least in theory) removes duplicates. But I dreamed of something else. I would like to have a program that will read all the files, count their cryptographic hashes, save them in the database, and every time a new file is added there, it will immediately check if it was not already there. My net…

C# F# - different tones of .NET

I like good programming languages and C# is definetely one of them. It is my main tool at work. But it is not the only language in the world. When I've got a chance to make one of our next services in F# i was more than just happy about it. Some parts (.csprojects) were already done and needed to be replaced by their F# implementation. I thought F# is just another language with "strange" syntax which does the same stuff the same way. Boy, was I wrong. I had trouble to write interface method, then to implement it. Then to properly use other method. This is so much different. For example, in C# you declare everything about method in first line:
string method( string param1, int param2) while in F# it will look more like this:
let method param1 param2 : string See there is no parameter type? You don't have to add that. You can of course:
let method param1:string param2:string : string But the thing is you don't have to. F# is static language just like…

Xamarin Forms Binary Size

Apps on iOS are nice, Xcode is fine development environment and working in it is fun.
I have and app on iOS which I would like to port also to Android.
I thought about rewriting it in Xamarin.Forms. It turned out Xamarin apps (now as a part of Visual Studio) are also nice to write. I choose Xamarin.Forms to minimize code needed per platform.
App is available on github: https://github.com/jaropawlak/MyExpenses.Xamarin and has almost all functionality my original app had.
There is, however, one issue. BIG issue. It's the binary size.
While my original iOS app takes less than 2MB on device, Xamarin version is around 100MB. That is not acceptable for so simple app. I don't mind apps being big for a reason.
I would also accept that if it wouldn't make the app slow. But it makes it slow.
Have a look:

Cool ha? Native is so fast! So, what are the sizes exactly?



Native app is 1.1 MB







  Xamarin.Forms app is 101.2 MB




The question is: can I shrink the app to some reasonable size? …

Let's GO

C# is a great language. Each new version takes the best solutions from other languages and keeps it very modern. However writing C# all the time both at work and at home feels boring sometimes. I like learning new languages as this provides good exercise. I've decided to write a simple go program. And because I didn't have a better idea I took an app that I had already written in .NET Core and created it again in Go. The app should download history of average daily cryptocurrency value from exchange Binance. I want it to get all crypto pairs from beginning of time until now. I’ve started with simplest thing ever:
package main const hostUrl = "https://binance.com" const apiResourceUri = "/api/v1/klines" const apiGetSymbolUri = "/api/v1/exchangeInfo" const downloadLocation = "data" // here I’ll save data So far so good Opening url http://binance.com/api/v1/exchangeInfo will get us among other things list of all symbols that…

Coredata With Cloudkit

With iOS 13 we'll get new cool feature - coredata db with cloudkit backup. Exactly what I need. 
Bad news is that my old device will not get the update.

My doctor said that I should track food I eat. What I should do is divide my day into 2-3 hour windows and eat a small meal in every one of them. And write it down and then show it to the doctor so we can talk about what I should and what I should not eat. 
I did the tracking for few weeks in excel sheet but an app would be so much convenient!

I thought about simple logger in iOS and a website to generate reports. This is the place where merged cloudkit and coredata would help a lot. It turns out manually adding cloud backup is really easy. Here is the quick doc of the changes required:

// before... usual stuff class Repository { func createLogItem() -> LogItem { return LogItem( context: context!) } func deleteItem(_ item: LogItem) { context?.delete(item) } func saveChanges() { sav…