A reminder to myself » simion http://simionbaws.ro Stuff I might need later. Mon, 06 Jul 2015 13:25:52 +0000 en-US hourly 1 http://wordpress.org/?v=4.3.1 OSX Disk Utility Erasing/Formatting stuck at “Unmounting disk …”, “Couldn’t unmount disk” http://simionbaws.ro/osx/osx-disk-utility-erasingformatting-stuck-at-unmounting-disk-couldnt-unmount-disk/ http://simionbaws.ro/osx/osx-disk-utility-erasingformatting-stuck-at-unmounting-disk-couldnt-unmount-disk/#comments Mon, 15 Jun 2015 07:23:08 +0000 http://simionbaws.ro/?p=466 If you are trying to format/erase a disk and disk utility/diskUtil is stuck at “unmounting disk”, probably “fsck_hfs” is stuck in a loop, trying to repair it before mounting.

couldnt-unmount-disk-disk-utility-error

I’ve seen solutions where you must boot from an external operating system, bla blah. Too complicated and time consuming.

To fix this fast and easy, start formatting, wait for “unmounting disk” message to appear, then go to Terminal, find the process with the following command

ps ax | grep fsck_hfs

You’ll get something like

simion@Simions-MacBook-Pro:~$ ps ax | grep fsck_hfs
 3693   ??  U      1:32.61 /System/Library/Filesystems/hfs.fs/Contents/Resources/./fsck_hfs -y /dev/disk2s2
 3984 s000  S+     0:00.00 grep fsck_hfs

Then … kill the process with

sudo kill 3693

Then it should continue automatically with formatting the drive.

Note that you must do this before disk utility gives the error message “Could not unmount disk”.

]]>
http://simionbaws.ro/osx/osx-disk-utility-erasingformatting-stuck-at-unmounting-disk-couldnt-unmount-disk/feed/ 0
Aplicatia Bancomate pentru Android (În curand și pe IOS) http://simionbaws.ro/stories/aplicatia-bancomate-pentru-android/ http://simionbaws.ro/stories/aplicatia-bancomate-pentru-android/#comments Sun, 08 Mar 2015 01:45:41 +0000 http://simionbaws.ro/?p=441 final

Această aplicație vă ajută să gasiți ușor și rapid bănci și bancomate (atm-uri) în toată România.

Important: momentan lucrează doar cu anumite bănci, pentru a asigura corectitudinea datelor. Baza de date este în continuă dezvoltare, si vom adăuga bănci noi în perioada ce urmează.

Specificații:
– Afișeaza cele mai apropiate bancomate și bănci din locația dumneavoastră, sau in orice alt punct pe hartă
– Locațiile bancomatelor sunt actualizate zilnic, din surse oficiale, in mod automat (dacă apar bancomate noi, sau se desființeaza bancomate vechi, noi vom ști primii)
– Opțiune de navigare catre un bancomat ales
– Opțiune de căutare adresă / locație
– În cazul băncilor (sucursalelor) este afișat și un număr de telefon
– Filtru în funcție de banca aleasă
– Acoperire in toata Romania
– Pentru eficiența transferului de date/baterie, sunt afișate cele mai apropiate 30 bancomate/sucursale din locația curentă sau locația aleasă de dumneavostră, calculele fiind efectuate pe server.

Ce deosebește această aplicatie față de celelalte aplicații din acest domeniu?
Contine doar acele bancomate ale căror coordonate pe hartă sunt obtinute din surse oficiale (banci). Bancile care nu oferă coordonate exacte ale bancomatelor nu sunt implementate momentan (geocodarea adresei ar putea fi imprecisă, acest subiect va fi tratat în următoarea versiune). Deci cu noi mergeți la sigur!
În plus, baza de date este actualizata zilnic, in mod automat, pentru fiecare bancă în parte.

Băncile implementate în momentul de față (coordonate din surse oficiale):
– Banca Transilvania
– Raifeissen Bank
– BRD groupe societe generale
– ING Romania
– Bancpost
– Alpha Bank
– Euronet (Banca Carpatica)
– OPT Bank
– Unicredit Tiriac Bank
– Piraeus Bank
– Banca Romanească
În acest moment exista peste 6000 de bancomate în baza de date, pentru aceste bănci.
Bănci ce vor fi implementate (prin geocodarea adresei) în perioada ce urmează:
– BCR – Banca Comerciala Romana (80% finalizat)
– Garanti Bank
– BCR
– CEC Bank
– CreditEurope Bank
– Libra Bank
– Pro Credit Bank
– Leumi Bank
– Millenium Bank
– Marfin Bank

 

