Author Archives

Randomize timestamp in MySQL

To randomize timestamp column in mysql You can use the following statement:
 
UPDATE your_table SET
timestamp_field = TIMESTAMPADD(MINUTE, RAND()*60,timestamp_field);
 

Show images depending on the browser’s width with CSS only

I had the make promo offers sections form our site. Usually this is an easy task but the requirement on this case was to preserve the full page width design and keep the page usable for 600px wide screens.
So let’s start with the HTML portion.
 
<div id="top_offers">
<a href="#"><img src="1.png" alt="image 1"/></a>
<a href="#"><img [...]

Linux batch encoding convert one liner

 
find -name ‘*.php’ -exec iconv -f cp1251 -t utf8 ‘{}’ -o ‘{}’.utf8 \;
 
Idea taken from here.

Enable PL/SQL for Database in Postgres

To enable PL/SQL in PostgreSQL use:
 
CREATE LANGUAGE ‘plpgsql’ HANDLER plpgsql_call_handler
LANCOMPILER ‘PL/pgSQL’;
 

Alter Columns Position in Postgres

Some workarounds to alter columns position in Postgres

MySQL Database Alias

Sure, it’s not possible to create alias for database in MySQL but here’s a good workaround.
Don’t forget to set the perditions for the alias as well.

chomp for bash

Bash doesn’t have chomp command but you can use tr to get rid of \n \r (and other) characters.

SQL_CALC_FOUND_ROWS (kind of) for postgres

When I switched from MySQL to PostgreSQL, one of the things I missed the most was the ease of paging using SQL_CALC_FOUND_ROWS and SELECT FOUND_ROWS() afterwards. One of the places I use it heavily is in my Table class, which generates, sortable, filterable and paged HTML table based on an SQL Query. The tough spot [...]

MySQL UNION DISTINCT with result priority

I had to modify the search algorithm today, the idea was to fetch the exact matches first then the split words matches. The status quo was:
 
(SELECT product_id FROM products WHERE a=1)
UNION DISTINCT
(SELECT product_id FROM products WHERE a=2 OR a=1)
 
I wanted to be sure that the result from the first sub-query are before the [...]

RT73 on Hardy Heron

If you happen to use rt73 wireless with serial monkey drivers, and after upgrading the wireless stopped to work, take a look at this thread on how to fix it. The good news is that rt73 adapters now work out of the box with Hardy.