Syed Aslam

Thoughts, stories, and ideas.

Working with Files in Ruby

by Syed Aslam in Ruby · 10 min read

It all starts with the IO class. The IO class is the basis for all input and output in Ruby either by itself or via its descendant classes, particularly File. To a large extent, IO's API consists of wrappers around system library calls, with some enhancements and modifications. A ...

Retrieving random row from a table via ActiveRecord

in Active Record · 1 min read

There are multiple ways to retrive a random row from a table: This is fast and requires no custom SQL. All this does is count number of rows in a table and select one row at some offset while still having the table ordered by primary key. It uses offset (limit), not ID number, s ...

Recover MySQL root Password

in Mysql · 1 min read

You can recover MySQL database server password with following five easy steps. Step # 1: Stop the MySQL server process Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password. Step # 3: Connect to ...

Highlighting current link within a navigation list in rails

in Rails · 1 min read

It's very common to want to highlight the current link within a navigation list for the current action being performed. If you are using Ajax, then this is easy, handle the onclick event to highlight the current link. Make sure you have a CSS class called youarehere. The followi ...

Centering a Fixed-Sized Element with CSS

by Syed Aslam in Css · 1 min read

Here is one way to center a fixed-width/fixed-height div at the center of its container. This could be adapted to centering text, images, etc. within their containers. Essentially, we do a bit of arithmetic to get the fixed-sized element centered using absolute positioning and ma ...

Re-initializing table sequence in postgresql

in Postgresql · 2 min read

Re-initializing a table sequence is quite normal and required in some cases. I had to do that recently. If the table has data and needs to be preserved, then temporarily you have to move the data, delete the data in original table and re-initialize the sequence and copy the origi ...