Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    • Archives

    • Recent comments

    Archive for February, 2007

    Multiple IEs on one Windows: enabling Printing in IE6

    19th February 2007

    After IE7 came out, it got much harder for HTML/CSS coders to maintain compatibility with both IE6 and IE7.
    IE7 is pushing IE6 out, as it is a high-priority update; however, massive part of users will remain on IE6 for various reasons, not excluding the licensing issues (non-licensed/fake-licensed Windows XP will not let install IE7).

    The problem is: after installing IE7, you no longer have IE6 (which is replaced by IE7).

    However, there is a good and simple solution, enabling one to run IE3 through IE7 on one computer.
    To do so, just install the latest version of IE you want (I assume it’s IE7), and then point your browser to evolt’s archive of browsers (what an excellent collection!). You will have to “install” (just copy, really) each older IE you want into a separate directory, and create a short-cut for each. (You may want to use all-in-one installer, found here – also a great package, though I didn’t use it.)

    After I installed IE6, I also copied some additional files to its folder (like wininet.dll, version 6.00.2900.2180 or like that), to avoid problems with cookies disabled in IE6.

    However, there is a huge problem with multiple IEs: Print Preview and Print do not work at all!
    After some searching, I found two bug reports:

    • clicking on any bookmark will not load the bookmark, but will open the Print dialogue
    • trying to use the bookmark-derived Print dialogue appears not to work: produces blank page

    Read the rest of this entry »

    Share

    Posted in Programming, Software, Web, XHTML/CSS | 3 Comments »

    Vertically align text to bottom within div

    19th February 2007

    I was looking to solve this extremely common problem – when you need to vertical-align:top/middle/bottom something within the DIV element. So far not a single solution fits my exact case, but I collected different solutions here for convenient reference.

    • vertical-align CSS property should be applied to the inline element within your DIV (which is a block element), and NOT to the DIV itself. For this to work, you may need to set line-height and font-size to the height of the enveloping DIV element:
      1. <div>
      2. <img src="/images/demoBoxH.gif" alt="" />
      3. </div>
      1. div{
      2.     height:200px;
      3.     width:200px;
      4.     background:blue;
      5.     text-align:center;
      6.     line-height:200px;
      7.     font-size:200px;
      8. }
      9. *>div{
      10.     font-size:12px
      11. }
      12. img{
      13.     vertical-align:middle
      14. }
    • there is a different approach: for the element within your DIV, set display:absolute and bottom:0px (or top:0px) to vertically align to bottom or top, respectively. Note that this approach doesn’t let aligning to “middle”, and that it works best when only one block-level element is aligned – otherwise elements will overlap at the bottom/top of container DIV. Container DIV should be set to position:relative.
    • another approach: we can set the container DIV to
      1. div {display:table-cell;vertical-align:middle}

      because for table cells vertical-align property works as one might expect from common sense and the text-align property. Basically, by doing so we ask the browser to treat our DIV as a table-cell, where vertical-align works just perfectly. However, this approach appears not to work on most IE browsers (probably except for IE7 only, but I didn’t try, as I need IE6 support as well).

    • one more table-cell-display-based solution by Nikola:
      1. .nav_next a {
      2. display: table-cell;
      3. width: 85px;
      4. text-align: center;
      5. padding-top: 60px;
      6. position: relative;
      7. top: 60px;
      8. margin-top: -60px;
      9. }

      This time, display:table-cell is applied to the immediate text container (anchor in the example), and then padding-top is added to push text to the bottom. Should work in FF3 and IE6; in FF3, this solution worked in a test setup without the last 3 CSS attributes, but YMMV.

    • vertical alignment can be simulated with margins, applied to the element(s) within the container DIV. This is a simple approach and I would recommend it, if the heights of the container and elements within it are known (otherwise, this method is of no help). Example application of this method: if you have a DIV container 200px high, and need to position some SPANed text within it; first, set SPAN to
      1. span {display:block; height:20px}

      (or whatever height value fits your requirements), and then set margins to vertically align the SPAN. To align your SPAN to top, you would apply

      1. span {display:block; height:20px;margin-bottom:180px}

      to your SPAN; to align to bottom –

      1. span {display:block; height:20px;margin-top:180px}

      to align in the middle –

      1. span {display:block; height:20px;margin:90px 0px}

    References:

    (The problem I have involves vertically aligning two DIVs within a container DIV so that DIV1 is aligned to top, and DIV2 is aligned to bottom, and their content is aligned appropriately to top/bottom, and that it works in at least IE6, IE7, FF2. If anyone has a ready solution – please comment. When I find mine, I’ll add it to the list above.)

    Share

    Posted in Programming, XHTML/CSS | 5 Comments »

    Mondscheintarif (2001)

    15th February 2007

    This is an emotional and feminine movie. It’s pleasant, entertaining, and even a bit unusual. I didn’t see some clear message delivered by Mondscheintarif, but I did enjoy the movie.
    Read the rest of this entry »

    Share

    Posted in Movies | No Comments »

    The Man Who Wasn’t There (2001)

    15th February 2007

    This might be worth seeing once, but definitely not twice or more.
    Read the rest of this entry »

    Share

    Posted in Movies | No Comments »

    PhotoFiltre: recommended simple image-editing software

    9th February 2007

    I’ve been using PhotoFiltre for quite a while until now, and can recommend this software.
    In my case, primary usage purpose is light-weight editing – when Photoshop/GIMP would be an overkill, and Paint is just not enough.
    Read the rest of this entry »

    Share

    Posted in Software | 1 Comment »

    Choosing simple flash-based MP3 player

    8th February 2007

    I decided to buy a digital companion to use while commuting, travelling for longer distances, creating voice memos, probably even listening to some FM.

    Quite quickly I figured out my list of basic requirements: Read the rest of this entry »

    Share

    Posted in Hardware | No Comments »

    SQL tips

    2nd February 2007

    This is a copy of the Top 1000 SQL Performance Tips by Jay Pipes Sheeri Kritzer Bill Karwin Ronald (“Jeremy Basher”) Bradford Farhan “Frank Mash” Mashraqi Taso Du Val Ron Hu Klinton Lee Rick James Alan Kasindorf Eric Bergen Kaj Arno Joel Seligstein Amy Lee. Some tips dropped as not useful for me personally. This post is kept as a personal note/reference.

    Specific Query Performance Tips:
    1. Use EXPLAIN to profile the query execution plan
    2. Use Slow Query Log (always have it on!)
    3. Don’t use DISTINCT when you have or could use GROUP BY
    4. Insert performance
    1. Batch INSERT and REPLACE
    2. Use LOAD DATA instead of INSERT
    5. LIMIT m,n may not be as fast as it sounds
    6. Don’t use ORDER BY RAND() if you have > ~2K records
    7. Use SQL_NO_CACHE when you are SELECTing frequently updated data or large sets of data
    8. avoid wildcards at the start of LIKE queries
    9. avoid correlated subqueries and in select and where clause (try to avoid in)
    10. no calculated comparisons — isolate indexed columns
    11. ORDER BY and LIMIT work best with equalities and covered indexes
    12. separate text/blobs from metadata, don’t put text/blobs in results if you don’t need them
    13. derived tables (subqueries in the FROM clause) can be useful for retrieving BLOBs w/out sorting them. (self-join can speed up a query if 1st part finds the IDs and use it to fetch the rest)
    14. ALTER TABLE…ORDER BY can take data sorted chronologically and re-order it by a different field — this can make queries on that field run faster
    15. Know when to split a complex query and join smaller ones
    16. Delete small amounts at a time if you can
    17. make similar queries consistent so cache is used
    18. Have good SQL query standards
    19. Don’t use deprecated features
    20. Turning OR on multiple index fields (<5.0) into UNION may speed things up (with LIMIT), after 5.0 the index_merge should pick stuff up. 21. Don't use COUNT * on Innodb tables for every search, do it a few times and/or summary tables, or if you need it for the total # of rows, use SQL_CALC_FOUND_ROWS and SELECT FOUND_ROWS() 22. Use INSERT ... ON DUPLICATE KEY update (INSERT IGNORE) to avoid having to SELECT 23. use groupwise maximum instead of subqueries Scaling Performance Tips:
    1. Use benchmarking
    2. isolate workloads don’t let administrative work interfere with customer performance. (ie backups)
    3. as your data grows, indexing may change (cardinality and selectivity change). Structuring may want to change. Make your schema as modular as your code. Make your code able to scale. Plan and embrace change, and get developers to do the same.

    Network Performance Tips:
    1. Minimize traffic by fetching only what you need.
    1. Paging/chunked data retrieval to limit
    2. Don’t use SELECT *
    3. Be wary of lots of small quick queries if a longer query can be more efficient
    2. use multi_query if appropriate to reduce round-trips

    OS Performance Tips:
    1. Use proper data partitions
    1. For Cluster. Start thinking about Cluster *before* you need them
    2. Keep the database host as clean as possible. Do you really need a windowing system on that server?
    3. Utilize the strengths of the OS
    4. pare down cron scripts
    5. create a test environment
    6. source control schema and config files
    7. for LVM innodb backups, restore to a different instance of MySQL so Innodb can roll forward
    8. partition appropriately
    9. partition your database when you have real data — do not assume you know your dataset until you have real data

    MySQL Server Overall Tips:
    1. innodb_flush_commit=0 can help slave lag
    2. Optimize for data types, use consistent data types. Use PROCEDURE ANALYSE() to help determine the smallest data type for your needs.
    3. use optimistic locking, not pessimistic locking. try to use shared lock, not exclusive lock. share mode vs. FOR UPDATE
    4. if you can, compress text/blobs
    5. compress static data
    6. don’t back up static data as often
    7. enable and increase the query and buffer caches if appropriate
    8. config params — http://docs.cellblue.nl/easy_mysql_performance_tweaks/ is a good reference
    9. Config variables & tips:
    1. use one of the supplied config files
    2. key_buffer, unix cache (leave some RAM free), per-connection variables, innodb memory variables
    3. be aware of global vs. per-connection variables
    4. check SHOW STATUS and SHOW VARIABLES (GLOBAL|SESSION in 5.0 and up)
    5. be aware of swapping esp. with Linux, “swappiness” (bypass OS filecache for innodb data files, innodb_flush_method=O_DIRECT if possible (this is also OS specific))
    6. defragment tables, rebuild indexes, do table maintenance
    7. If you use innodb_flush_txn_commit=1, use a battery-backed hardware cache write controller
    8. more RAM is good so faster disk speed
    9. use 64-bit architectures
    10. –skip-name-resolve
    11. increase myisam_sort_buffer_size to optimize large inserts (this is a per-connection variable)
    12. look up memory tuning parameter for on-insert caching
    13. increase temp table size in a data warehousing environment (default is 32Mb) so it doesn’t write to disk (also constrained by max_heap_table_size, default 16Mb)
    14. Run in SQL_MODE=STRICT to help identify warnings
    15. /tmp dir on battery-backed write cache
    16. consider battery-backed RAM for innodb logfiles
    17. use –safe-updates for client

    Storage Engine Performance Tips:
    1. InnoDB ALWAYS keeps the primary key as part of each index, so do not make the primary key very large
    2. Utilize different storage engines on master/slave ie, if you need fulltext indexing on a table.
    3. BLACKHOLE engine and replication is much faster than FEDERATED tables for things like logs.
    4. Know your storage engines and what performs best for your needs, know that different ones exist.
    1. ie, use MERGE tables ARCHIVE tables for logs
    2. Archive old data — don’t be a pack-rat! 2 common engines for this are ARCHIVE tables and MERGE tables
    5. use row-level instead of table-level locking for OLTP workloads
    6. try out a few schemas and storage engines in your test environment before picking one.

    Database Design Performance Tips:
    1. Design sane query schemas. don’t be afraid of table joins, often they are faster than denormalization
    2. Don’t use boolean flags
    3. Use Indexes
    4. Don’t Index Everything
    5. Do not duplicate indexes
    6. Do not use large columns in indexes if the ratio of SELECTs:INSERTs is low.
    7. be careful of redundant columns in an index or across indexes
    8. Use a clever key and ORDER BY instead of MAX
    9. Normalize first, and denormalize where appropriate.
    10. use INET_ATON and INET_NTOA for IP addresses, not char or varchar
    11. make it a habit to REVERSE() email addresses, so you can easily search domains (this will help avoid wildcards at the start of LIKE queries if you want to find everyone whose e-mail is in a certain domain)
    12. In 5.1 BOOL/BIT NOT NULL type is 1 bit, in previous versions it’s 1 byte.
    13. A NULL data type can take more room to store than NOT NULL
    14. Choose appropriate character sets & collations — UTF16 will store each character in 2 bytes, whether it needs it or not, latin1 is faster than UTF8.
    15. Use Triggers wisely
    16. use min_rows and max_rows to specify approximate data size so space can be pre-allocated and reference points can be calculated.
    17. Use HASH indexing for indexing across columns with similar data prefixes
    18. Use myisam_pack_keys for int data
    19. be able to change your schema without ruining functionality of your code
    20. segregate tables/databases that benefit from different configuration variables

    Other:
    1. Read and post to MySQL Planet at http://www.mysqlplanet.org/

    Share

    Posted in Notepad | No Comments »