get-it-on-google-play-store-logo

Screenshot_2015-03-24-01-17-56 Screenshot_2015-03-24-01-18-12 Screenshot_2015-03-24-01-18-30 Screenshot_2015-03-24-01-18-35 Screenshot_2015-03-24-01-18-51 Screenshot_2015-03-24-01-18-56 Screenshot_2015-03-24-01-20-04 Screenshot_2015-03-24-01-21-39

 

Aplicatia Bancomate pentru Android

Google+
]]>
http://simionbaws.ro/stories/aplicatia-bancomate-pentru-android/feed/ 0
Improve font rendering for IntelliJ IDEA / Pycharm in Ubuntu http://simionbaws.ro/linux/improve-font-rendering-for-intellij-idea-pycharm-in-ubuntu/ http://simionbaws.ro/linux/improve-font-rendering-for-intellij-idea-pycharm-in-ubuntu/#comments Wed, 26 Nov 2014 15:25:02 +0000 http://simionbaws.ro/?p=409 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/infctl.sh setstyle linux
sudo gedit /etc/profile.d/infinality-settings.sh
# and set
USE_STYLE="UBUNTU"

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)

-Dawt.useSystemAAFontSettings=lcd
-Dswing.aatext=true
-Dsun.java2d.xrender=true

and in 

~/.profile
  add

export PYCHARM_JDK=/usr/lib/jvm/java-1.7.0-openjdk-amd64"

 

or whatever the installed java path is.

Reboot.

Start the IDE and enjoy perfect fonts.

Google+
]]>
http://simionbaws.ro/linux/improve-font-rendering-for-intellij-idea-pycharm-in-ubuntu/feed/ 7
Ubuntu – Fix large fonts for Google Chrome in Address Bar and Bookmarks bar http://simionbaws.ro/linux/ubuntu-fix-large-fonts-for-google-chrome-in-address-bar-and-bookmarks-bar/ http://simionbaws.ro/linux/ubuntu-fix-large-fonts-for-google-chrome-in-address-bar-and-bookmarks-bar/#comments Mon, 24 Nov 2014 08:32:56 +0000 http://simionbaws.ro/?p=404 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.

Google+
]]>
http://simionbaws.ro/linux/ubuntu-fix-large-fonts-for-google-chrome-in-address-bar-and-bookmarks-bar/feed/ 0
Django `CheckboxSelectMultiple` with `ModelMultipleChoiceField` generates too many queries (solution) http://simionbaws.ro/programming/django-checkboxselectmultiple-with-modelmultiplechoicefield-generates-too-many-queries/ http://simionbaws.ro/programming/django-checkboxselectmultiple-with-modelmultiplechoicefield-generates-too-many-queries/#comments Sat, 13 Sep 2014 11:57:18 +0000 http://simionbaws.ro/?p=388 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

Example:

Good practice:

test = forms.ModelMultipleChoiceField(
        queryset=MyModel.objects.all(),
        cache_choices=True,
        widget=forms.CheckboxSelectMultiple)

Bad practice:

test = forms.ModelMultipleChoiceField(
        queryset=MyModel.objects.all(),
        widget=forms.CheckboxSelectMultiple)

django-logo-negative

Google+
]]>
http://simionbaws.ro/programming/django-checkboxselectmultiple-with-modelmultiplechoicefield-generates-too-many-queries/feed/ 0
Command/Shortcut to Lock Screen with “away message prompt” in Linux Mint 17 / Cinnamon http://simionbaws.ro/linux/commandshortcut-to-lock-screen-with-away-message-prompt-in-linux-mint-17-cinnamon/ http://simionbaws.ro/linux/commandshortcut-to-lock-screen-with-away-message-prompt-in-linux-mint-17-cinnamon/#comments Tue, 24 Jun 2014 09:50:09 +0000 http://simionbaws.ro/?p=371 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:

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

  2. Click on Add custom shortcut button, and enter the following command:

    python /usr/lib/cinnamon-screensaver-lock-dialog/cinnamon-screensaver-lock-dialog.py

    example:
    Screenshot from 2014-06-24 12:41:27

  3. 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.
  4. You’re done.
    When you want to lock your screen with a custom “away” message, just press the shortcut you assigned (Ctrl + L)

