Friday, November 20, 2015

Cache and SSL in Chrome on Ubuntu Linux

I had a hard time testing if cache headers I've added to static files are working. Firefox was working as supposed, while Chrome wasn't.

Here is the Nginx configuration I was testing:

    # static files
    location ~ ^/(***)?$ {
        root ***;
        try_files $uri /;
        add_header Cache-Control "max-age=3600";
        gzip on;
        #etag on;
        access_log off;

I was trying different combinations to find out why sometimes the files where taken from cache (looking to developer's console in Chrome) and why other times Chrome was always making requests with response 200.

My tests showed that my Chrome was using cache if both Cache-Control and ETag headers where present. The problem is that if `etag on` directive is enabled together with `gzip on`, etags are not generated:

When I disable gzip and enable etag, cache works ok.

But my colleagues say that in their browsers, including Chrome on OSX cache works as expected.

It turned out that the server I was testing on had a self signed certificate, and Chrome has issues with caching in such cases:

I tried to export the certificate and import it back as a trusted certificate, but it didn't work. They say:

Google Chrome in Linux doesn’t have a SSL certificate manager, it relies on the NSS Shared DB.

Now cache works as expected in my Chrome on Ubuntu Linux.

Thursday, November 5, 2015

Run SketchUp Make 2015 in Ubuntu 15.10

1. Install wine
2. Download SketchUp Make 2015 Windows 32 Bit from
3. In a terminal
export WINEARCH=win32 WINEPREFIX=$HOME/sketchup
# select Windows 7
# run installation
wine SketchUpMake-en.exe
# run SketchUp
wine C:/Program\ Files/SketchUp/SketchUp\ 2015/SketchUp.exe /DisableRubyAPI
Menu crashes the program, so press Ctrl-O to open a file.

I've installed Wine 1.7.44 and the program doesn't crash when selecting File menu.

Wednesday, May 20, 2015

Nina Zakharenko - Technical Debt - The code monster in everyone's closet - PyCon 2015

Technical debt is the code monster hiding in everyone's closet. If you ignore it, it will terrorize you at night. To banish it and re-gain your productivity, you'll need to face it head on.

Alex Gaynor - Techniques for Debugging Hard Problems - PyCon 2015

Sometimes your programs have bugs. Often they're shallow things, simple AttributeErrors or TypeErrors. Sometimes they're large, complex, and nearly impossible to debug. This talk explores techniques for figuring these out.

Tuesday, May 19, 2015

Distributed Systems 101 - PyCon 2015

A very brief introduction to the theory and practice of distributed systems.

Thursday, March 12, 2015

Console editor with Notepad behavior

When I started using Linux (it was Ubuntu in 2007), I wanted a console text editor which would support keyboard shortcuts used in Windows Notepad:

- Ctrl + Left/Right -- go to the beginning/end of the previous/next word
- Ctrl + Home/End -- go to the beginning/end of the file
- Shift + Left/Right -- select previous/next character
- Control + Shift + Left/Right -- select previous/next word
- Control + Shift + Home/End -- select line to the beginning/end
- Control + C/V/X/Z -- copy/paste/cut selected text, undo last operation

Nano, which is present in Ubuntu out of the box, is quite simple, but doesn't support almost all of the shorcuts.

Vim -- I didn't like it immediately -- I even didn't know to close it.

Emacs -- I could not exit it either, but I liked it more.

In the end I stopped looking and used what I have -- Vim/Emacs/Nano.

But today I found out that Emacs starting with version 22.1.1 has Cua mode.
The command M-x cua-mode sets up key bindings that are compatible with the Common User Access (CUA) system used in many other applications.
Add this to `~/.emacs`:

(cua-mode t)
(setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour

and it works!

Be aware that Emacs has its own clipboard, and Ctrl+V will not paste system clipboard contents.

Sunday, March 8, 2015

Shell script argument with a default value

So, I made I shell script which makes some backup copies. I want it to accept one argument which is the directory where to store the backups. And if it was not provided, it should have some default value.

This works:
if [ -z "$1" ]; then
echo "${BACKUP_DIR}"

But it's too verbose. Of course you could write it in one line, but here is a nicer version:
[ -z "$1" ] && BACKUP_DIR="/home/ubuntu/backups" || BACKUP_DIR="$1"

But the variable name is repeated twice. We can do better:

BACKUP_DIR=$([ -z "$1" ] && echo "/home/ubuntu/backups" || echo "$1")

But I think this is the clear winner:


If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted.