A Swiss Geek previously in Singapore, now in Portugal

Resize Images on the Fly

Clients know the best what sizes an image should be (screen size, dpr, …). Don’t pre-generate useless sizes and let them ask for the dimensions that suits them best.

Cors at the Edge

With the raise of API driven apps, CORS is becoming an unavoidable subject. By adding a CDN, your CORS rules become a burden on caching.

Creating a Serverless GeoIP API

Why build a GeoIP API when you can buy it directly from Maxmind or use their GeoIP Databases? Using the downloadable database works well when used on an instance. When you need it inside Lambda or Glue, it becomes difficult to keep it up-to-date. It becomes easier to use an external HTTP-API. Hosting it yourself reduces the response time by having it nearer to your apps and you can extend your service by combining multiples sources.

Read More…

MySQL: deleting a huge amount of rows

One of our MySQL tables has started to grow out of control with more than 1 billion rows (that’s 109). The table is a typical “Rails Active-Record table” with id as primary key (auto increment), created_at, updated_at and a few columns for the business data. The table has multiple indexes on various columns, some of them having a cardinality in the millions. created_at and status don’t have an index. The majority of results from Google, involved peoples with millions of rows and deleting them in batches of 1000. We had the problem amplified by 103.

Read More…

converting dynamic sites to static hosting

Why? Security and speed are the two main factors that made me migrate dynamic sites to static sites. I used to build some small sites without any framework using PHP to reuse common files (headers, footers, database connections) with some minimalistic administration pages to avoid to do vi over ssh to manage content. Security wasn’t a concern, Internet users where nice and respectful back then (or more probably I was young and naive). A badly done image upload can quickly become a hacker paradise. This little php snippet that sends out thousands of emails or worse runs brute force attacks against some powerful institutions.

Read More…

From Wordpress to Hugo

As mentioned in Going Static, I migrated my Wordpress blogs to a static site build with Hugo. Most articles on the subject convinced me that it would be easy. The truth is, it isn’t that straight forward. Content With help of a Wordpress plugin, exporting your posts and content is easy. The plugin adds the necessary front matter in Yaml format. But you still need to go through all your posts to update manually all image references. Depending on the amount of posts and images you have, this can be a tremendous task.

Read More…

Going Static

I hosted my blog with Wordpress on my own VPS. The amount of attacks and successful hacks on this blogs is enormous. Wordpress just suffers from notoriety and therefore becomes an easy target. Maintaining Wordpress up-to-date and add some tricks to minimize the risks just didn’t become worth the pain anymore. On top of that, maintaining a VPS to run Apache, PHP and MySQL to serve a few never changing posts didn’t make sense anymore.

Read More…

Network Speed Testing

Everyone is aware of tools like speedtest.net to get a sens of the Internet connectivity speed to certain regions. While it works on mostly every device it allows you to test speed to only one server at a time. And is primarily meant to test the speed of your ISP. I wanted to test connectivity to several part of the world in an one click way, usable on multiple devices. The answer didn’t struck me at once, but it all can be done with some Javascript and mainly with the xhr object.

Read More…

Skip use of CDN near hosting region

The server hosting this domain is a VPS hosted in Switzerland by Nimag network SàRL. Access speed from Asia is pretty bad, specially due to network latency on the pipes Singapore-US and US-Europe. In using a CDN to serve assets, we improve global page loading time in lowering the loading times of assets. The VPS has a good European connexion, there is not much need for visitors in Europe to use a CDN. The other reason, is to lower the traffic costs on the CDN level.

Read More…

First steps into Cloudflare

While writing about Cloudfront, I came accross another CDN service called Cloudflare. The free entry price made me suspicious, hosting and transport has a price. Since I had nothing to loose and that this domain was new, I decided to give it a try. So far, didn’t find any dirty trick. What is Cloudflare? CDN is one of the features, but in fact, they do more than just delivery. Content Delivery Network They place themselves in the CDN category. They are not a CDN in the strict sens of the term. You are not able to push files to Cloudflare and let them serve it. They are acting as a proxy in front of your site, same way Varnish would do it. But instead of having only one proxy server, they have them spread over the world, assuring that each user always get the content from the nearest one, and therefore reducing latency and speeding up the page serving.

Read More…