Welcome to EnDavid.com. You can find here a compendium of things that I have published and other stuff I made during my spare time.

If you get lost, try visiting the Site Map.

In this main page, you can find my main blog, where I keep track of the updates of this site, and post some technical articles from time to time. If you are interested, just subscribe to the RSS feed.


Advent of Code 2021: Postmortem
Thu, 30 Dec 2021 13:10:49 +0000

I managed to complete Advent of Code this year. It was my first time attempting it, so I wanted to write down my impressions.

About AoC

Advent of Code (AoC) is an advent calendar of programming puzzles developed by Eric Wastl, started in 2015.

Every day from December 1st until December 25th a new puzzle is revealed, at 5AM in UK time. Each puzzle has 2 parts. In order to unlock the 2nd part, you need first to submit the correct answer for the 1st one. There's no time limit to complete the puzzle (you can still do them now), but the first 100 people to complete the puzzle get a score. It's very hard to get in the ranking, though, since it seems the fastest people complete them in under a minute (is that even possible? I need several minutes to read the problem... ๐Ÿ˜…), and there are lots of people attempting it. This year started with more than 200K people taking part. If you are in the UK, you also need to wake up early (I can't ๐Ÿ˜‚).

However, puzzles get slightly harder as days progress. Weekends tend to be even more challenging. So if you don't give up, you may get higher in the rank. I was 44K in the ranking of the first day, but ended up 5K in the 25th. The site provides also some interesting stats so you can see the completion rate of each puzzle.

What for

You can do it to compete, or simply to practice. In my case, it was mostly to practice. I'm usually busy with side projects so I never really thought that I wanted to give myself even more programming work. But this year I haven't done much programming on the side, so I was starting to forget Swift a bit, since it's a language I only use in my side projects. But I had to check something in Swift for work, so I thought that doing this year's AoC in Swift would be a good way to warm up.

I like Swift, and the problems were fun, so I quickly got into it. Although at a later date I started to get tired. On Christmas day, the first part wasn't that difficult, but the 2nd part was simply to collect all the stars from the previous days... ๐Ÿ˜… I had 3 unfinished puzzles (or rather, 5 parts), so I did a bit of a programming marathon to finish them all and I ended up a bit tired ๐Ÿ™ˆ Although once done, it's a great sense of accomplishment. ๐Ÿ‘

How to approach it

As you like, really. But what I've done is creating a single project where I put all the files for all the puzzles. It's a CLI app that I always invoke passing a file named something like day12_input.txt, or day23_example1.txt. From the name of the file I get the day number, and then I execute the corresponding dayXX function, from a big switch-case (I thought of using reflection to invoke the right method, but Swift's Mirror API lets you access only the attributes, not the methods). I distributed these functions in files named WeekN.swift, 7 days per file, just because I don't like huge files. For short exercises, I write the algorithm inside that day's function. But in most cases I create a separate file with the functionality and invoke it from that day's function. See below, after 25 days.

Having it all in a single project has been useful because I could reuse some of the code. I kept refactoring as I went, to make the code more useful. I also started adding test functions. I invoked these test functions from the corresponding daily function, although perhaps I could have created a separate test project. But at this point, it's perhaps overengineering the problem. ๐Ÿ˜…

Debugging code can also be fun, even when unnecessary. I tried doing some visualizations of the problems to help me debug, but also because it's cool. There are people in Twitter generating images and animations for some of the problems. Here are some interesting ones I found: day 15 (search), another day 15, day 14 (polymerization), day 13 (origami) in C64, and day 13 animation.

I wrote some code to export my image-like structures into images and create animations with the steps of the algorithms, and here are some of the results: day 11 (flashing octopus), and day 9 (smoke basin).

Conclusion

Try it. Even if you don't know any programming, it may be interesting to read the problem and try to figure out whether you can solve it mathematically or on paper. Sometimes, it can be fun just thinking on how many permutations of a particular problem there are.

Perhaps plan in advance when you are going to attempt solving the problems. I happened to have some holidays so I could spent some hours every day on AoC. There are better things to do on holidays, perhaps, but you can always take some paper with you and think about the problem while resting at a coffee shop (restrictions allowed).

Thanks to Eric Wastl for all the time spent creating these puzzles. ๐Ÿ˜Š


iOS eats your data. How to control it.
Sun, 07 Nov 2021 00:10:39 +0000
Recently I was on vacation and I was surprised to find out that I was using 100 MB of cellular data per day, when I had disabled everything except for WhatsApp. And WhatsApp usage seemed to be just a few kilobytes. Where was my data going?

A bit of background

I haven't signed to any mobile phone contracts in the UK for 8 years. I've always been on "Pay As You Go", because I have Internet at home and Internet at the office, so why paying for a service I barely need? The phone itself is expensive enough, so I thought perhaps "Pay As You Go" was a better deal for me. And it turns out I've been paying an average of ยฃ30 a year, cheaper than any contract around.

That doesn't mean I didn't use data. What I did was disabling all the apps except WhatsApp, so I could receive messages. You can disable the cellular data usage under Settings โ†’ Cellular on iOS. If I had to use Google Maps or something I would turn on that app just momentarily and search what I needed to. I don't travel that often, so it wasn't lots of data.

However, two things happened in 2021 that made an impact on the amount of data I consume. The first one was the increase of tariffs by Three, my mobile career. They tripled the cost of their standard rate for calls (from 3p to 10p per minute), and they also made texts and data 5 times more expensive (from 1p per MB to 5p per MB, and 10p per text). Perhaps many people during the pandemic had a similar thought to mine 8 years ago: why paying through the nose for a contract when I'm staying at home where I'm already paying for the Internet? And then the reaction from Three has been to increase the standard rates. Who knows. ๐Ÿคทโ€โ™‚๏ธ

The second thing was that I updated to iOS 14, that introduced Widgets. All of a sudden more things seemed to be happening on the background that I wasn't aware of. And that consumes data. When I went on vacation, I bought an add-on of 500MB for ยฃ5 that lasts one month, and to my surprise, I used 100MB of those in the first day. So I panicked a bit. ๐Ÿ˜…

Where's the data being used?

I noticed that most of the data was used on System Services. Fortunately, you can take a look inside System Services and see them by category. The major culprits in my case were: Time and Location (23.7 MB), Messaging Services (14.5 MB), Push Notifications (13.5 MB), Apple ID Services (12.2 MB), and Software Updates (9.6 MB). This is with all cellular data disabled for all the apps except for WhatsApp.

I suspect that all the data gone in Time and Location was used by the Weather App widget. There's no control over the cellular data access of widgets, so you either remove the widget, or disable the location services completely. I did enable Google Maps after that and it seems the data usage while on Google Maps is all accounted for under Google Maps, and not under System Services. For all the apps, I only allow them to use the location services while on the app.

Similarly to location data, there's no control over the push notifications other than disabling them completely for each app. Even if you have the cellular data disabled for FB Messenger, if someone sends you a message you will see the message in the notifications screen... And if they send you a picture, the picture will preview as well. ๐Ÿ˜…

Other things like Software Updates can also be set to manual updates only. But again, there's no much control of what things can be done over cellular data.

Apple's Messages app doesn't seem to have any control either. I assume that the Messaging Services refers to that app. If someone sends you images, they will arrive. This is unlike WhatsApp, where you can set it so images are not automatically downloaded while on cellular ใƒผ and that's the reason why WhatsApp is the only messaging app that I want to enable while on cellular.

After a couple of days constantly checking my data usage, I decided to completely disable the location services, and all the push notifications for all apps except for WhatsApp, and only enable certain apps when needed. I managed to keep the data usage around 500 MB for the 3 weeks I was abroad.

My recommendations to save data

Ideally, I would set up a shortcut to enable a "data-saving" mode while on cellular. But certain actions are not available in the Shortcuts app, like enabling the location services. I think if you simply don't want to use cellular data and you are mostly walking from Wi-Fi to Wi-Fi (e.g. from home to the office and viceversa), the simplest solution is to simply disable the Cellular Data completely, under Settings โ†’ Cellular.

However, if you are going to be without Wi-Fi for a while and want to stay somewhat connected, my recommended settings are:

  • Settings โ†’ Cellular โ†’ Reset Statistics, so you start counting how much data you use. If you are on a data plan and you want to switch to "Pay As You Go", reset the statistics and check your stats for a couple of days. Then, take a screenshot of the stats, reset the statistics again, and try the rest of the settings I explain below. See if you can survive with that.
  • Settings โ†’ Cellular โ†’ disable everything except WhatsApp, the Phone app, and any app that you may need when you are out (e.g. Uber or your train tickets).
  • WhatsApp โ†’ Settings โ†’ Storage and Data โ†’ Media auto-download โ†’ set Photos, Audio, Video and Documents only to auto-download while on Wi-Fi.
  • Settings โ†’ Privacy โ†’ Location Services โ†’ Off. This is the only definite way I could find to avoid data being used by location services in the background. As I said, I suspect it's being used by widgets, but the only granularity available at the moment is for apps.
  • Settings โ†’ Notifications โ†’ disable all the notifications for all apps you don't need. I only left WhatsApp. People can either reach me through WhatsApp, or call me directly.
  • Settings โ†’ General โ†’ Software Update โ†’ Automatic Updates โ†’ Off.
  • Settings โ†’ App Store โ†’ Cellular Data โ†’ Automatic Downloads โ†’ Off, and App Downloads โ†’ Always Ask.
  • Settings โ†’ General โ†’ Background App Refresh โ†’ Wi-Fi.
  • Settings โ†’ Battery โ†’ Low Power Mode โ†’ On. I'm not sure how helpful this is, but it should reduce any background activity like downloads. The problem is that it automatically turns itself off when you plug your phone to charge it.
By disabling all those notifications, you have the added advantage that you may feel less stress when you are out and about. Just learn to disconnect! ๐Ÿ˜ƒ

My wishlist

Having to look at the data usage may be more stressful to some than thinking of the waste of money of their monthly contracts. There is a lot of room for improvement, although totally out of my control. Here are some of the things I would like to have:

  • An option to disable any background usage of time & location services completely for background tasks and widgets while on cellular data (but still being able to use them in the allowed apps when on foreground).
  • Being able to disable notification while on cellular, or to limit the amount of data of those notifications, to avoid receiving heavy attachments.
  • Access to all the relevant options in the Shortcuts app, so I can create my own "cellular data saving mode". Or better, a "cellular data saving mode" by Apple that does everything that I need.
  • Cheaper tariffs for "Pay As You Go", or a monthly 500 MB data plan for ยฃ2.5 a month.

How much do you pay monthly for your data & calls? Do you think it's worth it?


FOHWT: Fear Of Having Wasted Time
Wed, 13 Oct 2021 00:23:00 +0100

Anxiety and Fear Of Missing Out

One of the negative impacts of social media is the anxiety some users may experience when using social networks, or as a consequence of them. One buzz word we hear these days is FOMO, or the Fear Of Missing Out. FOMO is โ€œanxiety stemming from the belief that others might be having fun while one is not presentโ€, and it's associated with fear of regret.

Certainly, when I see lots of Instagram posts of people traveling around the globe I also feel like I should be traveling as well, in order to โ€œenjoy lifeโ€. But I do enjoy other things in life, so I can't really say that makes me anxious. So I think I'm safe from FOMO. However, there's another type of related anxiety I could be suffering.

Fear Of Having Wasted Time

This is a word I made up that best describes the type of anxiety I have at times. I would define the Fear of Having Wasted Time (FOHWT) as the anxiety one suffers after having done some leisure activity and feeling that the activity should always culminate with some shareable asset.

For instance, if I play a videogame, specially a long one, I feel I have to record a video summarizing it or giving comments about it. I don't care if the video has any impact, but I feel better with myself if all those hours I invested in that game end up with me creating something based on that experience. After a couple of years, I enjoy re-watching my video and remembering the game.

The more hours you invest in the game, or the more joy you had with it, the stronger the FOHWT. If it's a short game or a game I didn't really enjoy, I don't really feel compelled to record anything. Unless the game is so bad that I think the video is going to be funny. ๐Ÿ˜…

I think this anxiety could be related to some kind of obsessive behavior. With videogames, I had a similar feeling with trophies and achievements: I felt I had to collect them all after clearing the game, not because I enjoyed doing so, but because it was visible proof that I completed it. However, I managed to get rid of that obsession by recognizing it as an obsession, not something that was really fun.

But gradually I've been replacing that obsession by another: content creation. It's certainly more fulfilling than trophies, but it may prevent us from really enjoying our leisure time. For instance, I don't feel like starting a new game until I create a video or write a blog post about the last one I cleared, and because that may take time and I'm too tired after work, I end up not doing anything.

I mentioned videogames, but it can be anything. For instance, if I read a non-fiction book, I like highlighting things and taking notes. Perhaps I create some pretty illustrated notes with the things I found more interesting, e.g. these notes from Michio Kaku's โ€œThe future of humanityโ€: Instagram endavidg #TheFutureOfHumanity. Right now I'm stuck in another book from Michio Kaku because before I continue to the next chapter I would like to summarize and illustrate the one I just read... ๐Ÿ˜…

Fear of wasting time

Note that FOHWT is not the same as the โ€œfear of wasting timeโ€ (FOWT). The tense of the verb is important in this case. I think the fear of wasting time would be some type of anxiety suffered before doing some leisure activity, not after. I'm OK with playing a videogame or reading a book, but I may not start it in the first place because I may feel I may not have time later on to write about it. ๐Ÿ˜…

Although if think again, I may be experiencing FOWT in some situations as well. For instance, when I read books I usually read non-fiction because I think they may be useful for something. But a novel... will I be learning anything from it? ๐Ÿ˜… I recently read a novel, โ€œFinal Fantasy XV: The Dawn of The Futureโ€, because I liked the game, but also because: 1) I read it in Japanese, so I was practicing Japanese and learning new words; 2) I thought I could make a video or write a blog post about it later on (I had already recorded a couple of videos about the game). ๐Ÿ˜…

