Saturday, July 30, 2016

Haskell in Docker

This is for my functional programming friends.

If you want to try haskell, or try a different version of haskell than the one you have on your system, you can use one of the official  haskell docker containers.

All you need is Docker and the following two commands:


docker pull haskell
docker run --rm --interactive --tty haskell

and you are done, you are in ghc interactive mode

Thursday, July 28, 2016

Merging git branches while keeping some files from the old branch

Lets say we have master and experimental branch.
Master has evolved and we would like to merge its changes in the experimental branch, that has not yet lost its value.

But there are some files in the experimental branch we would like to keep.

How can we do that?

First we need to create our own merge driver. A merge driver is the command that is responsible for the actual merging of the files. In this case we need a driver that does not do anything to the files we want to preserve.

We can accomplish that by using this command:

git config --global merge.ours.driver true


This driver will always return true for every file that meets a specific pattern. What is this pattern and how do we configure it?

We need to create a file called .gitattributes in our project, version it, and add as contents the pattern of the files we would like to keep from being merged:

echo 'email.json merge=ours' >> .gitattributes
git add .gitattributes
git commit -m 'chore: Preserve email.json during merges'

This will protect a file called email.json from being merged.

After that we execute
git merge -

to complete the merge.

If you need more details please check this link: https://medium.com/@porteneuve/how-to-make-git-preserve-specific-files-while-merging-18c92343826b#.fbw1wyyby

Wednesday, July 27, 2016

Inspecting a docker container.

It is very common to perceive a docker container as a black box, you do now know what is in there, and very rightly so. That is what a container is all about.
But what happens when you want to actually finetune its deployment? What happens when you want to find out if there are multiple ports or volumes defined, in it. What are the hashes that are being used in your system?

All these can be retrieved by using the docker inspect command:

docker inspect grafana

And this is the output:

[
    {
        "Id": "6280c5bb41b8a5410d0d35b478e1617d77c332df503b32271cebdc5aadc68579",
        "Created": "2016-07-27T17:32:56.328619446Z",
        "Path": "/run.sh",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 8153,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-07-27T17:32:57.239316798Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:932c5bca836b177b4f2071fd1061d8649f74fb510fe51b5e2d466a0e4856f10a",
        "ResolvConfPath": "/zfspool1/docker/containers/6280c5bb41b8a5410d0d35b478e1617d77c332df503b32271cebdc5aadc68579/resolv.conf",
        "HostnamePath": "/zfspool1/docker/containers/6280c5bb41b8a5410d0d35b478e1617d77c332df503b32271cebdc5aadc68579/hostname",
        "HostsPath": "/zfspool1/docker/containers/6280c5bb41b8a5410d0d35b478e1617d77c332df503b32271cebdc5aadc68579/hosts",
        "LogPath": "/zfspool1/docker/containers/6280c5bb41b8a5410d0d35b478e1617d77c332df503b32271cebdc5aadc68579/6280c5bb41b8a5410d0d35b478e1617d77c332df503b32271cebdc5aadc68579-json.log",
        "Name": "/grafana",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "3000/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "3000"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [
                "grafana-storage"
            ],
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "StorageOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "BlkioIOps": 0,
            "BlkioBps": 0,
            "SandboxSize": 0
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [
            {
                "Name": "b68a5fe8f6e8c817bfacbbd8004e2452411673bd631e09564873a58badc0ac3d",
                "Source": "/zfspool1/docker/volumes/b68a5fe8f6e8c817bfacbbd8004e2452411673bd631e09564873a58badc0ac3d/_data",
                "Destination": "/etc/grafana",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Source": "/zfspool1/grafana-volume",
                "Destination": "/var/lib/grafana",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Name": "ac220948e55e4e65ac9905b480bf1150aa8732a0ab6b094a8269032921478775",
                "Source": "/zfspool1/docker/volumes/ac220948e55e4e65ac9905b480bf1150aa8732a0ab6b094a8269032921478775/_data",
                "Destination": "/var/lib/grafana/plugins",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Name": "7be07c6927bbe12d0957a05a8bf3284a6e10c0ec9152646b85c2583e47a2ac6e",
                "Source": "/zfspool1/docker/volumes/7be07c6927bbe12d0957a05a8bf3284a6e10c0ec9152646b85c2583e47a2ac6e/_data",
                "Destination": "/var/log/grafana",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "6280c5bb41b8",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": null,
            "Image": "grafana/grafana",
            "Volumes": {
                "/etc/grafana": {},
                "/var/lib/grafana": {},
                "/var/lib/grafana/plugins": {},
                "/var/log/grafana": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "/run.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "121cb533502a3613ed086db64b3291c6dcaf2808fa97499c5bd1aac95a913593",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "3000/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "3000"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/121cb533502a",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "bd06a65e45743a62d86509ff4ec49b38f78e8c23c5dc45c74c3cdfb98c840c21",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "8312143de9ee482776c4b923b71d695687244fc9ac28ec8d151bd7678a9240ae",
                    "EndpointID": "bd06a65e45743a62d86509ff4ec49b38f78e8c23c5dc45c74c3cdfb98c840c21",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02"
                }
            }
        }
    }
]