Screenshot from 2014-06-24 12:47:44

Google+
]]>
http://simionbaws.ro/linux/commandshortcut-to-lock-screen-with-away-message-prompt-in-linux-mint-17-cinnamon/feed/ 0
Install Skype 4.3 in Arch Linux / Manjaro http://simionbaws.ro/linux/install-skype-4-3-in-arch-linux-manjaro/ http://simionbaws.ro/linux/install-skype-4-3-in-arch-linux-manjaro/#comments Wed, 18 Jun 2014 21:46:56 +0000 http://simionbaws.ro/?p=356 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:

  1. Download Skype -> http://www.skype.com/go/linux (Choose “Dynamic” from distribution dropdown)
  2. Extract the archive
    cd Downloads
    
    tar -xjf skype-4.3.*
  3. Move the contents of the extracted folder to /opt/skype
    sudo mkdir /opt/skype
    
    sudo mv skype-4.3.*/* /opt/skype
  4. Edit
    /usr/bin/skype
     , and change the
    exec
      command path to
    exec "/opt/skype/skype" "$@"
     

    #!/bin/bash
    
    LIBDIR="/usr/lib32"
    
    if [[ -e "$LIBDIR/libv4l/v4l2convert.so" ]]; then
            export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}$LIBDIR/libv4l/v4l2convert.so"
    fi
    
    if [[ -e "/usr/share/skype/lib/libQtWebKit.so.4" ]]; then
            export LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}/usr/share/skype/lib/libQtWebKit.so.4"
    fi
    
    # exec "$LIBDIR/skype/skype" "$@"  # (old one)
    exec "/opt/skype/skype" "$@"

Google+
]]>
http://simionbaws.ro/linux/install-skype-4-3-in-arch-linux-manjaro/feed/ 4
Sublime slack – preformatted text http://simionbaws.ro/sublime-slack/sublime-slack-preformatted-text/ http://simionbaws.ro/sublime-slack/sublime-slack-preformatted-text/#comments Mon, 09 Jun 2014 19:24:37 +0000 http://simionbaws.ro/?p=350 Changelog in 1.4.5: Whenever you send a code selection (ctrl+alt+u), it is preformatted.

Example:

Screenshot from 2014-06-09 22:12:21

Google+
]]>
http://simionbaws.ro/sublime-slack/sublime-slack-preformatted-text/feed/ 0
Django get current user globally in the project http://simionbaws.ro/programming/python-programming/django-python-programming/django-get-current-user-globally-in-the-project/ http://simionbaws.ro/programming/python-programming/django-python-programming/django-get-current-user-globally-in-the-project/#comments Fri, 23 May 2014 08:00:56 +0000 http://simionbaws.ro/?p=340 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:

try:
    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):
        setattr(
            _thread_locals,
            'user_{0}'.format(current_thread().name),
            request.user)

    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 response


def get_current_user():
    return getattr(
        _thread_locals,
        'user_{0}'.format(current_thread().name),
        None)

Usage example:

from myapp.middleware import get_current_user

user = get_current_user()

Google+
]]>
http://simionbaws.ro/programming/python-programming/django-python-programming/django-get-current-user-globally-in-the-project/feed/ 0
Invalidate template fragment cache in Django 1.5 http://simionbaws.ro/programming/python-programming/invalidate-template-fragment-cache-in-django-1-5/ http://simionbaws.ro/programming/python-programming/invalidate-template-fragment-cache-in-django-1-5/#comments Wed, 21 May 2014 13:23:23 +0000 http://simionbaws.ro/?p=335 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())
    cache.delete(cache_key)

Example usage:

{% cache 259200 key_name model_instance.pk %}
    ... cached content here ...
{% endcache %}

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

… and delete the cache:

invalidate_template_fragment('key_name', model_instance.pk)

 

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('key_name', [model_instance.pk])
cache.delete(key)

Google+
]]>
http://simionbaws.ro/programming/python-programming/invalidate-template-fragment-cache-in-django-1-5/feed/ 0