Implementing GDPR in my blog

GDPR General Data Protection Regulation (GDPR) is the EU regulation to protect user data and privacy in Europe. A friend from Europe contacted a few days ago and told me that you don’t have cookie notice in your website and asked to do something about it.

My blog is powered by Jekyll which is a static site generator. It doesn’t (actually can’t) gather users’ data by itself. The only way to do so is by utilizing third-party JavaScripts. Except for one section, which is the comment section, I don’t use any third-party scripts. I don’t even have Google Analytics enabled on this blog. So to be able to truly implement the GDPR, I must only load the comment section when the user accepted the terms.

The approach

There were two approaches for implementing GDPR here:

  • Whenever a new user comes in, ask to allow cookies by showing a pop-up or something similar (The most common way).
  • Only show the cookie notice when the user is in a post page and wants to see/write a comment.

I believe the second approach is much better. Most of the times, users just want to read the blog post and leave. They don’t want to leave a comment. Therefore, I don’t even load the comment section at all! Instead, I show the following notice and when the user accepted the terms, I will load comments:

GDPR notice

Implementation

Disqus comment section is loaded into a <div> element using an inline javascript. So to implement this section I must first make sure the user accepted the cookie notice and then load the section. When the user click the approve button, I create a cookie. If the cookie doesn’t exist, I realize that the user has not approved yet. So I wrote two functions; one for getting the cookie value by name (getCookie(cname)), and the second is for setting the cookie value (setCookie(cname, value, exdays)).

function getCookie(cname) {
  var name = cname + '=';
  var decodedCookie = decodeURIComponent(document.cookie);
  var ca = decodedCookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }

  // Return empty string if cookie with specified name not found.
  return '';
}

function setCookie(cname, cvalue, exdays) {
  var d = new Date();
  d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
  var expires = 'expires=' + d.toUTCString();
  document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';
}

The first function getCookie check all website cookies to see if there’s any match with the name cname. If not, it returns an empty string. You may also want to return undefined instead but I chose to just return an empty string. In addition to these function I also have two divs. The one for loading the Diqus comments in and the second for the notice itself:

<div id="disqus_thread"></div>
<div id="cookie_notice" class="alert alert-info">
  The comment section uses cookies and third-party JavaScripts. To enable
  comments please click the approve button. For more information please checkout
  <a
    href="https://help.disqus.com/en/articles/1717103-disqus-privacy-policy"
    target="_blank"
    >Disqus privacy policy</a
  >
  <button id="approve_cookie" class="btn btn-sm btn-primary">Approve</button>
</div>

Then I have to handle the onClick event of the approve_cookie button to set the cookie when it’s clicked:

document.getElementById('approve_cookie').onclick = function () {
  setCookie('cookie-confirm-accepted', '1', 30);
  window.location.reload();
};

Finally I have to load the comment section only if the user accepted the terms; otherwise, the cookie notice div must be shown:

var cookie_container = document.getElementById('cookie_notice');
var disqus_config = function () {
  this.page.url = '[the page URL]';
  this.page.identifier = '[the page Identifier]';
};

(function () {
  cookie_container.style.display = 'block';
  if (getCookie('cookie-confirm-accepted') === '') {
    // Don't load the rest if the user cookie was empty
    return;
  }
  cookie_container.style.display = 'none';
  var d = document,
    s = d.createElement('script');

  s.src = 'https://[disqus username].disqus.com/embed.js';

  s.setAttribute('data-timestamp', +new Date());
  (d.head || d.body).appendChild(s);
})();

Please also note that the cookie we create has an expire date of 30 days (30 * 24 * 60 * 60 * 1000); so the notice will be shown again after that.

Beside GDPR, I also realized that my blog loads much faster since there is once less library to load. The only libraries I’m currently use are Bootstrap and PT Serif font from Google Fonts.

In Misc | 09 Feb 2021

A geeky/minimal way to do journaling

I started journaling on a regular basis around 3 years ago. Even before that, I always did my best to stay organized especially about my notes. As you may know, I’ve been using Evernote for around 8 years but near a year ago, I decided to move from Evernote to Apple Notes because Evernote didn’t support many features like right-to-left (I’m not sure if it now supports RTL or not).