Sunday, July 24, 2016

Setting up a freebsd box with Vagrant

It makes sense to be able to spin up a freebsd system to use as for test of new ideas and concepts. It is also a good way for one to familiarize himself with the platform and experiment with new settings and technologies.

One of the easiest ways to do this is to use Vagrant. All it is needed is the following Vagrantfile:

# -*- mode: ruby -*-"
# vi: set ft=ruby :

box_type  = "freebsd/FreeBSD-10.3-RELEASE"

Vagrant.configure("2") do |config|
  config.vm.box = "#{box_type}"
  config.vm.synced_folder ".", "/vagrant", :disabled => true
  config.vbguest.auto_update = false
  config.ssh.shell = "sh"
  config.vm.base_mac = "080027D14C66"

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--memory", "1024"]
    vb.customize ["modifyvm", :id, "--cpus", "1"]
    vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
    vb.customize ["modifyvm", :id, "--audio", "none"]
    vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
    vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
  end

end

Saturday, July 23, 2016

Installing latex packages with greek support for ubuntu 16.04

It is natural for things to evolve, and that is true for package names in linux distributions. So the good old tetex package family has evolved to texlive in ubuntu and what used to be one big package has been split to multiple smaller.
So in order to compile my latex files with Greek support and all, i need to install the following packages (and their dependencies) in ubuntu 16.04:


  • texlive
  • texlive-latex-extra
  • texlive-lang-greek

Tuesday, July 12, 2016

Autojump usage

Autojump is a tool that allows us to navigate our filesystem faster when using the command line.
It does all that by keeping statistics of which folders we visit most frequently and by making that available to us through some handy shortcuts.

There are multiple integrations with various shells, and an autojump plugin bundled with my oh-my-zsh.

Installation:

We can install autojump using our package manager:
sudo apt-get install autojump

After that we need to source its initialization file. There are different files for each mainstream shell, so for zsh in ubuntu this line should do the trick:

[[ -s /usr/share/autojump/autojump.zsh ]] && . /usr/share/autojump/autojump.zsh

copy that in your .zshrc and do a
. ~/.zshrc

you are ready to use autojump now.

Usage:

See statistics:
autojump -s

Navigate:

j dir

Open a directory in file browser instead of navigating:

jo dir

Autojump website:https://github.com/wting/autojump

Autojump usage

Autojump is a tool that allows us to navigate our filesystem faster when using the command line.
It does all that by keeping statistics of which folders we visit most frequently and by making that available to us through some handy shortcuts.

There are multiple integrations with various shells, and an autojump plugin bundled with my oh-my-zsh.

Installation:

We can install autojump using our package manager:
sudo apt-get install autojump

After that we need to source its initialization file. There are different files for each mainstream shell, so for zsh in ubuntu this line should do the trick:

[[ -s /usr/share/autojump/autojump.zsh ]] && . /usr/share/autojump/autojump.zsh

copy that in your .zshrc and do a
. ~/.zshrc

you are ready to use autojump now.

Usage:

See statistics:
autojump -s

Navigate:

j dir

Open a directory in file browser instead of navigating:

jo dir

Autojump website:https://github.com/wting/autojump

Thursday, July 7, 2016

Cleaning up docker device mapper

Docker device mapper is an alternative storage backend to aufs.
During everyday operation lots of images are downloaded that are never  deleted , so the device mapper may end up taking a lot of space in your system, unless you remember to clean it up regularly.

You can see the details about your docker instance by executing

sudo  docker info

This command will tell you what backend you are using and how much space is allocated to it.

After executing a container, you may want to clean up the images it downloaded in order for it to run. People usually forget to do this and eventually they end up taking a lot of space.

An easy way to clean any unused images and cleanup your device mapper is by executing the following command:

sudo docker images -a|awk '{print $3}'|xargs sudo docker rmi

In the past there was a bug that prevented docker from releasing the disk space. This has been now resolved and you should have no issues if you are running a newer kernel than 3.13