Category Archives: Programming

Good Book About Javascript

I’ve have been working with Javascript here and there – always small pieces –  as I know Java, C, Python I though that I do not need to learn anything special about Javascript, that I should be able to manage right away – In fact I somehow did, but I’ve been always bit struggling with some strange behaviours.   Having to write couple of Firefox add-ons recently I decided to read some book about Javascript to shed a light on those anomalies  –   I found this book very good – Javascript: The Good Parts by Douglas Crockford.

It relatively small book – I’ve read it in a few hours, but it gives you very good overview of all features of the language and show you how to write good and maintainable code in JS.   Now I know that Javascript is very expressive language, where I can use some powerful features like functional programming, prototypes etc.

Writing to file in Firefox Extension

Mozilla has provided nice high level API in its Add-On SDK, where one can relatively easily write an extension, without need for any special knowledge about internals of Firefox – the general knowledge of Javascript, HTML and CSS plus very nice and detailed documentation of the SDK are basically enough.

However there are some functionalities, that are not available in SDK and then more effort is needed and  XPCOM components have to be used via their JS interfaces.  This requires bit more  research, so I’d like to share one useful snippet of code  – how to save string to file, which user has chosen via standard file picker dialogue: Continue reading Writing to file in Firefox Extension

GSettings – Flexible Configuration System

GSetttings is the standard way how Gnome 3 applications store their configuration. GSettings is the front-end interface for application, actual values are stored by back-end – standard one is called dconf. We can then use the tool dconf-editor to easily browse all stored configurations for all applications. Thanks to GObject introspection we can also work easily with GSettings from python. Continue reading GSettings – Flexible Configuration System

LOB As A Link in Apex

APEX 4.1 enables to include a download link to LOB object in standard or interactive repors.   Documentation is available  here, however the approach is not so obvious from it.  So here is quick recap, how it works:

  1. In report query you must have column that contains LOB length  (not LOB itself!) –  so something like select dbms_lob.getlength(MY_LOB) my_lob_lenght from MY_TABLE
  2. The report column corresponding to LOB length should be set as:
    Display As: Display As Text (escape special characters, does not save state)
    Number/Date Format: DOWNLOAD:TABLE_NAME:LOB_COLUMN_NAME:ROW_PRIMARY_KEY_COLUMN
    (beware names are case sensitive here)
  3. When more sophisticated download behaviour is needed you should also include  columns for MIME type of data, file name and modification timestamp.   Once you store basic DOWNLOAD format you can edit it with masked edit link “BLOB Download Format Mask”
  4. Download link is only shown when LOB length > 0 and is not null.

Continue reading LOB As A Link in Apex

Coverting Ebooks with Multiple Processes

Recently I’ve been converting a batch of ebooks into epub and mobi formats.  I used python tools, parts of my project MyBookShelf, which uses calibre and LibreOffice for all the hard work.   The conversion tool enables to run several conversion in parallel – in separate processes.  I wondered how the conversion will speed up with adding more processes.   I ran it  on my notebook with core i5 processor – two physical cores, each core can run two physical threads, 8GB memory. Graph below shows results for conversion of about 10 books into both formats.

Interesting thing for me is that only notable speed up is between 1 and 2 processes.   Not very much gain with running 3 or 4 –  looks like full utilization of HW threads is held back by I/O or memory speed limits?

Removing Diacritics Marks from Strings

Many Latin alphabets (like my native Czech) contain characters with diacritical marks (or can be called accent marks). For some application in computers (like searching, cross systems compatible file names etc.) we would like to remove diacritics and translate  to string containing just ASCII  characters.   Common approach for this is to use UNICODE character decomposition.

It utilizes fact, that unicode has two ways how to represent characters with diacritics – for instance character á (LATIN SMALL LETTER A WITH ACUTE) normaly has code 225,  but this character can be decomposed into two unicode characters   code 97 (LATIN SMALL LETTER A) and character code 769 (COMBINING ACUTE ACCENT).   This process will work for majority of common ‘special’ Latin characters, however there are still few left, for which unicode does not have decomposition defined – these include characters like ø  (LATIN SMALL LETTER O WITH STROKE)  used in Norwegian language or ł (LATIN SMALL LETTER L WITH STROKE) used in Polish language.  A special handling is needed for these characters – basically a transcription table to map these into some basic Latin characters (it could be 1 to many mapping – for instance æ (LATIN SMALL LETTER AE) should map to ‘ae’).

Characters decomposition is defined in unicode standard and all common computer languages contains libraries which contain unicode definitions and can decompose characters.  Below Ishow how this can be done in python. Continue reading Removing Diacritics Marks from Strings

APEX – Dynamic Actions with Report Region

In many scenarios it would be nice if we can provide some dynamic actions to report (classical) region, which can be handled via Ajax calls, rather then submitting a whole page  – these actions could include:

Quick Way to Debug Objects in Python

Often it is necessary to print an object to debugging log. This small utility function can help to print all  properties:

 

Well Behaving APEX Item Plugin

I ‘ve recently created  multiselect plugin for APEX 4.1 –  there is still little information about how exactly write APEX plugins,  and some aspects – like cascading LOV, I have not found explained anywhere, so I’d like to share my experiences here:

What You Need

To write plugin you will need:

  • Oracle Database and APEX running somewhere –   the installation manual for APEX is very good and you can go step by step  according to it
  • Knowledge of  PL/SQL – it is good to have PL/SQL Reference at your hand
  • Reference documentation for APEX 4.1 API
  • Some knowledge of APEX and also some basic knowledge of plugins – try some available tutorials you can find on web – this article will focus on rather specific issues within Item plugin.
  • Oracle SQL/Developer (or other development tool)- to write PL/SQL  – optional, if you are PL/SQL god and can write correct code by heart – if you struggling with PL/SQL like me this is an invaluable helper.
  • Web server running on your local machine – to help to develop  Javascript part of plugin
  • Firefox with Firebug – to debug Javascript (or Chrome, if you prefer) Continue reading Well Behaving APEX Item Plugin

Having 3D fun with Visual Python

Visual Python or vpython is python library for simple 3D animation, especially useful for animation of  simple physical scenes – like pendulum, ball on a spring, movement in gravitational field etc.  It is fairly simple to use and gives quite nice animations, which can demonstrate some  laws of physics.  I actually spot this package, when I saw an article about physics in popular mobile game “Angry Birds – Space”. In that article they had been arguing about physics laws in the game and also referred to  vpython, where they made some experiments. I told myself I have to try it myself, so I’ve created small program using vpython. Continue reading Having 3D fun with Visual Python