Emacs mu4e: auto-complete mail addresses

I love auto-complete package. I wish it was more commonly used by other emacs packages. But luckily auto-complete is very easy to use(*). Below is a small snippet to use auto-complete mode for completing mail addresses when writing an e-mail with mu4e.

(defvar ac-source-contacts
  '((candidates . mu4e~contacts-for-completion)
    (prefix . "^\\(?:To\\|CC\\|BCC\\): \\(?:.*, *\\)?\\(.*\\)")))

(add-hook 'mu4e-compose-mode-hook
            (setq ac-sources '(ac-source-contacts))

(*) provided that you already have a nice list of candidates to choose from : )

Update 3/01/2015: `company-mode` which provides a completion mechanism very similar to `auto-complete` mode works with mu4e out of the box. You don’t have to configure anything. Install and enable. Although there is a graphical glitch, I find its completion better.

Python code to convert ligth wave length to RGB color

This is a small python function to convert a wave length of light to its corresponding RGB color. Note that this is a crude approximation. Calculating the actual RGB representation of a specific wave length is rather tricky. You could also say it’s impossible. That’s because your computer screen can only show a limited range of light colors. So, below code should be good enough for most presentational purposes.

def wave2rgb(wave):
    # This is a port of javascript code from  http://stackoverflow.com/a/14917481
    gamma = 0.8
    intensity_max = 1

    if wave < 380:
        red, green, blue = 0, 0, 0
    elif wave < 440:
        red = -(wave - 440) / (440 - 380)
        green, blue = 0, 1
    elif wave < 490:
        red = 0
        green = (wave - 440) / (490 - 440)
        blue = 1
    elif wave < 510:
        red, green = 0, 1
        blue = -(wave - 510) / (510 - 490)
    elif wave < 580:
        red = (wave - 510) / (580 - 510)
        green, blue = 1, 0
    elif wave < 645:
        red = 1
        green = -(wave - 645) / (645 - 580)
        blue = 0
    elif wave <= 780:
        red, green, blue = 1, 0, 0
        red, green, blue = 0, 0, 0

    # let the intensity fall of near the vision limits
    if wave < 380:
        factor = 0
    elif wave < 420:
        factor = 0.3 + 0.7 * (wave - 380) / (420 - 380)
    elif wave < 700:
        factor = 1
    elif wave <= 780:
        factor = 0.3 + 0.7 * (780 - wave) / (780 - 700)
        factor = 0

    def f(c):
        if c == 0:
            return 0
            return intensity_max * pow (c * factor, gamma)

    return f(red), f(green), f(blue)

Below is an example code that uses this function:

import matplotlib.pyplot as p
import numpy as np

N = 100
image = np.zeros((5,N,3))

for i in range(0, 5):
    for j in range(0, N):
        start = 380
        end = 780
        wave = j * (end-start)/N + start
        image[i][j] = wave2rgb(wave)

ax = p.axes()

This should produce an output similar to below:


Emacs on-the-fly (as you type) syntax checking for VHDL [flycheck, nvc]

Flycheck is an on the fly syntax checker for Emacs. When configured properly it performs really great. Flycheck itself doesn’t do syntax checking. It uses external tools for that. There are many syntax checker tools out there for programming languages like C and python, but none for vhdl. Then I’ve noticed that error output of nvc vhdl simulator is quite helpful and decided to use it as syntax checker back end. Result was better then I expected.

Integrating nvc with flycheck wasn’t hard. It’s merely adding a few lines to your init file. See below. I think the code is self-explanatory.

(flycheck-define-checker vhdl-nvc
 "A VHDL syntax checker using nvc."
 :command ("nvc" "--message=compact" "-a" source)
 ((error line-start (file-name) ":" line ":" column
 ": error: " (message) line-end))
 :modes vhdl-mode)

Obviously you will need nvc vhdl simulator for this to work. Get it from here: https://github.com/nickg/nvc

It’s not the best and you may encounter some problems using nvc like that, after all it’s not designed for this purpose. But it’s still pretty useful.

My Review of Lenovo T440s

This is my review of Lenovo T440s. It doesn’t cover much. It’s more like notes about things that have annoyed me with this device.


I knew that touchpad wasn’t good before buying this device. No review that I read has skipped that point. I thought, how bad it could be? Maybe it’s not as good as the -now- old design, but it should be a decent touchpad. After all there are no other products -that I know of- that has the famous touchpad of the Lenovo Thinkpad series. Well, I was wrong! This touchpad literally sucks! I can’t believe Lenovo decided to ship this beautiful product with this touchpad. It’s stupid but a few times I found myself thinking: have they deliberately tried to make this worse?

First of all, physical buttons are gone. You should have noticed that already.

When touching the touchpad (not clicking), it shakes and makes sound. It’s really annoying, and feels cheap. Like similar devices, whole touchpad is a button. But to for a click, you have to apply a decent amount of force. No problem, you can use touch-clicking. But this doesn’t work for right click. You have to actually press down the touchpad for a right click. When pressing the touchpad, cursor always moves around and I miss my target, which is really really annoying. It’s almost impossible to right click without cursor moving around (and sometimes messing things up).

There are two red markings on the top side of touchpad that I thought indicated left and right click. Nope. It’s left click everywhere, only right bottom side is right click. But when using the trackpoint right top side is right click. Middle click? There are markings on top middle, but no middle click. I think this works when using trackpoint, but I haven’t figured out that yet. I never knew that using a touchpad would be that confusing.

Palm rejection isn’t good. Touchpad area is quite big. When typing, my thumb touches the touchpad and this moves the cursor around, clicks etc. The fact that I have to focus on the position of cursor right now writing this blog post, is annoying.

By the way touchpad actually have a really nice surface. It feels nice to touch and move your finger around.


Keyboard is nice. I’m no lenovo expert, but this keyboard is as good as t530 (previous lenovo laptop that I had used).

Keyboard back light has two levels. You can switch between off state, half brightness and full brightness by pressing Fn+Space keys.

By default you have media keys in place of function keys. If you want to press a function key you can use Fn key. That’s not a big issue, you can press Fn+ESC and lock Fn key. Now, top row keys act as function keys and to use them as media keys you press Fn. When locked, green led of Fn key will be on, so that you are not confused.

Wi-Fi problems

I heard about brand new laptops having trouble with connecting to wifi, but I never heard one that crashes the wifi network! Yep. This device has crashed (and will continue to crash) my entire wifi network. I couldn’t connect to wifi from other devices, I had to restart the router and the wifi adapter of the other devices to be able to re-connect them. It’s a mess! I have found some reports that stated; this problem is caused by some Lenovo software, but I couldn’t find the exact problem yet (that problematic lenovo software doesn’t exist on my device). No wifi for now.

After installing linux I didn’t have much issue with the wifi. It’s just that sometimes signal goes away, and I have to restart the internal wifi adapter for it to work. But It’s rare, and it might be an issue with the wifi router I’m connecting to.


Generally LCD is good. It’s bright and viewing angles are spectacular. There is a little light bleeding on the edges – which is a common problem with all IPS displays. I only notice it when watching something fullscreen. It starts to be annoying when you watch things frequently.

But something else I keep noticing is a display artifact similar to a dead pixel. I’m not sure if it’s a dead pixel or not. It looks like a small, tiny 1-2 pixel wide shadow on the screen. It’s not really annoying. But still, I wish it didn’t exist.

Other Problems

This one isn’t exactly a product defect like others, but still, it’s an issue that I had to solve. Device disk came with 4 partitions already. Boot partition, system partition, recovery partition, some unknown partition.. And I learned that to be able to create another 5th partition I had to convert one of these to an extended partition which requires me to delete the system partition.. Isn’t that awesome!


Second day after I got the device, I have installed Linux Mint Debian (Cinnamon desktop) on it. Here is a list of problems I have encountered so far.

  • microphone mute key doesn’t work, led also doesn’t work (there is a fix that requires me to compile the kernel)
  • fingerprint doesn’t work (there is a patch to libfprint library, which is reported to work slow)
  • hibernate doesn’t work (I fixed that by creating a swap partition)
  • suspend drains too much power (I have measured it and it looks like, computer can survive on suspend only 6 days. This may sound like a small issue but consider that I sometimes leave my computer on suspend for two days, and when I open it up an important amount of battery is drained. I have switched to hibernate, because you never know when you need battery life.)
  • Occasional lock-ups after waking from hibernate! Whaaat? It literally locks down like windows. I think I should try another distribution. (Updated to Linux Mint 17 which is based on Ubuntu 14.04, problem persists)

Update 28 Dec: Case/Body

Laptop has an aluminum body which contributes it to look really sleek and still be lightweight. But actually design of the case has a serious defect. Maybe my unit has this problem, I don’t know. To see what I’m talking about please have look at the below photographs. You should have noticed the unfortunate scratches. These scratches are caused by the laptop lid. Even tough laptop lid has a rubber material on its edges that (I think) should have prevented this issue. But it seems that, this doesn’t work because inner part of the laptop lid, is too thick. Inner edges of the LCD (which doesn’t have any rubber) touches the bottom body of the laptop and causes these scratches. With all the small issues this is the most saddening one. It’s been only a few months and my laptop already looks old 🙁 .

Also when lid closed, keyboard touches the LCD and occasionally I have to clean the grease left from keys touching the screen (actually I wash my hands quite frequently). I hope this doesn’t cause a permanent problem in the future. I have been planning to use this laptop for a long time.

Script to Install Debian Packages as a Group

This is a python script to install debian packages as a group. This will allow you to remove the packages you don’t need easily when you want to clean your system.

When you install a package using `apt-get` it will mark all packages that are installed as it’s dependencies as “automatically installed”. When an “automatically installed” package is not needed by a “user installed” package it can be “automatically removed”. So when you install an application with `apt-get` it’s easy to remove its unnecessary dependencies. But if you frequently build and install applications from source, you will be installing bunch of packages which are build dependencies. And those packages will not be marked as “automatically installed”. Even if you mark them somehow, you need a parent package that depends on them to prevent them to be uninstalled with `apt-get autoremove`.

And this is where `depinstaller.py` will help you. It will create a dummy package with dependencies that you specify and install that package with gdebi. That way you can clean your system from these packages easily, by removing that dummy package and running `apt-get autoremove` afterwards.

You can find `depinstaller.py` at my public git repository: https://bitbucket.org/hyOzd/depinstaller

Emacs shell-mode and auto-complete integration

Looks nice, doesn’t it?

First you need to install bash-completion mode which will improve shell-mode completion by using bash’s completion support. Note that, at this moment bash-completion mode doesn’t work for me (bash –version = 4.3.11). This is probably the case for you as well. No worries, there is a fix that is not merged to master branch yet. You need to get complete_D branch and install that one.[Now it’s merged] Follow the setup instructions given in README file. And continue below.

Add below lines to your .emacs file:

(defun ac-bash-candidates ()
"This function is a modifed version of
bash-completion-dynamic-complete from bash-completion.el"
  (when bash-completion-enabled
    (let* ( (start (comint-line-beginning-position))
                    (pos (point))
                    (tokens (bash-completion-tokenize start pos))
                    (open-quote (bash-completion-tokenize-open-quote tokens))
                    (parsed (bash-completion-process-tokens tokens pos))
                    (line (cdr (assq 'line parsed)))
                    (point (cdr (assq 'point parsed)))
                    (cword (cdr (assq 'cword parsed)))
                    (words (cdr (assq 'words parsed)))
                    (stub (nth cword words))
                    (completions (bash-completion-comm line point words cword open-quote))
                    ;; Override configuration for comint-dynamic-simple-complete.
                    ;; Bash adds a space suffix automatically.
                    (comint-completion-addsuffix nil) )
      (if completions

(setq ac-source-bash
	  '((candidates . ac-bash-candidates)))

(add-hook 'shell-mode-hook
			(setq ac-sources '(ac-source-bash))

If you noticed I have actually used bash-completion-dynamic-complete from bash-completion.el.

pcb2blender – Move your pcb files to 3D with Blender

I have been working on a tool for a while, which converts your pcb design files to Blender 3D models and allows you to render fancy images. Blender is a free and awesome 3D design tool. pcb2blender only supports Eagle files for now but adding support for more tools won’t be an issue.

Above image is just a very ugly example you can create with pcb2blender. Blender is a very capable tool. Once you know what you are doing you will be able to create quite realistic renders. And I aim to make this completely automated for you.

So how pcb2blender works? Currently, it’s implemented as a python script which you call inside Blender. When you call Blender with below command, after a few minutes of magic your 3D model should be ready.

>> blender -P eagle2blender.py -- boardfile.brd

pcb2blender will read you pcb file, create outline of board and place components from it’s model library. And your 3D model is ready. Now you can edit your model any way you want with Blender’s tools and create very nice renders.

You can find the code at  https://bitbucket.org/hyOzd/pcb2blender. Since it’s under development, it’s much likely you will have problems. And don’t expect much from it since model library is almost empty. I’m working on it.

At the moment, I’m working on the structure of model library. Because once you start to create models, it’s hard to update them all in case of a change. It’s important to set it right at the beginning. So I need to be careful.

If you can make the code work or just can’t, please let me know. Remember to read README file. And use a proper OS, such as linux ; ) .

My first English post


This is my first English post. My blog is mainly in Turkish. But I want to share some tips in English too. So this time I set up my blog as bilingual.

If you see any mistakes I made writing please let me now. I would be greateful if you help me improve my English. Thanks in advance.