Even this blog post has been born out of FOWT. I could be watching TV or chilling out before going to bed, but instead I thought I had to write all this down before I forgot about it (the concepts of FOHWT and FOWT came to my mind a couple of nights ago). By sharing it, it may reach someone and be useful to somebody. But even if it doesn't, it can be useful to myself in the future when I review my past writings. So this is also a kind of FOHWT, because I can't leave the random thoughts I have when my mind is idle go to waste. ๐Ÿ˜‚

If you can relate to this, please let me know! ๐Ÿ˜ƒ


Image maps of an arbitrary area
Sat, 14 Aug 2021 13:23:56 +0100

Introduction

Web developers may be familiar with the map and area tags to define clickable areas in an image. The area tag lets you define rectangular, circular, or polygonal areas. But wouldn't it be easy if we just painted the areas in a separate image that defines the clickable sections? That's what I made this tool for: Dumper (github).

It was common in the old 8-bits and 16-bits days to use indexed images this way to define areas. However, indexed images aren't a thing anymore, and the common thing in browsers is that when the image gets loaded, it gets automatically converted to an RGB image. That means it's not easy to get the index values with standard Javascript. So this Dumper web app I made simply lets you define a color palette, and looks for the actual RGB values in your images to give you the index back from the color palette. You can dump the values as hexadecimal numbers. The numbers are displayed with their actual color in the palette. The idea is that you copy and paste those values in your source code to embed image selections.

