Numbers

  • From Top 10 Facts - The ocean
    • There are 3 million shipwrecks in the bottom of the ocean
    • Challenger point visited by David Cameron is 11000 meter deep while Mt Everest is around ~8800 meters tall.
    • 95% of the oceon floor is unmapped.
    • 72% of the Earth surface is water

Quotes

  • Hofstadter’s Law: It always takes longer than you expect, even when you take into account Hofstadter’s Law.[2] https://en.wikipedia.org/wiki/Hofstadter%27s_law
  • The first 90 percent of the code accounts for the first 90 percent of the development time. The remaining 10 percent of the code accounts for the other 90 percent of the development time. Tom Cargill, Bell Labs https://en.wikipedia.org/wiki/Ninety-ninety_rule

Code snippets

  • I have a nasty bug in my linux setup. Here is the thing:
    • I run python3 scripts from bash files.
    • Whenever I run from my own terminal, it’s all good.
    • However, whenever I run them through crontab as bash script (indirectly python script) as cron job, it returns this and halts the whole script UnicodeEncodeError: 'ascii' codec can't encode characters in position 26-27: ordinal not in range(128)
    • This is very interesting because I already use my virtualenv python3 to run the script and it’s supposed to be utf-8 anyways. And I mostly deal with Turkish text so I must use utf8 otherwise strings are not ASCII by default. On top of that I always prepend # -- coding: utf-8 -- at the top of my python scripts to make sure that utf8 encoding is used.
    • None solved the problem, it works fine in the terminal when I run myself, It fails whenever I run through crontab.
    • Here is the solution: Just define an environment variable before running the python script export PYTHONIOENCODING=utf-8. I added them at the top of all my bash files running python3 scripts. And the problem is solved.
  • I have a really large (24GB) sqlite file and from that I wanted to create a subset of data as new sqlite db to have query performance. I was doing with a python script but it was slow. So I found this effective yet super fast way.
      ATTACH DATABASE 'other.db' AS other;
      CREATE TABLE other.foo AS SELECT * FROM main.foo; -- create and populate a table
      INSERT INTO other.bar SELECT * FROM main.foo; -- insert into an existing table
      DETACH other;
    
  • Assing human readable domain like addresses to local IPs:
    • Open hosts file: notepad c:\windows\system32\drivers\etc\hosts
    • Add IP and domain pairs like 192.168.0.33 self.pi
    • In your browser go to http://self.pi:1234 boom, your server in raspberry pi listening to 1234 port will be hit.
  • I have been using WSL 1 for quite some time and it’s time to upgrade to make it play nice with new VSCode WSL extensions.
    • I have been getting this weird error while following the official guidelines: https://docs.microsoft.com/en-us/windows/wsl/install-win10
    • wsl --set-default-version 2 For information on key differences with WSL 2 please visit https://aka.ms/wsl2
      • And nothing happens.
    • Make sure you have WSL 2 is ready to be activated: wsl -v -l ``` wsl -l -v NAME STATE VERSION
      • Ubuntu Running 1 ```
    • In this case, apparently the correct command is this:
        wsl --set-version ubuntu 2
        Conversion in progress, this may take a few minutes...
        For information on key differences with WSL 2 please visit https://aka.ms/wsl2
        Conversion complete.
      
    • It worked like a charm at the end. Now my full setup is there and I have WSL 2. I don’t need to create brand new image.
  • Open syncthing to LAN syncthing -gui-address=0.0.0.0:8384
    • Otherwise GUI is only reachable from the machine syncthing is running on.
    • Other flags: syncthing [-audit] [-auditfile=<file|-|-->] [-browser-only] [device-id] [-generate=<dir>] [-gui-address=<address>] [-gui-apikey=<key>] [-home=<dir> | -config=<dir> -data=<dir>] [-logfile=<filename>] [-logflags=<flags>] [-no-browser] [-no-console] [-no-restart] [-paths] [-paused] [-reset-database] [-reset-deltas] [-unpaused] [-upgrade] [-upgrade-check] [-upgrade-to=<url>] [-verbose] [-version]
  • To get what model of your raspberry pi is from the command line, you can use lshw:
    • sudo apt-get install lshw and then simply type lshw
    • This also prints tons of information about the OS too.
    • There are these but they are not interesting for me cat /etc/debian_version & cat /etc/os-release. Because they are OS related.
  • Raspberry pi loadtest code snippet (stress-ng), easily benchmark your raspberry pi and make sense out of the results:
    sudo apt-get install stress-ng
    nice -19 stress-ng -c 4 --metrics --timeout 60s
    
    • Bogo: “bogus operations per second”
Device # CPUs hogged stressor bogo ops real time(secs) usr time(secs) sys time(secs) bogus ops/s(real time) bogus ops/s(usr+sys time)
Raspberry Pi Model B Rev 2 4 cpu 684 66.88 56.22 9.73 10.23 10.37
Raspberry Pi 4 Model B Rev 1.4 4 cpu 9245 60.20 240.68 0.04 153.58 38.41
Intel i9 9900K 4 cpu 92413 60.01 240.03 0.00 1539.88 385.01
Raspberry Pi Model B Rev 2 1 cpu 614 60.15 51.10 8.02 10.21 10.39
Raspberry Pi 4 Model B Rev 1.4 1 cpu 2923 60.13 60.10 0.01 48.61 48.63
Intel i9 9900K 1 cpu 25757 60.01 59.99 0.00 429.24 429.35
  • I’ve been trying to get rid of zsh for some time. But it’s so stubborn. Some commands to make your life easier.
    • See your default shell: echo $SHELL
    • Change default shell for login user: chsh -s /bin/bash
    • Uninstall zsh sudo apt-get autoremove zsh

Hosting your own cloud aka Nextcloud

Wrestled this week a lot to self host a nextcloud 20 instance in a free GCP instance.

Well I first tried to do everything properly aka dockerized containerized with SSL and stuff. But failed miserably after 7 trials with clean VPS on GCP: I ended up installing everything myself, I followed the steps in nextcloud website but failed with the permission issues though I was so close. Nextcloud instance was read only and not being able to write anything to vps. So I switched to follow some instructions from some random blogs, after 3-4 trials, I found this one worked best: Best tutorial ever: https://www.howtoforge.com/tutorial/how-to-install-nextcloud-on-debian-10/

Even I have Let’s Encrypt SSL.

If you see random Server stopped working errors. It’s highly likely that your mariadb server is down. Moreover you can not bring it back with simple sudo systemctl restart mariadb instead you need to kill hanging mariadb for good and then restart.

# Grab the PID from this command
ps aux | grep mariadb

# Insert your PID instead of 1234
sudo kill -9 1234 

# Now restart
sudo systemctl restart mariadb

# Voila, go to your nextcloud instance url and it will start syncing back.

The reason this is happening for me is that I was trying to sync large amount of files and causing some conflicts. So I quickly deleted them when the server is up and this is gone for good. Sync was seamless again.