Smooth tile scrolling with Slick

game1

This is my first attempt for smooth tile scrolling in Slick. The offx/offy coordinates are not entirely correct for hero, smaller than the tile image but it's a good start the "smooth" part comes from shx/shy variables which offset the rendering position. The code is after the break:

Update: Check the project source code page at Google Code: http://code.google.com/p/jmuonline/

Continue Reading »

Media Wiki Bot

I needed a bot to quickly modify the pages of wiki.muonlinehelp.com. So I created Mutex which kind of helps do the job. It's full of bugs with no error handling but works for me.

Usage:

 
<?
  require 'class.mediawiki.php';
  $mw = new mediawiki('http://yourwikiurl/api.php');
  $mw->login('bot_user', 'bot_password');
  $mw->editPage('title', 'page_text');
?>
 

You can get the source code from here.

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 src="2.png" alt="image 2"/></a>
  <a href="#"><img src="3.png" alt="image 3"/></a>
  <a href="#"><img src="4.png" alt="image 4"/></a>
  <a href="#"><img src="5.png" alt="image 5"/></a>
</div>
 

The HTML will render as this:
Screen Shot 1

Let's add a little css to get the desired effect:

 
  #top_offers{
    height: 190px;
    background-color: #d3d7cf;
    overflow: hidden; /* hide the excess images*/
    text-align: justify; /* or center here */
  }
  #top_offers a img{
    margin: 20px;
    border:none;
  }
 

Which brings the following results:
Screen Shot 2

Screen Shot 3

You can play with the example here.

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 was to get all the records' count, without supplying second query.

I found the solution in ADODB's Pager class and it is the following:

Given the query: [SQL] (without LIMIT and OFFSET), execute the following query:

 
SELECT Count(*) FROM ([SQL]) AS foo;
 

I know it's not as easy as SQL_CALC_FOUND_ROWS but it works;