Apple Notes is a great tool for do simple note-takings; however, I have recently faced some buggy behavior such as high CPU usage while writing notes and laggy typing experience. In addition, I experienced some difficulties accessing my notes from non-macOS devices using iCloud website. While searching for alternatives, I realized that none of the note-taking apps out there meet my needs. Notion which is, in my opinion, the most comprehensive note-taking solution out there is to complex for me. All I want to do is rich-text writing with support for photo attachment.

My newest solution

As you may know, I’m a big fan of Markdown. In fact, I do most of my writings including this blog in markdown. It’s a very simple yet powerful markup language that you will fall in love with its simplicity.

A few weeks ago, I found an app called Exporter on the Mac AppStore that let you export notes from Apple Notes app as markdown files! What could be better than this!? I instantly exported all of my notes to markdown and created a private Git repository and pushed all of them there. Git hosting providers such as Github and Gitlab support markdown out of the box. This means your markdown files will be displayed as prettified HTML when you access them via their websites/apps. Also, there are some cool plugins for text-editors like VSCode and [neo]vim that let you preview your markdown files live. Once you’ve done your daily journal, you can commit that markdown file and push it to a git server so you won’t lose it.

You may ask how can I search through my notes? The answer is simple: grep and find. Here is an example:

# Search for 'Nika (My daughter's name)' in notes folder.
grep -iRl "Nika" ~/repos/notes

I believe this is the simplest way to manage your notes while keeping it in a safe place.

33

33 Today was my 33rd birthday. Although it’s getting more and more boring for some people to celebrate birthdays, it’s going to be a special year for me.

Last year I decided to start a new path in my life and moving from the city I’ve born in to another country. Although I’m still here in Tehran, I’ve almost done doing whatever needed to move.

The reason I’m mentioning this is because this move is not only valuable for me but for my wife and my daughter as well. It will open new doors in our lives and as a father and husband, I’ll do whatever needed to provide the best life quality possible for my family. Because as a matter of fact, there is nothing more important than our families.

I hope everything goes fine and the process finishes in a smooth way.

PS: The Spongebob birthday cake idea was Nika’s ;)

How much resources are actually enough?

Yesterday I came across this post on Reddit in which a person shows that he has upgraded his laptop’s RAM to 128GB and its storage to 12TB!

A high-end laptop with 128GB of storage

For the first 10 seconds after I watched this I said: Wow! This is a bold configuration. He probably can do whatever he wants with his laptop now! But after 30 seconds I said: What he can do with his laptop that I can’t with mine? After that, my brain started to use its power to convince me that there are certain areas, which I’m not aware of, that need a decent amount of resources. For example, maybe he’s a 3D animator who needs these resources to render heavy graphics. Or maybe he is a scientist that does a lot of complex computations. Anyway, I hope he has compelling reasons for this upgrade.

As an another example, a couple of weeks ago Samsung announced their new flagship phone Galaxy S21 Ultra. Believe it or not but this phone has 16GB of RAM, 5! cameras (one of them has a 108MP sensor), an octa-core processor (1x2.9 GHz Cortex-X1 & 3x2.80 GHz Cortex-A78 & 4x2.2 GHz Cortex-A55), and up to 512GB of storage! The funny part is that this phone has twice more resources than my current laptop I use for software development. My daily driver laptop has a Core i5 processor with 8GB of RAM and 256GB of storage. I use it almost every day and since I’m a software developer I do lots of resource-intensive tasks such as compilation and computation. I own this for about 4 years now can’t find a reason to upgrade it yet; however, the battery needs to be replaced which is normal.

In my opinion, the question we should ask ourselves before buying these stuff is that do we really need all of these? I personally do care about photos. I took lots of photos from my family and we love watching them every now and then. But my 12MP iPhone camera was always enough. We have even printed some of our best photos as well and the quality is satisfying.

Companies like Apple and Samsung are delighted to see people consume more even if they don’t use what they have purchased. They simply don’t care! All they want is your money! Even further, they want the society to believe that people who have the latest gadgets are more admirable; and unfortunately, they have succeeded!