You can try the Dumper web app here: Dumper (web).

I made this tool last year because I wanted to make a map-based selection screen for my latest game, Sopilabitas (Word Wall ES), a Spanish word puzzle game. Here are a couple of those selection screens, as the user taps at different sections on the map:

Image maps in Swift

The way I use these maps in the game, which it's programmed in Swift, is through these data types:

typealias UVCoord = (Float, Float)

struct ImageSegment {
    let name: String
    let centroid: UVCoord
}

struct ImageSegmentation {
    static let empty = ImageSegmentation(width: 1, height: 1, segments: [], data: [0])
    let width: Int
    let height: Int
    let segments: [ImageSegment]
    let data: [Int]
    func get(uv: UVCoord) -> Int {
        let x = Clamp(Int(uv.0 * Float(width)), low: 0, high: width - 1)
        let y = Clamp(Int((1 - uv.1) * Float(height)), low: 0, high: height - 1)
        let i = y * width + x
        return data[i]
    }
}  
So the data for each map looks like this:

let southAmerica = ImageSegmentation(
    width: 24,
    height: 52,
    segments: [
        ImageSegment(name: "Chile", centroid: (0.25, 0.307692)),
        ImageSegment(name: "Argentina", centroid: (0.375, 0.288462)),
        // ...
    ],
    data: [0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 
      //...
    ]
)
The get(uv) function in ImageSegmentation is used to convert the tapped coordinates to an index value from the map, and that way we know which country was tapped. It's that simple.

