Autarchy of the Private Cave

Science, Society, Programming and Hobbies

  • Exits

  • Categories

  • Archives

  • Visitors' track

    Locations of visitors to this page
  • Tags list

  • Earn and spend


  • Exits

  • Ratings

    Science Blogs - Blog Top Sites website monitoring service
  • Archive for the 'Programming' Category


    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 »

    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 »

    PHP proxy

    19th September 2007

    PHP proxy is simple but good. I converted it into a proxy-function for one of my projects.

    Do pay attention to the comments, especially these two:

    I had issues with this script (and others) returning 0 for the bytesTotal in flash. Basically, the Content-Length header was absent from the response. By simply adding
    header("Content-length: ".strlen($response)) before the echo, it resolved the issue. I don't know if there is a more appropriate fix to account for character encoding, etc, but it seems to work.

    @Schimmi: Well, if you can add some checks there (like who is referring your script) and allow the access to whitelisted clients (served from your domain)... I think, you can totally make it used applications from same-domain....So it would not be open to world. Yeah above script doesn't have those things.

    Share This

    Posted in Links, Notepad, PHP, Programming | No Comments »

    PHP proxy

    19th September 2007

    PHP proxy is simple but good. I converted it into a proxy-function for one of my projects.

    Do pay attention to the comments, especially these two:

    I had issues with this script (and others) returning 0 for the bytesTotal in flash. Basically, the Content-Length header was absent from the response. By simply adding
    header("Content-length: ".strlen($response)) before the echo, it resolved the issue. I don't know if there is a more appropriate fix to account for character encoding, etc, but it seems to work.

    @Schimmi: Well, if you can add some checks there (like who is referring your script) and allow the access to whitelisted clients (served from your domain)... I think, you can totally make it used applications from same-domain....So it would not be open to world. Yeah above script doesn't have those things.

    Share This

    Posted in Links, Notepad, PHP, Programming | No Comments »

    MySQL - Python: good MySQLdb tutorial (examples)

    7th September 2007

    Andy Dustman gave a presentation on Python and MySQL at the MySQL Users Conference 2005, Santa Clara, CA. The presentation is an excellent collection of examples for those who use the MySQLdb Python module.
    Read the rest of this entry »

    Share This

    Posted in Links, Notepad, Programming, Python | 2 Comments »

    MySQL - Python: good MySQLdb tutorial (examples)

    7th September 2007

    Andy Dustman gave a presentation on Python and MySQL at the MySQL Users Conference 2005, Santa Clara, CA. The presentation is an excellent collection of examples for those who use the MySQLdb Python module.
    Read the rest of this entry »

    Share This

    Posted in Links, Notepad, Programming, Python | 2 Comments »

    Date and time in Python scripts

    7th September 2007

    Here's an excellent description of various methods to handle date and time in Python scripts.

    Share This

    Posted in Links, Notepad, Programming, Python | No Comments »

    Date and time in Python scripts

    7th September 2007

    Here's an excellent description of various methods to handle date and time in Python scripts.

    Share This

    Posted in Links, Notepad, Programming, Python | No Comments »

    Elegantly converting Python list into another list with changed items

    30th August 2007

    I just had a small problem with my Python script:

    1. I have a list of tuples, called records_cache; each tuple looks like this:
    (note: for copy-pasting, click the PLAIN TEXT box headers)

    PYTHON:
    1. (ensembl_transcript_id, ensembl_gene_id, chrom_start, chrom_end, utr_start, utr_end, sequence, strand)

    2. I need to INSERT only some of those values into MySQL table, using the MySQLdb executemany() method. The values I need are utr_start, utr_end, ensembl_gene_id (in exactly this order).

    To do this, I need to create another list of tuples, but with shorter 3-item tuples. Let us call the new list genes_update.

    Here is the elegant, though probably not the most efficient, solution:
    Read the rest of this entry »

    Share This

    Posted in Programming, Python | 1 Comment »

    Elegantly converting Python list into another list with changed items

    30th August 2007

    I just had a small problem with my Python script:

    1. I have a list of tuples, called records_cache; each tuple looks like this:
    (note: for copy-pasting, click the PLAIN TEXT box headers)

    PYTHON:
    1. (ensembl_transcript_id, ensembl_gene_id, chrom_start, chrom_end, utr_start, utr_end, sequence, strand)

    2. I need to INSERT only some of those values into MySQL table, using the MySQLdb executemany() method. The values I need are utr_start, utr_end, ensembl_gene_id (in exactly this order).

    To do this, I need to create another list of tuples, but with shorter 3-item tuples. Let us call the new list genes_update.

    Here is the elegant, though probably not the most efficient, solution:
    Read the rest of this entry »

    Share This

    Posted in Programming, Python | 1 Comment »

    Is the force with you?

    12th August 2007

    Today, after starting ./configure to make one of the programs, I noticed this in the logs:
    is the Force with you? configure will tell!

    I don't know what is that intended to mean, but this is definitely funny: configure script, able to detect if the Force is with Skywalker...

    Share This

    Posted in Humour, Programming | No Comments »

    Non-Programmer’s Tutorial for Python

    12th August 2007

    Non-Programmer's Tutorial for Python

    Share This

    Posted in Links, Programming, Python | No Comments »

    Non-Programmer’s Tutorial for Python

    12th August 2007

    Non-Programmer's Tutorial for Python

    Share This

    Posted in Links, Programming, Python | No Comments »

    Good Python starter’s guide

    12th August 2007

    ... which covers some of the FAQs Python starters have.
    The guide was complete in December'2004, but does have lots of useful information for Python newbies and beginners.

    Share This

    Posted in Links, Programming, Python | No Comments »

    Good Python starter’s guide

    12th August 2007

    ... which covers some of the FAQs Python starters have.
    The guide was complete in December'2004, but does have lots of useful information for Python newbies and beginners.

    Share This

    Posted in Links, Programming, Python | No Comments »

    Python: iterate (and read) all files in a directory (folder)

    12th August 2007

    I found a sample of Python code to iterate through all the files within the specified folder (directory), with ability to use wildcards (*, ?, and [ ]-style ranges). Below is a portion of code from a working script:
    Read the rest of this entry »

    Share This

    Posted in Programming, Python | 2 Comments »

    Python: iterate (and read) all files in a directory (folder)

    12th August 2007

    I found a sample of Python code to iterate through all the files within the specified folder (directory), with ability to use wildcards (*, ?, and [ ]-style ranges). Below is a portion of code from a working script:
    Read the rest of this entry »

    Share This

    Posted in Programming, Python | 2 Comments »

    Geany source installation error: “libc.so: file format not recognized; treating as linker script”

    10th August 2007

    Today I was looking for some simple but convenient source-code editor. I came across this post, and decided to try Geany. I'm using Slackware 11 at the moment, and as there were no packages available, I downloaded Geany source to compile and install.

    However, the 'configure' script failed. When trying to compile 'conftest.c' with gcc, the following error was produced:

    libc.so: file format not recognized; treating as linker script

    (Note 1: in the error above, I removed all the paths which were prepended to the actual error message.)
    (Note 2: I suspect that this error is the result of incomplete/failed/erroneous update of glibc slackware package I attempted a while ago. Will have to fix that more properly than described below.)

    Here's the solution which helped me to install Geany successfully:
    Read the rest of this entry »

    Share This

    Posted in *nix, Programming, Software | 2 Comments »

    How to convert between utf8 and cp-1251 without iconv or mbstring

    8th July 2007

    This helped me, maybe it will help you: How to convert between utf8 and cp1251 without iconv
    Read the rest of this entry »

    Share This

    Posted in Links, PHP, Programming, Web | No Comments »

    How to convert between utf8 and cp-1251 without iconv or mbstring

    8th July 2007

    This helped me, maybe it will help you: How to convert between utf8 and cp1251 without iconv
    Read the rest of this entry »

    Share This

    Posted in Links, PHP, Programming, Web | No Comments »

     
    Close
    E-mail It