Konpat's Record of Struggles

จารึกการดิ้นรนของกรพัฒน์

Swap Alt and Ctrl Ubuntu 16.04

Using dconf-editor, if you have already tried the xmodmap way, tried this one ... it's superior because the xmodmap will fail (and need to be rerun) after you change the keyboard layout, furthermore, it has no currently reliable way to start it on login or after boot.

So, let's get started, if you don't have one:

sudo apt install dconf-editor  

Open it up, and see the org.gnome.desktop.input-sources.xkb-options, you might see [] for now, but update it to ['ctrl:swap_lalt_lctl','ctrl:swap_ralt_rctl'].

You should see the effect immediately.

Furthermore, you might have problem with alt+tab (now currently is ctrl+tab), if you want to change to ctrl+tab, just to keep it matched with the physical alt, read on.

Change Alt + Tab to Ctrl + Tab

It turns out even you have the unity-tweak-tool it's not at all straightforward to change this, because the tool won't allow you to bind ctrl+tab actually it won't allow even alt+tab, I think it's a bug or the app has no privilege to intercept the alt+tab itself.

So, another way is through the compizconfig-settings-manager, if you don't have it just install.

In it, you should find the Ubuntu Unity Plugin section, go to Switcher.

Now update it to be as follows, see the Key to start the switcher is now set to <Control>Tab:

If you want to also change the shortcut for switching windows in the same app (which default is alt + grave accent), you may change it now with the Key to flip through windows in the Switcher set it to control + grave accent instead.

อ่านต่อ »

A Rule of thumb to Install Ubuntu Alongside with Windows

A rule of thumb is: if you install windows in UEFI mode (which Windows 10 is almost always be), you will need to install Ubuntu in UEFI mode as well.

If you missed that out prepare to have problems with booting. This kind of problem won't be fixed with ANY tools regrading the booting problems, maybe any is an overstatement, but I did try the boot-repair (https://help.ubuntu.com/community/Boot-Repair), all it's saying was boot it with UEFI mode.

So, how to install Ubuntu with UEFI mode then ?

As the link suggests, you can make sure that you do it right if you create an only UEFI bootable usb. This way you can guarantee that if it works it's gonna work right.

The process of creating a UEFI bootable usb is in the link, but I will recap it here:

  1. Insert USB.
  2. Format it to FAT32, flag it with boot and lsb, you might use the Gparted to do this.
  3. Mount the USB.
  4. Copy all files from the .iso file, to the USB, including all hidden files (ctrl + h, in nautilus to see the hidden files)
  5. But, I prefer this way better, 7z x <.iso_file> -o<usb_mount_path_with_trailing_slash>
  6. That's all.

Tried to boot it, you might have to set your bios to enable UEFI mode or even prefer it first.

If you already have problem

