Saturday, September 3, 2016

Weaverley by sir Walter Scott

Just finished the first novel of Scott, with the title Weaverley.
It is one of the classic books of Scottish literature and narrates the story of an English gentleman of the name Weaverley, that serves as an officer in the English army during the Jacobite civil war.

Apart from the very long editorial, which may or may not exist in different versions of the book, and the somewhat flowery style of sir Scott, the book is captivating. It is describing the social structure in the scottish highlands during the civil war and also describes how the war itself affected the future generations of Scotland.

Overall a very interesting reading to anyone who is interested in understanding the complicated history of Scotland.

Wednesday, August 10, 2016

Resizing disk space in Virtualbox virtual machine

If you need to increase your disk space in a virtual machine, if your disk is in vmdk format then you need to execute the following steps:

First you need to convert your disk to vdi by cloning.
Vdi can be resized and replace the vmdk disk in place. Just remove the vmdk in the settings
Internal partition needs to be resized this can be done by using the gparted iso:

http://gparted.sourceforge.net/download.php


Add the gparted as a cd iso and boot from it, resize the partition. In the next boot the system will recognize the new capacity

Vdi cloning and disk increase can be done with the following two commands:
  • VBoxManage clonehd "/home/nickapos/VirtualBox VMs/NCRWin7/NCRWin7-2016-06-27-disk1.vmdk" "/home/nickapos/VirtualBox VMs/NCRWin7/win7clone.vdi" --format vdi
  • VBoxManage modifyhd "/home/nickapos/VirtualBox VMs/NCRWin7/win7clone.vdi" --resize 100000



After that we are ready to boot. This will work with windows as well as linux. If you need to export your vm, there is a chance that Virtualbox will convert the image back to vmdk

Monday, August 1, 2016

Ubuntu ufw and docker

If you are using a system with ufw and at the same time are using docker, please keep in mind that docker manipulates the iptables rules in order to allow access to its services.

That means that it will open ports that you never intended to open to the world.
In order to disable this, you need to add the  --iptables=false in its arguments and restart it.

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