Autarchy of the Private Cave

Science, Society, Programming and Hobbies

  • Exits

  • Categories

  • Archives

  • Visitors' track

    Locations of visitors to this page
  • Tags list

    • Web Hosting

    • Blog sponsors

    • Earn and spend


    • Exits

    • Ratings

      Science Blogs - Blog Top Sites website monitoring service

    Archive for the 'Programming' Category


    GNAT GPL 2008 is now available

    12th June 2008

    We are pleased to announce the release of GNAT GPL 2008, the Ada Toolset for Academic users and FLOSS developers.

    It introduces hundreds of enhancements including:

    • Availability on the Windows .NET platform
    • Upgrade of the debugging engine
    • Improvement in robustness and efficiency for Ada 2005 features
    • Many new warnings & restrictions to help programmers detect errors earlier
    • Companion tools such as gprof, gcov, gnatcheck, gnatpp and gnatmetric are being enhanced to support a wider variety of needs, coding styles, and coding standards
    • Support for Pre/Post conditions

    GNAT GPL 2008 comes with version 4.2.1 of the GNAT Programming Studio IDE and GNATbench 2.1, the GNAT plug-in for Eclipse.

    It is available on the GNU Linux (32 and 64 bit), .NET, and Windows platforms.

    GNAT GPL 2008 can be downloaded from the “Download GNAT GPL Edition” section on https://libre.adacore.com/

    Share This

    Posted in Ada, Programming | No Comments »

    GNAT GPL 2008 is now available

    12th June 2008

    We are pleased to announce the release of GNAT GPL 2008, the Ada Toolset for Academic users and FLOSS developers.

    It introduces hundreds of enhancements including:

    • Availability on the Windows .NET platform
    • Upgrade of the debugging engine
    • Improvement in robustness and efficiency for Ada 2005 features
    • Many new warnings & restrictions to help programmers detect errors earlier
    • Companion tools such as gprof, gcov, gnatcheck, gnatpp and gnatmetric are being enhanced to support a wider variety of needs, coding styles, and coding standards
    • Support for Pre/Post conditions

    GNAT GPL 2008 comes with version 4.2.1 of the GNAT Programming Studio IDE and GNATbench 2.1, the GNAT plug-in for Eclipse.

    It is available on the GNU Linux (32 and 64 bit), .NET, and Windows platforms.

    GNAT GPL 2008 can be downloaded from the “Download GNAT GPL Edition” section on https://libre.adacore.com/

    Share This

    Posted in Ada, Programming | No Comments »

    Drupal theme development: where to start

    8th June 2008

    Simplest way to develop your custom Drupal theme is to start with some skeleton/wireframe theme.

    In this post, I’m briefly reviewing 4 themes (atck, blueprint, framework, and zen), made specifically to serve as theme developer’s starting point. All 4 are listed with their features (as per Drupal project page of each one), with my personal “impressions” (not based on actual use experience, yet). There’s also my choice and order of preference for the 4 candidates at the end.
    Read the rest of this entry »

    Share This

    Posted in Drupal, Links, Notepad, Software, Web, XHTML/CSS | 5 Comments »

    Ad Unit Guidelines

    7th June 2008

    When either consulting on a new website design, or actually designing one, keep in mind Ad Unit Guidelines if the website is going to use advertising. The list is far not exhaustive, but sufficiently standard.

    Share This

    Posted in Links, Notepad, Web, XHTML/CSS | No Comments »

    Developing reluctant (pessimal) algorithms

    13th April 2008

    If you had some programming experience - read it here. Otherwise ignore, it’s targeted for a narrow group.

    Share This

    Posted in Humour, Links, Programming | No Comments »

    Instructions on installing libmp3lame-enabled ffmpeg on shared linux hosting

    12th March 2008

    Note: this post is based on the comment by Simon, who generously shared his experience.

    Step-by-step:

    • Download the compiled ffmpeg with libmp3lame support (direct download links: older version ffmpeg.with.lame and newer version ffmpeg.2007-10-28.with-libmp3lame-support).
    • Rename the downloaded executable file to "ffmpeg" (no extension), upload it to the directory on your server (in this example /home/myusername/).
    • Download libmp3lame.so.0.
    • Upload libmp3lame.so.0 to the same directory where you placed ffmpeg in.
    • Create a php file with the following code (remember to change the paths to your own, where you actually uploaded binaries in previous steps):
      PHP:
      1. <?php
      2. exec("export LD_LIBRARY_PATH=/home/myusername/");
      3. echo passthru("/home/myusername/ffmpeg -formats");
      4. ?>

    • If you access that PHP file with your browser, you should be able to see a list of formats which are supported by ffmpeg, and if you find "EA libmp3lame" somewhere in the output, then it means you now can Encode Audio in libmp3lame!
    • If that doesn't work for you: LD_LIBRARY_PATH can be a protected variable in PHP (you can check for this by searching for the "safe_mode_protected_env_vars" value in phpinfo() output). The workaround here can be to write your commands to a file from php, then chmod that file with 0775 permissions (rwx-rx-rx), and run the file through exec(). In this way, PHP is not changing the LD_LIBRARY_PATH, but telling the server to run a file, which tells the server to change it. This method worked for the original author of these instructions.

    For passing arguments to the PHP wrapper script - check out PHP's $argv variable (more on this here). If you decided to use shell-script as a wrapper for "export LD_LIBRARY_PATH", then using $1, $2 etc will allow you to pass parameters to the shell script, e.g. in the example below

    CODE:
    1. export LD_LIBRARY_PATH=/home/myusername/
    2. /home/myusername/ffmpeg -i /home/myusername/$1 $2 /home/myusername/$3

    you could pass "input file" as first argument, "parameters" as second and "output file" as third to make such a wrapper script work.

    Share This

    Posted in *nix, PHP, Programming, Software, Web | 9 Comments »

    Instructions on installing libmp3lame-enabled ffmpeg on shared linux hosting

    12th March 2008

    Note: this post is based on the comment by Simon, who generously shared his experience.

    Step-by-step:

    • Download the compiled ffmpeg with libmp3lame support (direct download links: older version ffmpeg.with.lame and newer version ffmpeg.2007-10-28.with-libmp3lame-support).
    • Rename the downloaded executable file to "ffmpeg" (no extension), upload it to the directory on your server (in this example /home/myusername/).
    • Download libmp3lame.so.0.
    • Upload libmp3lame.so.0 to the same directory where you placed ffmpeg in.
    • Create a php file with the following code (remember to change the paths to your own, where you actually uploaded binaries in previous steps):
      PHP:
      1. <?php
      2. exec("export LD_LIBRARY_PATH=/home/myusername/");
      3. echo passthru("/home/myusername/ffmpeg -formats");
      4. ?>

    • If you access that PHP file with your browser, you should be able to see a list of formats which are supported by ffmpeg, and if you find "EA libmp3lame" somewhere in the output, then it means you now can Encode Audio in libmp3lame!
    • If that doesn't work for you: LD_LIBRARY_PATH can be a protected variable in PHP (you can check for this by searching for the "safe_mode_protected_env_vars" value in phpinfo() output). The workaround here can be to write your commands to a file from php, then chmod that file with 0775 permissions (rwx-rx-rx), and run the file through exec(). In this way, PHP is not changing the LD_LIBRARY_PATH, but telling the server to run a file, which tells the server to change it. This method worked for the original author of these instructions.

    For passing arguments to the PHP wrapper script - check out PHP's $argv variable (more on this here). If you decided to use shell-script as a wrapper for "export LD_LIBRARY_PATH", then using $1, $2 etc will allow you to pass parameters to the shell script, e.g. in the example below

    CODE:
    1. export LD_LIBRARY_PATH=/home/myusername/
    2. /home/myusername/ffmpeg -i /home/myusername/$1 $2 /home/myusername/$3

    you could pass "input file" as first argument, "parameters" as second and "output file" as third to make such a wrapper script work.

    Share This

    Posted in *nix, PHP, Programming, Software, Web | 9 Comments »

    How to improve MySQL application performance

    6th March 2008

    Juicy presentation, even for seasoned MySQL developers.

    You can also download the PDF of this presentation: Read the rest of this entry »

    Share This

    Posted in Links, Programming, Web | No Comments »

    SQL injection: RIAA example

    16th February 2008

    I know it's kind of old now, but check this image out:

    RIAA screenshot with some SQL injection code

    Via webplanet.ru - reddit.com.

    Share This

    Posted in Links, Notepad, Programming, Society, Web | No Comments »

    Python: passing by value vs passing by reference

    11th February 2008

    Note: this a collection of scraps, describing how values (de)referencing works in Python, and describing when your variable is either a value or a reference. Primary source of knowledge for this post (also here).

    Python passes references-to-objects by value (like Java), and everything in Python is an object. This sounds simple, but then you will notice that some data types seem to exhibit pass-by-value characteristics, while others seem to act like pass-by-reference... what's the deal?

    It is important to understand mutable and immutable objects. Some objects, like strings, tuples, and numbers, are immutable. Altering them inside a function/method will create a new instance and the original instance outside the function/method is not changed. Other objects, like lists and dictionaries are mutable, which means you can change the object in-place. Therefore, altering an object inside a function/method will also change the original object outside.

    Immutable variables - such as integers [strings, numerics and tuples are immutables] - are passed by value. That is, if your function accepts some integer argument, you are safe assuming that your function won't be able to modify your integer. Mutable variables - such as dictionaries and lists - are passed by reference, and so if your function accepts mutable argument, it may modify the contents of that mutable variable outside the scope of the function.

    When doing :
    s = "Hello "
    s += "World"
    ... you are not modifying the string object bound to s, but creating a new string object and binding it to s.

    If using object's methods within a called function, variable is considered "passed by reference" - it is modified out of the function's scope. If using assignment on a mutable object, it is created a-new within the function, and global value isn't modified.

    When you call a function with an arg, a "local variable" is created, which references the object passed as the argument. (well... an entry with the formal parameter name as key and a reference to the object passed in is created in the 'local' dict).

    So, rebinding this local symbol does not impact the binding in the caller's namespace - because the symbol lives in another namespace.

    *But* - and if the object referenced is mutable of course - modifying the object in the function... well, just modifies the object, because it's the *same* object that is bound to ('referenced by', if you prefer) both symbols (the one in the caller's namespace and the one in the function's namespace). So yes, the object *is* modified when the function returns.

    Share This

    Posted in Links, Programming, Python | No Comments »

    Python: passing by value vs passing by reference

    11th February 2008

    Note: this a collection of scraps, describing how values (de)referencing works in Python, and describing when your variable is either a value or a reference. Primary source of knowledge for this post (also here).

    Python passes references-to-objects by value (like Java), and everything in Python is an object. This sounds simple, but then you will notice that some data types seem to exhibit pass-by-value characteristics, while others seem to act like pass-by-reference... what's the deal?

    It is important to understand mutable and immutable objects. Some objects, like strings, tuples, and numbers, are immutable. Altering them inside a function/method will create a new instance and the original instance outside the function/method is not changed. Other objects, like lists and dictionaries are mutable, which means you can change the object in-place. Therefore, altering an object inside a function/method will also change the original object outside.

    Immutable variables - such as integers [strings, numerics and tuples are immutables] - are passed by value. That is, if your function accepts some integer argument, you are safe assuming that your function won't be able to modify your integer. Mutable variables - such as dictionaries and lists - are passed by reference, and so if your function accepts mutable argument, it may modify the contents of that mutable variable outside the scope of the function.

    When doing :
    s = "Hello "
    s += "World"
    ... you are not modifying the string object bound to s, but creating a new string object and binding it to s.

    If using object's methods within a called function, variable is considered "passed by reference" - it is modified out of the function's scope. If using assignment on a mutable object, it is created a-new within the function, and global value isn't modified.

    When you call a function with an arg, a "local variable" is created, which references the object passed as the argument. (well... an entry with the formal parameter name as key and a reference to the object passed in is created in the 'local' dict).

    So, rebinding this local symbol does not impact the binding in the caller's namespace - because the symbol lives in another namespace.

    *But* - and if the object referenced is mutable of course - modifying the object in the function... well, just modifies the object, because it's the *same* object that is bound to ('referenced by', if you prefer) both symbols (the one in the caller's namespace and the one in the function's namespace). So yes, the object *is* modified when the function returns.

    Share This

    Posted in Links, Programming, Python | No Comments »

    Convert MySQL database from one encoding/collation into another

    8th February 2008

    Most frequent use: convert database from latin1_swedish to utf8_general_ci.
    Original script found at: MySQL and UTF-8.

    Update: the original script had an error, it would generate queries likes this one (note the bold part):

    ALTER TABLE `links` CHANGE `link_rel` `link_rel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT NULL;

    This is clearly wrong syntax (and logic). I fixed this by making comparison to NULL strict (with three equal signs instead of two):

    // Does the field default to null, a string, or nothing?
    if ($row['Default'] === NULL)

    Update 2: based on comment by banesto, I modified the script; now it does not require specifying the from_collation, it's sufficient to specify to_collation (which will be used for all the fields and tables). The modified code is:

    if ($row['Collation'] == '' || $row['Collation'] == $convert_to)
    continue;

    Here's the script itself: (to copy-paste: first click the "Plain text" header)
    Read the rest of this entry »

    Share This

    Posted in Links, Notepad, PHP, Programming, Web | 10 Comments »

    Convert MySQL database from one encoding/collation into another

    8th February 2008

    Most frequent use: convert database from latin1_swedish to utf8_general_ci.
    Original script found at: MySQL and UTF-8.

    Update: the original script had an error, it would generate queries likes this one (note the bold part):

    ALTER TABLE `links` CHANGE `link_rel` `link_rel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT NULL;

    This is clearly wrong syntax (and logic). I fixed this by making comparison to NULL strict (with three equal signs instead of two):

    // Does the field default to null, a string, or nothing?
    if ($row['Default'] === NULL)

    Update 2: based on comment by banesto, I modified the script; now it does not require specifying the from_collation, it's sufficient to specify to_collation (which will be used for all the fields and tables). The modified code is:

    if ($row['Collation'] == '' || $row['Collation'] == $convert_to)
    continue;

    Here's the script itself: (to copy-paste: first click the "Plain text" header)
    Read the rest of this entry »

    Share This

    Posted in Links, Notepad, PHP, Programming, Web | 10 Comments »

    CodeCodex: shared online code repository

    10th December 2007

    CodeCodex Wiki.

    Found this one useful when looking for string conversion to uppercase - CodeCodex has it for 10 languages (alas, Ada isn't among them - but it's present in tiny pieces here and there, when searching for it at CodeCodex).

    Share This

    Posted in Links, Programming | No Comments »

    MySQL: INSERT IF NOT EXISTS syntax

    18th October 2007

    To start: as of the latest MySQL, syntax presented in the title is not possible. But there are several very easy ways to accomplish what is expected using existing functionality.

    There are two possible solutions: using INSERT IGNORE or REPLACE.

    Imagine we have a table:

    SQL:
    1. CREATE TABLE `transcripts` (
    2.  `ensembl_transcript_id` varchar(20) NOT NULL,
    3.  `transcript_chrom_start` int(10) UNSIGNED NOT NULL,
    4.  `transcript_chrom_end` int(10) UNSIGNED NOT NULL,
    5.  PRIMARY KEY  (`ensembl_transcript_id`)
    6. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    Now imagine that we have an automatic pipeline importing transcripts meta-data from Ensembl, and that due to various reasons the pipeline might be broken at any step of execution. Thus, we need to ensure two things: 1) repeated executions of the pipeline will not destroy our database, and 2) repeated executions will not die due to 'duplicate primary key' errors.

    Method 1: using REPLACE
    Read the rest of this entry »

    Share This

    Posted in Programming | 9 Comments »

    GoDaddy: undocumented 20-second CPU time maximal execution limit? (python, ELF, etc)

    16th October 2007

    Today, setting up a relatively serious (in CPU resources needed) web-system, I ran into a weird problem of python scripts ending prematurely. After some investigation, it looked like any process which uses up more than 20 seconds of CPU time, is automatically killed. To verify this, I wrote an infinite loop in C,

    C:
    1. int main () {
    2.  unsigned int i;
    3.  
    4.  for (i = 0; i <2 ; i++ ) {
    5.   i = 0;
    6.  }
    7.  
    8.  return 0;
    9. }

    compiled it and executed several times on the GoDaddy shared hosting server. I did observe the program running for the maximum of 20 seconds of CPU time, not a second more. Please note, that 20 seconds of CPU time can be much more of "real" time, if the script isn't using 100% of CPU, which often the case for shared hosting. Thus if you have in your php.ini max_execution_time set to, say, 60 seconds, your php script may actually execute as long as one minute; but I'm pretty sure that if your script has lots of CPU-intensive procedures, then as soon as it uses 20 seconds of CPU time, it will be terminated (however, this statement still needs checking - anyone?).

    To verify, I also created a cron job with the same file. It ran for 30 seconds CPU time.

    Strangely, this behaviour is not documented anywhere.

    This limit may also explain a number of other problems, if you have heavy web-applications: they just might be killed before they are finished, causing errors.

    I do understand the reason for this limitation, and am sure similar limitations exist in other shared hosting environments. The only important thing here is that this limit should have been documented and even put upfront somewhere in the hosting plans descriptions.

    I also wonder if the limit is the same for all godaddy shared hosting plans, or if it differs. 20 seconds when executed from PHP, and 30 seconds when executed as a cron job were observed on the Deluxe Linux Hosting plan.

    Extensions, additions and comments are welcome.

    Share This

    Posted in *nix, Misc, Programming, Web | 2 Comments »

    Flash countdown video tutorial

    27th September 2007

    Found a good video tutorial on how to create a countdown animation with Flash. Important notice: in my case, if Auto kern was enabled for the dynamic text box, there were no digits visible at all (size of my countdown animation was 120px wide and 186px high - quite small, so might be the reason of "auto kern" pushing text out of the view).

    Here's the image of the counter I created following the tutorial:
    countdown

    Share This

    Posted in Links, Programming, Web | No Comments »

    Useful Python looping techniques

    26th September 2007

    These are all excerpts from the Python documentation.

    To synchronously and simultaneously loop over two sequences:

    PYTHON:
    1. questions = ['name', 'quest', 'favourite colour']
    2. answers = ['Lancelot', 'the holy grail', 'blue']
    3.  
    4. for q, a in zip(questions, answers):
    5.     print 'What is your %s?  It is %s.' % (q, a)

    To loop over a sequence with both key and value:
    Read the rest of this entry »

    Share This

    Posted in Notepad, Programming, Python | No Comments »

    Useful Python looping techniques

    26th September 2007

    These are all excerpts from the Python documentation.

    To synchronously and simultaneously loop over two sequences:

    PYTHON:
    1. questions = ['name', 'quest', 'favourite colour']
    2. answers = ['Lancelot', 'the holy grail', 'blue']
    3.  
    4. for q, a in zip(questions, answers):
    5.     print 'What is your %s?  It is %s.' % (q, a)

    To loop over a sequence with both key and value:
    Read the rest of this entry »

    Share This

    Posted in Notepad, Programming, Python | No Comments »

    How to sort Python dict (dictionary)

    26th September 2007

    Sample script (copypasted from Well House Consultants training course):
    click the PLAIN TEXT header for copy-pasteable version

    PYTHON:
    1. #!/usr/local/bin/python
    2.  
    3. author = {"php":"Rasmus Lerdorf",\
    4.     "perl":"Larry Wall",\
    5.     "tcl":"John Ousterhout",\
    6.     "awk":"Brian Kernighan",\
    7.     "java":"James Gosling",\
    8.     "parrot":"Simon Cozens",\
    9.     "python":"Guido van Rossum"}
    10.  
    11. langs = author.keys()
    12. langs.sort()
    13.  
    14. for language in langs:
    15.     print language,"is the child of",author[language]

    You can also define the Python ksort() function similar to that found in PHP:
    Read the rest of this entry »

    Share This

    Posted in Notepad, Programming, Python | No Comments »

     
    Close
    E-mail It