Indices can also be used in other places, such as defining collision areas in games. It's a very simple way to do collisions, but it works for 2D games. Perhaps you can find other usages.

I hope this is helpful to anyone making these kind of region-based interactive screens, or any other game or app.


2020 Retrospective
Sat, 06 Feb 2021 21:49:11 +0000

More than 1 month late, but happy new year 2021!!!

I have been busy in my free time trying to finish my latest game: The Therapy RPG, a game I made as a birthday present to my sister. So I had this hard deadline, her birthday, and I've been "crunching" during January. But now I have some time to look back at 2020, the pandemic year...

Achievements

Work

The beta of our main product, EcoShot, ended successfully and I've been creating updates for it and our avatars. I also created a YouTube channel for it and created a few videos (with iMovie ๐Ÿค ): Introduction to EcoShot

During the summer, we managed to put together a remote internship program and I'm quite happy with what we achieved. It's a pity that we didn't get to meet the interns in person, but it was a great experience.

We also joined an EU Horizon 2020 research project, eTryOn, and I've been doing some interesting things for it as well.

Because of the pandemic, I've been working remotely since the 2nd of March, but I feel quite fortunate that we can do so and that we still have so much work to do! I've been quite busy...

Technical blog articles

I've started syndicating my technical articles to Medium, so I can collect both the articles I publish here and at work. My Medium page: medium.com@endavid.

