8. May 2013

Vim mode in Cloud9 IDE

Cloud9 IDE is cloud base IDE for NodeJS, Python, Ruby or PHP projects.

The cool thing about this IDE is that code editor has support for Vim mode (it also supports Emacs) :)

vim-cloud9

Go to View, Keyboard Mode and select Vim.

Voila you can use many Vim features, like indentation by >> or many others.

Here is offical video from Cloud9 Youtube channel:

4. February 2013

Useful Django package: django-debug-toolbar

django-debug-toolbar is simply must have tool for Django development.

It adds powerfull toolbar which allows detailed diagnostic and debugging of Django site.

django-debug-toolbarQuick install:

pip install django-debug-toolbar

Open settings.py and add:

MIDDLEWARE_CLASSES = (
    # ...
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    # ...
)
INTERNAL_IPS = ('127.0.0.1',)
INSTALLED_APPS = (
    ...
    'debug_toolbar',
)

Make sure that DEBUG is set to True

DEBUG = True

29. September 2012

Plone upgrade – Clear and Rebuild failed

Plone is not working very well when portal_catalog is not up-to-date. This happens after upgrades. It is recommended to go to portal_catalog, section Advanced and run: Clear and Rebuild.

I did this, but after few seconds I’ve got this fancy error:

Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module Products.CMFPlone.CatalogTool, line 460, in manage_catalogRebuild
Module plone.app.discussion.patches, line 45, in patchedClearFindAndRebuild
Module Products.ZCatalog.ZCatalog, line 287, in manage_catalogClear
Module Products.ZCatalog.Catalog, line 102, in clear

If you dig deep down into ZCatalog code, then you’ll see that some objects in DB simply don’t have clear method. Those objects are typically some ancient instances of TextIndex or instance of some long dead product.

Solution is to catch this error and remove those old grumpy objects from DB. Here is small patch:
eggs/Products.ZCatalog-2.13.23-py2.7.egg/Products/ZCatalog/Catalog.py:

    def clear(self):
        """ clear catalog """

        self.data = IOBTree()  # mapping of rid to meta_data
        self.uids = OIBTree()  # mapping of uid to rid
        self.paths = IOBTree()  # mapping of rid to uid
        self._length = BTrees.Length.Length()
        to_delete = []

        for index in self.indexes.keys():
            try:
                self.getIndex(index).clear()
            except:
                LOG.error('unclearable object %s. ' % str(index))
                to_delete.append(index)

        for del_index in to_delete:
            LOG.error('Removing from index %s. ' % str(del_index))
            del self.indexes[del_index]

Remove eggs/Products.ZCatalog-2.13.23-py2.7.egg/Products/ZCatalog/Catalog.pyc file to avoid caching. Start the Plone and run Clear and Rebuild function. Watch log file also for error messages from ZCatalog.

29. September 2012

Plone buildout problem – We already have zc.buildout

If you want to upgrade Plone just with buildout, then you may find following funny error:

 Installing.
 Loading extensions.
 Error: There is a version conflict.
 We already have: zc.buildout 1.5.2

Typical cause of this problem is that your bin/buildout is out of date. Solution is simple. Remove bin directory. Download latest version of bootstrap.py and let it generate new version of bin/buildout for you. Run biuldout again :)

wget http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py
python bootstrap.py
./bin/buildout

26. August 2012

WebExpo Startup Camp – summer 2012 – materials

I’m glad that I had opportunity to join Startup Camp in Trhový Štěpánov as mentor. Together with startup teams we were discussing and preparing new sites for their products. People were learning how to use Git, how to program in Python and how to create sites in Django. At the end of the day they were able to create prototype or deploy it to Heroku cloud.

Yyou can find my slides at SlideShare or download it as PDF.

Examples of Python code and simple Django testing project are available at GitHub in repository try_git.

Read more about WebExpo Startup camp.

23. August 2012

IntelliJ Idea – How to enable zoom of text by CTRL + Mouse wheel

You can zoom-in or out text in editor window of IntelliJ idea (PyCharm) by CTRL + Mouse wheel.

The only problem is that this feature is disabled by default. You have to turn it on.

Press CTRL + Alt + S (Settings) and type: “change font size” into text search field. Select: Editor and check option “Change font size (Zoom) with Ctrl+Mouse Wheel”

20. August 2012

Problems with deploying Heroku Django app from Windows

Deploying Django app to Heroku from Windows machine is little bit tricky.

You can follow instructions in Heroku manual. The first problem that you may encounter is with Postgres support in Python. There is problem with this command:

pip install Django psycopg2 dj-database-url

If you do not have Visual Studio installed on your machine, you’ll receive error that vcvarsall.bat is missing.

Solution is quite easy. You don’t need to install Visaul Studio. Just download binary version of psycopg2 module from http://www.stickpeople.com/projects/python/win-psycopg/

Then you can exclude psycopg2 from pip install command, because it is installed in system directory of Python.

Another tricky issue is with command:

pip freeze >requirements.txt

If you type this command in PowerShell then it will automatically create Unicode file with extra bytes. When you try to deploy project with messed requirements.txt to Herou then you’ll see self explanatory error ;-)

TypeError: must be encoded string without NULL bytes, not str

Nice :-)

Just open requirements.txt file with notepad and select Save as. In Save as dialog choose ANSI.

Commit file and push project to Heroku. It will work ;)

6. December 2011

Fine tune three.js export from Blender

Three.js exporter for new version of Blender 2.60 supports many features. The problem is that default exporter settings generates quite big JSON file even for small models.

Here is list of defaut options for save model function from export_threejs.js:

         filepath = "",
         option_flip_yz = True,
         option_vertices = True,
         option_vertices_truncate = False,
         option_faces = True,
         option_normals = True,
         option_uv_coords = True,
         option_materials = True,
         option_colors = True,
         align_model = 0,
         option_export_scene = False,
         option_lights = False,
         option_cameras = False,
         option_scale = 1.0,
         option_embed_meshes = True,
         option_url_base_html = False,
         option_copy_textures = False,
         option_animation = False,
         option_frame_step = 1,
         option_all_meshes = True

These are good settings when you want to save all objects from scene. It is quite overkill when you need to save just one dynamically generated object. I recommend to turn off following options:

option_all_meshes, option_materials

Here is sample code in Python which will select object by name and save it to file with defined options:

import bpy

bpy.ops.object.select_name(name="ObjectName")
bpy.ops.export.threejs(filepath="ObjectName.js", option_all_meshes=False, option_materials=False)

Further articles about Blender and Python are located under the tag Blender on my blog.

Enjoy :)

8. August 2011

Which programming language is the most popular?

Do you wonder whether your favorite language is the most popular?

Tiobe Programming Community Index could give you some hints about it.

Here is small sample:

You can find more details about other languages also at Tiobe.com.

27. June 2011

Quick start: Blender and Python

If you know right tricks then writing scripts for Blender is quite easy.

Here is video tutorial that explains some of those tricks. Enjoy.

  • Babel fish

      Translate from:

      Translate to:

  • Where’s the fish?

  • Further info

  • Twitter

    Follow @jurajmichalek on twitter.

  • Badges

  • Learning

    lynda.com online training tutorials
  • Tags

  • Topics

  • Comments