You still can make it boot up, but only with the help of Super Grub2 Disk (http://www.supergrubdisk.org/super-grub2-disk/), it will automatically detect all installed bootable OSes in all your drives, you can select one of the option and boot into your os. It's not permanent at least you can boot into.

If you want to reinstall grub2, you can try sudo

อ่านต่อ »

Enable Docker Remote API

Do you know that docker doesn't allow remote API as default. So, if you want to use the remote interpreter feature of PyCharm, you are out of luck out of the box.

In which case, you have to enable it first... here is how you do it.

the original article is here

First thing, let's see the docker status first:

sudo systemctl status docker  
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/docker.service.d
           └─override.conf
   Active: active (running) since จ. 2017-02-27 14:10:48 ICT; 4min 16s ago
     Docs: https://docs.docker.com
 Main PID: 10750 (dockerd)
   CGroup: /system.slice/docker.service
           ├─10750 /usr/bin/dockerd -H fd://
           └─10768 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-cont

... so much more ..

In CGroup, you will see that the dockerd is run with almost no arguments.

We might expect it to be like this instead to allow the local connection to the dockerd via a tcp port:

***** dockerd -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock

To realize that, we have to edit how the dockerd is started:

sudo systemctl edit docker  

Will open an editor editing a specific newly generated configuration file, which by the way should be blank in this case.

Add these lines:

[Service]
ExecStart=  
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock  

To take effect, restart the daemon:

sudo service docker restart  
อ่านต่อ »

Docker Repice for "gcsfuse" (Google Cloud Storage FUSE)

What's gcsfuse ?

from: https://cloud.google.com/storage/docs/gcs-fuse

Cloud Storage FUSE is an open source FUSE adapter that allows you to mount Google Cloud Storage buckets as file systems on Linux or OS X systems.

gcsfuse main repository: https://github.com/GoogleCloudPlatform/gcsfuse

Dockerize it

This is the product of many hours of my trail-and-error.

In the Dockerfile:

FROM debian:latest

RUN apt-get update  
RUN apt-get install -y curl lsb-release

RUN export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s` \  
    && echo "deb http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | tee /etc/apt/sources.list.d/gcsfuse.list \
    && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

RUN apt-get update  
RUN apt-get install -y gcsfuse

# need to run command with given user_id
RUN apt-get install -y sudo

# set running environments
ENV GOOGLE_APPLICATION_CREDENTIALS /credential.json  
ENV BUCKET_NAME undefined-bucket-name  
ENV UID 1  
ENV DATA_DIR /mnt

COPY entrypoint.sh /  
ENTRYPOINT ["sh", "/entrypoint.sh"]  

In the entrypoint.sh:

# just in case ...
chown -R ${UID}:${UID} ${DATA_DIR} 

# run with given user
exec sudo -u "#${UID}" gcsfuse --foreground --key-file=${GOOGLE_APPLICATION_CREDENTIALS} ${BUCKET_NAME} ${DATA_DIR}  

You may build it using: docker build -t gcsfuse .

The run command:

BUCKET_NAME=<your_bucket_name> \  
UID=${UID} \  
docker run -it --rm --privileged \  
  -v /etc/passwd:/etc/passwd:ro \
  -v <path_to_credentials>:/credential.json:ro \
  -v <your_mount_path>:/mnt:shared \
  gcsfuse

Note: :shared is crucial here ... it allows late-mouting in the container be visible to the host filesystem, without it, the host will not see anything as a result that the mounting point is being replaced by the newer one, and thus becoming obsolete.

Note2: the credential.json is the Service Account Key obtained from

อ่านต่อ »

Screenshot in Ubuntu using Shutter

You probably have this app pre-installed so search for it first.
If not, in any case, install it via apt install shutter.

Now, we will start using it.

Open the app Shutter, and go right to the preferences pane.

On the first page you might want to select automatically save file and automatically copy screenshot to clipboard like this:

And to keep the shutter programe from opening after we capture the screenshot you might want to uncheck the present main window after taking a screenshot option like this:

Now, the only part left is to bind it with shortcuts, we'll go to the keyboard settings, if you can't remember it's this one:

Go to the shortcuts menu, and create some:

Each of which is described as follows:

Note that these are the shutter options you can see full list from shutter --help

อ่านต่อ »

My Experiences with OneDrive (Review)

I have been using OneDrive for 2 months already, here I like to review my experiences with OneDrive a bit. In short, it's sluggish, memory hungry, and not FAULT tolerant.

It's Sluggish and memory hungry

Maybe, I exaggerated on this because the demand I put on it is quite extraorditary. I actually put 300k files (small ones by many) into the OneDrive system. It becomes processing changes forever. It took days (2 days + or -, if I counted correctly) to finish. And yet most of the time, not the internet bandwidth that it consumes, it rather the CPU itself that always spiked, with the memory usage of about 1 GB all the time.

Even I use the latest CPU from intel, admittedly it's ultralow voltage series, but hey its the latest Kaby Lake ! I expected much more from it rather than be totally consumed by the simple process of syncing!

Work harder Microsoft!

It's not fault tolerant

First thing first, if you're moving from the unix-world filesystems like ext4 or hfs+. You would very likely encounter the path too long problem in NTFS. NTFS supports only a puny fraction of maximum path length of those filesystems. Syncing these files to the Windows machine is a disaster! You might have to resolve it by hand, moving folders after folderes to the shorter paths. It was just a pain, but not necessarily contributed to the OneDrive, but anyways I will put it here!

It's not the end, there are many more scenarios in which I encounter problems. When I changing the contents in the drives in SOME WAYS it made the OneDrive process crashed. I reckon the moment to be when I used the program rsync to sync files from a remote host to my machine, it crashed severely and cannot be

อ่านต่อ »

Make \ (backslash) and / (slash) interchangeable in Windows command line

File: slash.cmd

@echo off
setlocal ENABLEDELAYEDEXPANSION  
set str=%*  
set str=!str:\=/!

REM run the parsed command  
%str%

It will execute the command while replace all the \ to /. Like, docker run -it -v %HOME%\test\dir:/workdir debian bash to be docker run -it -v %HOME%/test/dir:/workdir. Since, the Windows command prompt will only auto-complete the path using \ which doesn't work with Docker (linux) paths.

อ่านต่อ »