I think I managed to publish a few interesting articles:

Indie development

I spent 9 months creating another Spanish puzzle game, Sopilabitas (Word Wall ES). I created the concept a few years ago, but I just came back to it in January 2020, and started revising it.

The main target user is again my mum, because she seemed to enjoy the first game I created for her: Silabitas. After I saw that my mum spent a lot of time with word search games, I thought of combining Silabitas and word games. But I also thought I needed a time limit, because I found that Silabitas could be boring when the stages took too long to clear. So I came up with the "sunset" timer: when the sun sets (5 minutes), game over.

As always, I have only sold a bunch of copies, but my family & friends loved it, and my mum managed to reach the last stage, which it's quite impressive!

I also created a Daily Challenge mode in an update, which I think works quite well. The challenges are generated randomly using the date as the random seed. And I created one of those new iOS14 widgets for it.

Another technical achievement was to release it for macOS as well, although I cheated a bit because I used Mac Catalyst (the thing to compile iOS apps on Mac). Before doing so, I also released my drawing app Swift Pixels for macOS, so I could test Mac Catalyst and the release process for macOS before I did for this new game.

The release this time was a bit painful. I got rejected and it turned out it was all a misunderstanding from Apple. It took me 3 weeks of back and forth with them. I wrote a blog post to summarize it: The infamous Apple Guideline 5.2.3 on audio/video streaming.

After the release of the game I took a small break from game dev, but I resumed on November, when I started creating The Therapy RPG for my sister. I planned it so I could finish in 3 months, although it took me slightly more to get it released (my sister had to play the beta in Testflight for her birthday...).

Apart from games, I've done a bit of redesign of this site and I like how it's looking now. I wrote a bit of a design article about it, although it's not my field: EnDavid style update.

Power up

Between work and my spare time indie development, I keep using these 4 programming languages: Python, Swift, C++, and Javascript. This year I also started doing some programming in Go, for work. I've created a couple of command-line tools in Go to do some basic image processing.

I think I keep losing Japanese language skills, but I kept reading some chapters of Uramiya Honpo comic book, and I've watched a couple of anime series, including Demon's Slayer (้ฌผๆป…ใฎๅˆƒ).

Power down

Time is limited, so you can't focus on everything... I didn't practice any piano during 2020, but I'm thinking of restarting this year. I'll have to reduce the time I spend on indie game development.

Fun

2020 has been mainly not fun... In early March I started coughing so I self-isolated. It turned out to be allergy-related, most probably, but since I couldn't visit the GP it was a hard time of not knowing was going on... I basically stayed home until mid-May, with horrible pain in all my ribs from almost 2 months of cough attacks. Finally, the GP gave me an inhaler (preventer) that seems to have helped. When I stop using it, the cough seems to come back, so I'm now using it again. Hopefully this year I can get some allergy tests done...

Anyway, I had planned to visit Japan in late March, but because of the covid-19 pandemic I had to cancel all my travel plans. I did manage to travel to Spain to see my family and to disconnect for a bit on September. It wasn't easy to travel, and there's the quarantine and all that, so I decided to go for one month. Since we are working remotely, it doesn't really matter where I am. Although I took some days off, I was mostly working, but in a different environment, which felt good. I was able to wake up a bit early every day and go to swim to the beach before work.

I found some time to play games as well this year. I cleared Death Stranding on January, and I picked up Uncharted 4 in October (after releasing Sopilabitas). After that, I started Final Fantasy XV, but I stopped playing when I got busy with The Therapy RPG. I also bought Speluny 2 on Playstation 4, and I play from time to time, but that game is too hard...

What's my soundtrack for 2020? Probably something from Attack On Titan soundtrack. I also listened to a lot of lo-fi channels on Youtube, and still listening to Final Fantasy XV soundtrack quite often... In 2019 I made a couple of playlists in Youtube that I still listen to as well: Focotaku Heisei Best J-Pop, and Focotaku Heisei Best J-Pop Side-B. I had to update some of the links because a couple of videos had been removed.

And that's all!

Happy new year everyone! Let's hope we can break free from the virus in 2021 โค๏ธ


โช Previous year | Next year โฉ