Showing posts from 2014

Improve font rendering for IntelliJ IDEA / Pycharm in Ubuntu

Stock font rendering in Pycharm / Intelliji IDEA is horrible on Ubuntu. To improve it, change the following:

First of all, we need to install Infinality fonts:
sudo add-apt-repository ppa:no1wantdthisname/ppa
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install fontconfig-infinality

sudo /etc/fonts/infinality/ setstyle linux
sudo gedit /etc/profile.d/
# and set
Installed the patched OpenJDK with fontfix:
sudo apt-add-repository -y ppa:no1wantdthisname/openjdk-fontfix
sudo apt-get update
sudo apt-get install openjdk-7-jdk
In $IDEA_HOME/bin/*.vmoptions  add the following: (PS: $IDEA_HOME is the path to IntelliJIdea or Pycharm)
and in ~/.profile  add
export PYCHARM_JDK=/usr/lib/jvm/java-1.7.0-openjdk-amd64"

or whatever the installed java path is.


Start the IDE and enjoy perfect fonts.

Ubuntu - Fix large fonts for Google Chrome in Address Bar and Bookmarks bar

Since version 35, chrome switched to Aura framework and does not follow GTK theme anymore. This leads to large font size in address bar, and bookmarks bar.

However, it grabs font size settings from org.gnome.desktop.interface "font-name" property. To fix this, run the following command:
gsettings set org.gnome.desktop.interface font-name 'Ubuntu 10'
# or
gsettings set org.gnome.desktop.interface font-name 'Ubuntu 11'
# depending on your preferences
You must restart chrome for this to work.

Django `CheckboxSelectMultiple` with `ModelMultipleChoiceField` generates too many queries (solution)

If you use django.forms.ModelMultipleChoiceField with the default widget (django.forms.widgets.SelectMultiple ), all's good.

However, if you need to generate checkboxes for your choices, and use django.forms.widgets.CheckboxSelectMultiple you'll notice that the field will generate alot of queries (one for each element in the queryset), which is really really bad. I personally ended up with hundred of queries.

Fix: add cache_choices=True to your django.forms.ModelMultipleChoiceField


Good practice:
test = forms.ModelMultipleChoiceField(
Bad practice:
test = forms.ModelMultipleChoiceField(

South migrations and MariaDB

If you're working on a Django project along with other members of your team and you're using MariaDB (while the others are using MySQL) you're gonna have a bad time. Everytime you'll run migrations generated on a machine with other database than yours you'll get a strange exception and Google wouldn't give you too many hopes about solving it.

The exception, django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK is caused by leave_transaction_management method in django/db/backends/ and its source seems to be an incompatibility between MariaDB and MySQL (even if the former is just a fork of the other one).

So you want a fix? I couldn't find any, but I fixed this by compiling MySQL from AUR (I'm using Manjaro, which is based on Arch Linux). Even if it's not really a solution maybe you're coming here from Google and maybe this will help you to solve your issue: Arch/Manjaro uses Maria…

Command/Shortcut to Lock Screen with "away message prompt" in Linux Mint 17 / Cinnamon

If you want to have a shortcut with for locking the screen, but with prompt for lock message, here's what you need to do:

Go to Settings -> Keyboard, then click on Keyboard shortcuts tab

Click on Add custom shortcut button, and enter the following command:
python /usr/lib/cinnamon-screensaver-lock-dialog/

Click Add and then assign it a shortcut.
For example, the default lock screen shortcut is Ctrl+Alt+L. For the one with prompt, you can assign Ctrl+L.
You're done.
When you want to lock your screen with a custom "away" message, just press the shortcut you assigned (Ctrl + L)

Install Skype 4.3 in Arch Linux / Manjaro

Hi there,

Skype just released version 4.3 for linux. You can read this article  from OMG Ubuntu! to see what's new in 4.3

Long story short:

native notifications
UI improvements (new toolbar, better login screen, design changes)
floating widget for Call
cloud based Group Chat
support for PulseAudio 3.0 and 4.0

Currently, the AUR "multilib/skype" package is not upgraded to 4.3. If you don't wish to wait, here's what you must do:

Download Skype -> (Choose "Dynamic" from distribution dropdown)
Extract the archive
cd Downloads

tar -xjf skype-4.3.*

Move the contents of the extracted folder to /opt/skype
sudo mkdir /opt/skype

sudo mv skype-4.3.*/* /opt/skype

Edit /usr/bin/skype , and change the exec  command path to exec "/opt/skype/skype" "[email protected]"


if [[ -e "$LIBDIR/libv4l/" ]]; then
export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$LIBDIR/libv4l/v4l2conver…

Sublime slack - preformatted text

Changelog in 1.4.5: Whenever you send a code selection (ctrl+alt+u), it is preformatted.


Django get current user globally in the project

Sometimes, you will need to get the current authenticated user in models, or other parts of your app.

To achieve this, you must create this middleware and add it to MIDDLEWARE_CLASSES in project settings:
from threading import local, current_thread
except ImportError:
from django.utils._threading_local import local