The tragedy begins when you spend a considerable amount of money on a new device (The Galaxy S21 Ultra I mentioned above is around $1,400), let’s say a new phone, and after less than a week you face this unpleasant truth that it doesn’t make you happy anymore because the difference between your new gadget and the previous one is so slight you can’t even feel!

In November 2000, when Intel announced their first-generation Pentium 4 processors, most people instantly upgraded their PCs. You know why? Because the difference between previous generations and Pentium 4 was huge! Nowadays, your 2015 computer performance is almost as same as a 2020 model. You can feel it more obviously on smartphones these days. An iPhone 7 is capable of doing 80% of whatever you can do with an iPhone 12. Because the companies cannot provide life-changing features, they have started to limit older phones intentionally. Here are some very ridiculous examples:

  • Some wallpapers in iPhone 12 are not available in iPhone 11. Some of iPhone 11 wallpapers are not available in iPhone X.
  • Default ringtone on iPhone X or later is not available on earlier iPhones.
  • Software updates are not available for all phones. Buy a new phone to get the latest version of Android.

And then to sell you even more they trap you in an infinite loop:

  • The new iPhone 12 has new Blue color and you can’t believe how gorgeous is it! However, to protect it you will need to buy a case as well… Oh, you won’t be able to see our gorgeous blue color after the case is used.
  • You can now shoot videos in 8K! Wait… we forgot to mention that you will also need a display/TV to watch these videos on. But don’t worry! We got your back. You can buy one for just $2000!
  • Our previous phone had a 100MP camera sensor, but this year we have done a great job upgrading it to 108. Although the quality of the images is 99% similar to 12MP photos but theoretically 108MP is better.
  • Our new laptop boots up 5 seconds faster than our previous generations; so, you have 5 more seconds getting yourself conformable behind the desk.

Examples I’ve mentioned above seem funny but I’m afraid they are the truth behind what some companies advertise.

What I’m going to emphasize here is that more than 80% (if not 90%) of people upgrade their devices not because they need to be upgraded but because they just want to have the latest ones. Some people even use them to show off! They think the more belongings they have, the more respect they get from society. I believe we should stop value humans by what they have; instead, we must value them by what they have done! I’ve seen plenty of engineers and scientists who are using very typical devices; but, they do extraordinary things with them. On the other hand, I see some other guys who own lots of high-end gadgets but they even don’t know how to use them! Computers that are used to send astronauts to space have specifications similar to the majority of smartphones made 10 years ago.

I’m not against new gadgets. A friend of mine bought an iPhone 12 a week ago after his iPhone 6 screen broke. He bought a new phone because he needed one and it’s totally OK! You don’t need 128GB of RAM on your computer to write a great book. You don’t need an iPad Pro to become a good doctor. You don’t need a high-end smartphone with 108MP camera to solve world’s most demanding problems. You don’t need the latest Apple Watch to win olympic games! All you need is you!

I quitted Instagram and Twitter for about two months and nothing changed

I have been using Instagram and Twitter for nearly a decade. After reading Digital Minimalism by Cal Newport, I decided to practice using social media in a more intentional way so I started monitoring all of my social media activities and values they provide. What I realized was that Instagram, Facebook, and Twitter create almost no values for me at all. It was such a surprise because I put so much effort to take care of them in the past. For example, I tried my best to curate almost all of my tweets, try to post the best photos I could on Instagram; but in fact, I received almost no values from them.

As a result, I removed all social media apps from my phone and practiced using them via my computer’s web browser instead to reduce the amount of time I spend on each service. I also tweeted a few and posted a couple photos on Instagram since that time but again, I received no values in return! Finally I made my choice and signed out from my accounts even from web browsers. I wanted to see if not using these social media services have effects on my life and the results was a big NO! After quitting Twitter and Instagram nothing changed. I still in touch with my friends and family via Whatsapp and if I want to share a photo with them, I just post it to our family groups.

To be able to stay tuned with the latest news I care about, I installed an RSS reader on my computer and subscribed to my favorites websites and blogs and I usually check them once every other day.

It’s important to understand that by using social media, you’re spending your time and companies behind those services are selling your time to other companies like advertisers. They make a lot of money out of your attention and I believe it’s important for everyone to understand what is going on behind the scenes. I highly recommend you to reconsider your social media consumption and decide how you want your time to be spent because all creatures only live once.