Hello World! In Clojure

So, as part of my new year’s resolution for 2018 I decided to learn some functional programming, and I picked the clojure language to be my tool.

I’ll just use this space to write down the things I’m doing during my learning.

Of course the first exercise in every new programming language is to write a hello world, so I started by reading clojure’s getting started to learn how to begin.

Because clojure is a JVM language make sure you have java installed at you OS before starting.

While reading the getting started to understand how to install clojure I discovered there is a very nice build tool called Leiningen, which is pretty easy to install, you just have to download a script to one of your binaries path, like:

$ mkdir $HOME/bin
$ cd $HOME/bin
$ wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
$ chmod +x lein

Done!

After having leiningen installed it becomes pretty easy to have your first hello-world in clojure up and running:

$ lein new app hello-world

This command will bootstrap a project with everything set to have a hello-world running and the directory tree will look like:

hello-world/
├── CHANGELOG.md
├── doc
│   └── intro.md
├── LICENSE
├── project.clj
├── README.md
├── resources
├── src
│   └── hello_world
│       └── core.clj
├── target
│   └── default
│       ├── classes
│       │   └── META-INF
│       │       └── maven
│       │           └── hello-world
│       │               └── hello-world
│       │                   └── pom.properties
│       └── stale
│           └── leiningen.core.classpath.extract-native-dependencies
└── test
    └── hello_world
        └── core_test.clj

The contents of src/hello_world/core.clj will have something like:

(ns hello-world.core
  (:gen-class))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

To run it you enter the project directory and tell lein to run:

$ cd hello-world
$ lein run

And the output you already know what it is!

See you at the next post!

New Year's Resolution For 2018

My new year’s resolution for 2018 is going to be simple, but I believe it will help me be a better professional.

Here is the list:

  • Learn how to program in a functional language (Clojure)
  • Read Cracking the Coding Interview
  • Release the MVP of my social network
  • Write about my resolution progress in this blog

How to sign kernel modules on Fedora

So you tried to load your modules and got a message that is similar to the following one:

[[email protected] ~]$ sudo modprobe -v acpi_call
insmod /lib/modules/4.10.13-200.fc25.x86_64/extra/acpi_call/acpi_call.ko 
modprobe: ERROR: could not insert 'acpi_call': Required key not available

No worries, there is a fix for that, you have to sign your modules before they can be loaded. This happens because you are using a neat feature called secure boot, which prevents unsigned modules to be loaded.

Step 1: Create your own keys

So in order to sign your modules you need to generate your set of keys and load it into your machine. You can generate your keys using the following command:

openssl req -new -x509 -newkey rsa:2048 \
        -keyout name-of-your-keys.priv \
        -outform DER -out name-of-your-keys.der \ 
        -nodes -days 36500 -subj "/CN=WhateverYouNameIt/"

And to load the newly generated keys:

sudo mokutil --import name-of-your-keys.der

Warning: On the command above you’ll be prompted for a password, put any password you want, just make sure to remember because you’ll need it for the next step.

Now you have to reboot your machine and follow the steps at the screen to enroll your new keys.

Step 2: Sign your modules

To sign your module you have to run the following command:

sudo /usr/src/kernels/$(uname -r)/scripts/sign-file sha256 \
     ./name-of-your-keys.priv ./name-of-your-keys.der \
     /lib/modules/4.10.13-200.fc25.x86_64/extra/acpi_call/acpi_call.ko

Just make sure to inform the right path of your keys and your modules. After the signing process you can use modprobe to load your modules as intended.

Enjoy!

How to fix second battery not charging on Thinkpad t460s

So, because I couldn’t find anywhere on the internet how to fix this issue I think I should write this down here. If someone has the same problem the solution is documented.

Here is the story:

Some days ago I noticed that only the first battery on my Thinkpad t460s was being charged. The second one had 4% charge and was not charging at all. I tried to boot on Windows to check if it was a Linux driver problem, but still not charging.

I updated all the drivers and firmwares on Windows and no fix.

The only way I could find was having the batteries disconnected, don’t worry, you don’t have to open your laptop for that.

Follow the steps:

  1. Reboot your computer
  2. Press F1 to enter the BIOS
  3. Go to Config tab
  4. Then, go to Power
  5. Remove your AC adapter cable from the laptop
  6. Go to Disable Built-in Battery
  7. Your computer will turn off
  8. Wait 10 seconds
  9. Put the AC adapter back
  10. Your Thinkpad should turn on and now both of your batteries should be charging

Enjoy!

Running docker as non-root on Fedora 25

To add docker privileges to the logged in user in a Fedora 25 setup you just have to run the following commands at the terminal:

sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo systemctl restart docker
newgrp docker

Now you should be able to see the running containers using the docker ps command.

Enjoy!