summaryrefslogtreecommitdiffstats
path: root/content/blog
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2020-06-05 14:19:19 +0200
committerHarald Eilertsen <haraldei@anduin.net>2020-06-05 14:19:19 +0200
commit3a5504d031bbb2cc1eb80ca2929f2342cdeb727c (patch)
treec8b971cd00a5b9c81d6d2105048366aa7c88ccf4 /content/blog
parent1fa58a612e0d66b69cc0196831d0d375793aaac9 (diff)
downloadrabalderz-3a5504d031bbb2cc1eb80ca2929f2342cdeb727c.tar.gz
rabalderz-3a5504d031bbb2cc1eb80ca2929f2342cdeb727c.tar.bz2
rabalderz-3a5504d031bbb2cc1eb80ca2929f2342cdeb727c.zip
import more old posts.
Diffstat (limited to 'content/blog')
-rw-r--r--content/blog/2015-02-27-a-quick-script-to-import-data-from-my-bank-to-gnucash/index.md41
-rw-r--r--content/blog/2015-03-13-first-bike-trip-of-the-year/biketrip.jpgbin0 -> 147334 bytes
-rw-r--r--content/blog/2015-03-13-first-bike-trip-of-the-year/index.md26
-rw-r--r--content/blog/2015-03-13-first-bike-trip-of-the-year/svene-lake.jpgbin0 -> 49343 bytes
-rw-r--r--content/blog/2015-03-19-how-big-is-hello-world/index.md206
-rw-r--r--content/blog/2015-06-02-interessant-om-taterne/index.md20
-rw-r--r--content/blog/2015-06-09-the-stench-of-corruption/index.md24
-rw-r--r--content/blog/2015-06-26-kildevernet-i-norge-er-dødt/index.md22
8 files changed, 339 insertions, 0 deletions
diff --git a/content/blog/2015-02-27-a-quick-script-to-import-data-from-my-bank-to-gnucash/index.md b/content/blog/2015-02-27-a-quick-script-to-import-data-from-my-bank-to-gnucash/index.md
new file mode 100644
index 0000000..10ddd40
--- /dev/null
+++ b/content/blog/2015-02-27-a-quick-script-to-import-data-from-my-bank-to-gnucash/index.md
@@ -0,0 +1,41 @@
++++
+title = "A quick script to import data from my bank to GnuCash"
+lang = "en"
+
+[taxonomies]
+tags = ["software", "programming", "scripts"]
+
+[extra]
+author = "harald"
++++
+
+Here's a quick awk script I did to convert the bank statements from my bank to a
+format recognizable by [GnuCash]:
+
+```awk
+# A simple filter to mould the csv from nordea into
+# something that can be swallowed by gnucash.
+
+BEGIN {
+ FS = ";";
+ RS = "\n";
+ OFS = ";";
+ ORS = "\n";
+
+ # Regex for matching a date
+ DATE = /^[0-9]{4}\.[0-9]{2}\.[0-9]{2}$/;
+}
+
+# Only lines starting with a date should be printed
+$2 ~ DATE {
+ # Strip negative sign from withdraw column
+ withdraw = gensub(/\-/, "", "g", $8);
+ print $2,$4,$6,withdraw,$10;
+}
+```
+
+It could probably be shorter. I could drop setting the RS/ORS, but I like to be explicit. In addition to fixing the polarity of the withdrawals column it strips away all the lines that don't contain any transactions. I don't need them, and this saves me from having to do it manually in GnuCash.
+
+Not anything revolutionary, but thought I'd share it anyways.
+
+[GnuCash]: http://www.gnucash.org/
diff --git a/content/blog/2015-03-13-first-bike-trip-of-the-year/biketrip.jpg b/content/blog/2015-03-13-first-bike-trip-of-the-year/biketrip.jpg
new file mode 100644
index 0000000..8a31cbc
--- /dev/null
+++ b/content/blog/2015-03-13-first-bike-trip-of-the-year/biketrip.jpg
Binary files differ
diff --git a/content/blog/2015-03-13-first-bike-trip-of-the-year/index.md b/content/blog/2015-03-13-first-bike-trip-of-the-year/index.md
new file mode 100644
index 0000000..d52342a
--- /dev/null
+++ b/content/blog/2015-03-13-first-bike-trip-of-the-year/index.md
@@ -0,0 +1,26 @@
++++
+title = "First bike trip of the year!"
+lang = "en"
+
+[taxonomies]
+tags = ["biking", "outdoors"]
+
+[extra]
+author = "harald"
++++
+
+Nothing beats taking the bike out for a quick ride in the spring when it's finally warm enough! Looking forwards to more trips exploring the surrounding area from my new home.
+
+<!-- more -->
+
+The trusty old bike:
+
+{% figure(img="biketrip.jpg") %}
+The trusty old bike
+{% end %}
+
+A nearby lake:
+
+{% figure(img="svene-lake.jpg") %}
+A nearby lake
+{% end %}
diff --git a/content/blog/2015-03-13-first-bike-trip-of-the-year/svene-lake.jpg b/content/blog/2015-03-13-first-bike-trip-of-the-year/svene-lake.jpg
new file mode 100644
index 0000000..da1b7de
--- /dev/null
+++ b/content/blog/2015-03-13-first-bike-trip-of-the-year/svene-lake.jpg
Binary files differ
diff --git a/content/blog/2015-03-19-how-big-is-hello-world/index.md b/content/blog/2015-03-19-how-big-is-hello-world/index.md
new file mode 100644
index 0000000..498f6cf
--- /dev/null
+++ b/content/blog/2015-03-19-how-big-is-hello-world/index.md
@@ -0,0 +1,206 @@
++++
+title = 'How big is "Hello, world?"'
+lang = "en"
+
+[taxonomies]
+tags = ["programming", "rust", "c++", "d"]
+
+[extra]
+author = "harald"
++++
+
+## Rust
+
+I accidentally got an extra day off from work, so then I figured I could have a
+go at some initial dabblings in [Rust]. I haven't had time to play with
+this language at all yet, but skimming through the tutorial online a while ago
+got me interested. So off I went and wrote the mandatory intro-program:
+"Hello, world!"
+
+```rust
+fn main() {
+ println!("Hello, world!");
+}
+```
+<!-- more -->
+
+Nice and easy, and running the rust compiler gives me an executable I can run right away:
+
+```
+$ rustc hello.rs
+$ ./hello
+Hello, world!
+$ ls -l
+total 428
+-rwxr-xr-x 1 rabalder rabalder 430656 Mar 19 13:27 hello
+-rw-r--r-- 1 rabalder rabalder 45 Mar 19 10:18 hello.rs
+```
+
+Whoa! What's that, a minimalist hello world program takes about 430kB? Sounds excessive, but to be frank I didn't have anything to compare with, so let's see how some other common languages fare.
+
+## C++
+
+C++ is mature and has a long history. Together with it's parent C and grandparent FORTRAN, this is pretty much where the art of compiler writing has been developed and fine tuned. I would expect this to fare really well, so let's see how it checks out:
+
+```cpp
+#include <iostream>
+int main()
+{
+ std::cout << "Hello, world!" << std::endl;
+}
+```
+
+Compiling and checking with both gcc and clang:
+
+```
+$ g++ -o hello-g++ hello.cpp
+$ clang++ -o hello-clang++ hello.cpp
+$ ./hello-g++
+Hello, world!
+$ ./hello-clang++
+Hello, world!
+$ ls -l
+total 28
+-rwxr-xr-x 1 rabalder rabalder 8416 Mar 19 13:34 hello-clang++
+-rw-r--r-- 1 rabalder rabalder 83 Mar 19 10:23 hello.cpp
+-rwxr-xr-x 1 rabalder rabalder 8424 Mar 19 13:34 hello-g++
+```
+
+Pretty much exactly the same size for both. Definitely a lot better. Still a tad large for such a minimalist program, I think.
+
+## D
+
+Another language I have found interresting for quite a while is [D]. I have never really had the time to play with it though. At least nothing beyond the simple hello world type of programs. However reading about the language design, and following its development, I think it looks very promising.
+
+```d
+import std.stdio;
+void main()
+{
+ writeln("Hello, world!");
+}
+```
+
+Here we have three choices for the compiler, the official [dmd], [ldc] using llvm as a backend, and [gdc] built on the Gnu Compiler Collection:
+
+```
+$ dmd -ofhello-dmd hello.d
+$ ldc2 -ofhello-ldc2 hello.d
+$ gdc -o hello-gdc hello.d
+$ ./hello-dmd
+Hello, world!
+$ ./hello-ldc2
+Hello, world!
+$ ./hello-gdc
+Hello, world!
+$ ls -l
+total 3172
+-rw-r--r-- 1 rabalder rabalder 65 Mar 19 13:39 hello.d
+-rwxr-xr-x 1 rabalder rabalder 533080 Mar 19 14:39 hello-dmd
+-rwxr-xr-x 1 rabalder rabalder 2689880 Mar 19 15:23 hello-gdc
+-rwxr-xr-x 1 rabalder rabalder 12712 Mar 19 14:08 hello-ldc2
+```
+
+Interesting!
+
+[gdc] produces an absolutely humongous executable. 2.7MB for a simple hello world is clearly out of line!
+
+On the other hand [dmd] produces an executable in line with our original samle
+in Rust, 530kB. The winner is clearly [ldc] which gets away with 13kB. That's
+almost in line with the C++ version, even if it's about twice as large.
+
+The object files may be more interesting in this case:
+
+```
+-rw-r--r-- 1 rabalder rabalder 39512 Mar 19 15:31 hello-dmd.o
+-rw-r--r-- 1 rabalder rabalder 21936 Mar 19 15:29 hello-gdc.o
+-rw-r--r-- 1 rabalder rabalder 12384 Mar 19 15:30 hello-ldc2.o
+```
+
+They are much more comparable. The dmd-produced object file is still three times as large as the one produced by ldc, but it's less than a tenth of the complete executable. Also gdc plots itself nicely in the middle.
+
+My suspicion is that the rest of the executable in the gdc and dmd case is the full runtime library. On the other hand ldc produces an executable only slightly larger than the object file, which indicates it only links in the parts of the runtime that it needs. Why the huge difference between the executables produced by gdc and dmd, I do not know. If the object files was any indication, I would expect the relationship to be the other way around.
+
+## Assembler
+
+Just for comparison I also did a take a small hello world in assembler:
+
+```asm
+ use64
+
+stdout equ 1
+syscall_write equ 1
+syscall_exit equ 60
+
+section .data
+hello db 'Hello, world!', 10
+hello_len equ $-hello
+
+section .text
+ global _start
+
+_start:
+ mov rax, syscall_write
+ mov rdi, stdout
+ mov rsi, hello
+ mov rdx, hello_len
+ syscall
+
+ mov rax, syscall_exit
+ mov rdi, 0
+ syscall
+```
+
+I used nasm to assemble this:
+
+```
+$ nasm -f elf64 -o hello.o hello.asm
+$ ld -o hello hello.o
+$ ./hello
+Hello, world!
+$ ls -l
+total 12
+-rwxr-xr-x 1 rabalder rabalder 1064 Mar 19 14:47 hello
+-rw-r--r-- 1 rabalder rabalder 491 Mar 19 12:40 hello.asm
+-rw-r--r-- 1 rabalder rabalder 992 Mar 19 14:46 hello.o
+```
+
+Here we end up with an executable of about 1kB. My first attempt was actually about half that size again. I accidentally stripped away unused symbols that the linker includes by default. However, since I've done no optimizations in the other cases I found that to be a bit unfair. Still this is quite minimal compared to the other examples.
+
+## Conclusion
+
+So why do the different languages and compilers produce so wildly different executables for the same program?
+
+For the really big deviations we see with Rust and D compiled with gdc or dmd I am certain that the result is caused by including the full runtime library in the executable. There's probably ways to strip out what's not being used, which would reduce the size considerable for all of these cases. I have not explored how to do this.
+
+Looking at the object files produced from the actual source files seems to be a lot more predictable across languages and compilers. While the executable is meant to be a complete and standalone entity, something you can just run. The object file represents the actual machine code produced directly from the source. This means that the executable must include any supporting code that is needed during runtime. This part can vary significantly from one language to another.
+
+In fact, producing the object file from Rust, we see the following:
+
+```
+$ rustc --emit obj hello.rs
+$ ls -l hello.o
+-rw-r--r-- 1 rabalder rabalder 3696 Mar 19 14:56 hello.o
+```
+
+The object file is only 3.7kB. That's one third of the code produced by ldc again. Also for C++ the object files differ significantly from the finished executable:
+
+```
+-rw-r--r-- 1 rabalder rabalder 2656 Mar 19 16:05 hello-g++.o
+-rw-r--r-- 1 rabalder rabalder 2856 Mar 19 16:08 hello-clang++.o
+```
+
+With this comparison, it seems the Rust compiler is quite comparable to the code produced by the much more mature and state of the art compilers for C++.
+
+Anyways, this is a detour, and not an attempt to compare which language or compiler is better in any way. This is far from any real world scenario, and for more complex programs you may get completely different results.
+
+I have specifically not done any optimization of the linker stage. I wanted to see the difference between how the different languages compilers produced the resulting executable with the default settings.
+
+Further, comparing a very young language like Rust, that's still very much evolving, to some of the most mature toolchains there is will never be a fair comparison. Even if D is quite a bit older, it is also a language that still evolves rapidly. For both of these languages, I expect that as both the languages and tools mature they will become more comparable both to C++ and to each other.
+
+Even with all of the caveats above, I found this exercise quite interesting. I hope you did too.
+
+[Rust]: http://www.rust-lang.org/
+[D]: http://dlang.org/
+[dmd]: http://dlang.org/download.html
+[ldc]: https://github.com/ldc-developers/ldc/releases
+[gdc]: http://gdcproject.org/downloads
diff --git a/content/blog/2015-06-02-interessant-om-taterne/index.md b/content/blog/2015-06-02-interessant-om-taterne/index.md
new file mode 100644
index 0000000..1ecb066
--- /dev/null
+++ b/content/blog/2015-06-02-interessant-om-taterne/index.md
@@ -0,0 +1,20 @@
++++
+title = "Interessant om taterne"
+lang = "no"
+
+[taxonomies]
+tags = ["norge", "rasisme", "historie"]
+
+[extra]
+author = "harald"
++++
+
+Interessant [innlegg i Dagbladet][1] om taterne og romanifolkets behandling før, under og etter 2. verdenskrig:
+
+> Dersom NS-regimet hadde sendt taterne/romanifolket ut av landet, ville krigen markert et radikalt brudd med norsk assimileringspolitikk overfor folkegruppen. I stedet lanserte regimet en variant av venstrestatens assimileringspolitikk.
+>
+> I arbeiderpartistaten etter krigen ble denne politikken videreført og skjerpet, uten kritiske spørsmål.
+
+Les resten av innlegget [her][1].
+
+[1]: https://www.dagbladet.no/2015/06/02/kultur/meninger/debatt/tater/sterilisering/39453139/
diff --git a/content/blog/2015-06-09-the-stench-of-corruption/index.md b/content/blog/2015-06-09-the-stench-of-corruption/index.md
new file mode 100644
index 0000000..63b56f9
--- /dev/null
+++ b/content/blog/2015-06-09-the-stench-of-corruption/index.md
@@ -0,0 +1,24 @@
++++
+title = "The stench of corruption"
+lang = "en"
+
+[taxonomies]
+tags = ["politics", "corruption"]
+
+[extra]
+author = "harald"
++++
+
+From an [article in the Intercept][1]:
+
+> Senators, generals, ambassadors, former British Prime Minister Tony Blair and
+> the owner of The Atlantic were in the roster of powerful voices who wrote to a
+> federal judge to ask him to go easy on former CIA director and retired general
+> David Petraeus, who admitted to giving classified information to his mistress
+> and biographer.
+
+There is a stark and terrible contrast between how people already in power is
+treated compared to the whistleblowers that does not have these powerful
+connections. Read the [full article][1].
+
+[1]: https://firstlook.org/theintercept/2015/06/08/david-petraeus-powerful-friends-ask-judge-leniency/
diff --git a/content/blog/2015-06-26-kildevernet-i-norge-er-dødt/index.md b/content/blog/2015-06-26-kildevernet-i-norge-er-dødt/index.md
new file mode 100644
index 0000000..9d5d024
--- /dev/null
+++ b/content/blog/2015-06-26-kildevernet-i-norge-er-dødt/index.md
@@ -0,0 +1,22 @@
++++
+title = "Kildevernet i Norge er dødt!"
+lang = "no"
+
+[taxonomies]
+tags = ["PST", "pressefrihet", "kildevern"]
+
+[extra]
+author = "harald"
++++
+
+> Oslo tingrett har avgjort at PST får se beslaglagt materiale som skal vise en terrorsiktet 18-åring som angivelig skulle reise til Syria, skriver VG.
+>
+> Beslaget er av upublisert materiale fra en kommende dokumentarfilm fra filmskaper Ulrik Imtiaz Rolfsen.
+
+(Kilde: [Dagbladet, 26/6-2015])
+
+Det vil i klartekst si at kildevernet ikke lenger eksisterer i Norge. Politiet og PST kan når de måtte ønske det beslaglegge og få tilgang til råmateriale som journalister har under arbeid for å avdekke kilder til materialet.
+
+Dette er ikke akseptabelt i en rettstat hvor vi er avhengige av en fri presse som kan kritisere og korrigere myndighetene. Med den presedens som PST nå har fått i denne saken er ikke det lengre mulig. Norge er ett skritt nærmere å være en politistat.
+
+[Dagbladet, 26/6-2015]: http://www.dagbladet.no/2015/06/26/nyheter/innenriks/ulrik_imtiaz_rolfsen/39866542/