_thread_locals = local()

class GlobalUserMiddleware(object):
Sets the current authenticated user in threading locals

Usage example:
from app_name.middleware import get_current_user
user = get_current_user()
def process_request(self, request):

def process_response(self, request, response):

key = 'user_{0}'.format(current_thread().name)

if not hasattr(_thread_locals, key):
return response

delattr(_thread_locals, key)

return resp…

Invalidate template fragment cache in Django 1.5

Django 1.5 does not have a utility method to delete template fragment cache, with arguments.

In order to achieve this, you must create a custom method:
from django.core.cache import cache
from django.utils.hashcompat import md5_constructor
from django.utils.http import urlquote

def invalidate_template_fragment(fragment_name, *variables):
args = md5_constructor(u':'.join([urlquote(var) for var in variables]))
cache_key = 'template.cache.{0}.{1}'.format(fragment_name, args.hexdigest())

Example usage:
{% cache 259200 key_name %}
... cached content here ...
{% endcache %}

// note that "" is optional argument. You can use as many as you need

... and delete the cache:

In django 1.6+ you can do this more easy:
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key

key = make_template_fragment_key('…

Sublime Slack 1.4.3 Changelog

Fixed some bugs
Implemented avatar support. By default the avatar icon is this :

but you can change it with settings:

"team_tokens": {
"Team 1": "team-1-token-goes-here",
"Team 2": "team-2-token-goes-here",
"username": "ST",
"avatar_url": "",
"show_plaform_and_name": true


Ubuntu 14.04 ctrl+alt+del shutdown dialog

Currently , in Ubuntu 14.04 if you press Ctrl+Alt+Del, it pops out the logout or lock dialog.
Many of us were used to have the shutdown/restart dialog prompted on Ctrl+Alt+Del.

Here's how you get the shutdown dialog:

open System Settings -> Keyboard, click on the second tab "Shortcuts",  and then click on the "+" icon to add a new shortcut.

Give it a name (ex: "Shutdown dialog") and in the command field enter gnome-session-quit --reboot .

After creating the shortcut, you need to assign it a keybind. Click on "Disabled" in the right side of the shortcut, then press "Ctrl+Alt+Del". A conflict dialog will show up. Click on "Reassign".

Now, when pressing Ctrl + Alt + Del, you will have this dialog shown:

Alternatively, you want to have all the "quit" options in one dialog (lock, suspend, restart, shutdown) you can replace the command with gnome-session-quit --power-off  and get this result:

Wine - Diablo 3 via launcher error on Ubuntu 14.04

This error occurs on ubuntu 14.04 when trying to run Diablo III from launcher:
Wine - Diablo 3 via launcher error: Please try again after logging on as an administrator

To avoid this error, you must launch Diablo 3 using the following command:
setarch i386 -3 -L -B -R wine '/path/to/Diablo III.exe' -launch -opengl
Alternatively, if you want to create a shortcut, run:
sudo gedit /usr/share/applications/diablo.desktop
and paste the following content (don't forget to update the path to diablo .exe file, and the icon file)
[Desktop Entry]
Name=Diablo III
Comment=Run Blizzard Diablo III via Wine
Exec=setarch i386 -3 -L -B -R wine '/path/to/Diablo III.exe' -launch -opengl
You can download the icon file here: , save it somewhere and point the location in diablo.desktop file created previously.

Fix ugly Skype theme on Ubuntu 14.04

Because Skype is a 32bit app and the GTK theme engine is not installed by default for 32bit, skype uses Clearlooks theme instead of the ubuntu's gtk Ambiance theme.

To fix this, install the following:
sudo apt-get install gtk2-engines-murrine:i386 gtk2-engines-pixbuf:i386

[caption id="attachment_293" align="alignnone" width="620"] Before fixing skype[/caption]


[caption id="attachment_292" align="alignnone" width="620"] After[/caption]

Ubuntu 14.04 installing external .deb fails "Package operation Failed"

For some reason, installing external .deb files from ubuntu software center fails. The bug is reported on launchpad.

It doesn't really matter why it is not working, because the Ubuntu Software Center itself is slow and heavy.

The workaround given on launchpas is to use "dpkg -i <file.deb>" but the issue with this is that it does not resolve dependencies.

My recommendation is to use "Gdebi" as an alternative. It's extremly fast and lightweight, and it comes with a command line tool, and a GUI tool.

Once you install Gdebi (sudo apt-get install gdebi ), edit the default applications file:
sudo gedit /usr/share/gnome/applications/defaults.list
find the following lines:
and replace with

Ubuntu 14.04 lock screen asking password twice

So, everyone loves the new Ubuntu 14.04 lock screen, which looks exactly as the login screen.

But there is an issue with it. If you lock your screen manually (Ctrl + Alt + L) and leave your computer a couple of minutes (untill it locks the screen automatically), when you unlock it, it will ask for your password twice.

Workaround: Go to Settings -> Brightness and Lock -> Lock [OFF] (switch it to off).

Sublime Slack 1.4.0 released


1. File upload

current open file
right click in sidebar, on file
enter file path manually


2. API errors (example: 'invalid_auth') are sent to user with an alert.

Sublime Slack 1.3.3 bugfixes

Fixed some critical bugs:

after selecting a receiver from dropdown, sublime does not freeze anymore. Instead, it shows a loader in the status bar while sending the message.
fixed multiple teams name duplicate.

Please update by running "Package Control: Upgrade/Overwrite Packages"


Sublime Slack 1.3.2 changelog


When sending messages from input, the message can begin with @user, #channel or .group to skip channel/user/group selection
 New message from input will have autofilled the last @user #channel or .group used (for quick chatting, if you want to keep replying from sublime while you see received messages in chrome notifications)
Added some fancy loaders when grabbing data from api (channels/groups/users) and when sending message


Sublime Slack 1.3 released


support multiple tokens (teams)
send private messages to users
send messages to groups (private channels)

To update your plugin instantly, run "Package Control: Upgrade/Override all packages".


Manually generate Django password reset token

Ever needed to manually generate a password reset token?

For example, imagine this situation:
You create a user from a custom form, and you want the user to set his own password.
Solution: generate a password reset token,  email him the link, and let him choose his own password.

Here's how you implement this:
from django.contrib.auth.tokens import default_token_generator
from django.utils.http import urlsafe_base64_encode
from django.utils.encoding import force_bytes

from django.db.models.signals import post_save
post_save.connect(user_saved, User)
def user_saved(sender, instance, created, *args, **kwargs):
if created:
context = {
'token': default_token_generator.make_token(instance),
'uid': urlsafe_base64_encode(force_bytes(,
'user': instance,
# here, send an email with this context
To display the link in the email, you must set the password reset url, and display it:
{% url 'password_reset_co…

Deploy with fabric on multiple servers

Ever needed to deploy with fabric on multiple machines?
Here's a simple solution to aproach this issue.

In your , add these two methods:
def live():
env.hosts = [""]
env.user = 'test'
PATH = '/path/to/project'
# optional, is using virtualenv
ENV_PATH = '/path/to/virtualenv'
# overwrite whatever variabled you need to change on the current machine

def staging():
env.hosts = [""]
env.user = 'test2'
PATH = '/path/to/project/on/second/machine'
# optional, is using virtualenv
ENV_PATH = '/path/to/virtualenv'
# overwrite whatever variabled you need to change on the current machine
Now, when deploying, for example:
def deploy():
with cd(PATH), virtualenv(ENV_PATH):
run('uber command')
run('another uber command')
you must use the following commands, in the correct order:
#deploy on st…

jqPlot resize bar charts

To make a jqPlot bar chart resizeable, you need to do this:
$(window).on('resize', function () {
$.each(chart.series, function(index, series) {
series.barWidth = undefined;
where "chart" is the object returned by $.plot when initializing the plot.

Top things to do after installing Manjaro KDE

In this article I'll explain what you should to after installing Manjaro Linux with KDE  (current version 0.8.8)
Overview on my desktop
So, here's my current Manjaro KDE desktop look:

Here are the most important things I've done after installing Manjaro linux:
First thing, and the most important, was to fix fonts. Default KDE fonts aren't that pretty, so I've installed "infinality fonts" and cairo ubuntu.

Here's my current font configuration:

Ubuntu - resize window with alt-right click

To enable this functionality in ubuntu, install gconf-editor:
sudo apt-get install gconf-editor
run it, and navigate to apps/metacity/general and enable "resize_with_right_button"  key.

In Ubuntu 14.04
sudo apt-get install compizconfig-settings-manager
Click Window Management and Resize Window.

Set the key to "<Alt>Button3"

For Linux Mint (version now: 17):
gsettings set org.cinnamon.desktop.wm.preferences resize-with-right-button true

Pip PIL error: Could not find any downloads that satisfy the requirement PIL

When installing "PIL" with pip, I got this error:
Downloading/unpacking PIL
Could not find any downloads that satisfy the requirement PIL
 Fix: use "Pillow" instead of "PIL". Make sure you uninstall PIL first.
pip uninstall PIL
pip install Pillow

Slow SSH login on Ubuntu

I have recently experienced a slow ssh login issue on ubuntu 13.10 (xubuntu actually).
Tried all kind of solutions from internet, nothing worked, except this:

Edit the following file:
sudo nano /etc/nsswitch.conf
Find the following line:

hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4

replace with

hosts: files dns
VoilĂ !
Ssh authentication working like a charm!

Compare integer variable in django templates

Ever needed to compare some variable (that may come from db, forms, etc) in django templates with an integer?
{% if some_var == 3 %}
{% endif %}
The above example will not work. Django's template engine interprets the variable as a string.

Workaround for integer comparison:
{% if some_var|add:0 == 3 %}
{% endif %}
By using the "add" filter, the variable is transformed into an integer.