Syed Aslam

Thoughts, stories, and ideas.

Keeping array elements uniq in Ruby

by Syed Aslam in Ruby · 1 min read

With the uniq method you can remove duplicate elements from an array. However, calling uniq removes the duplicate elements and returns a new array with unique elemnts. It won't change the original array. You can use uniq! to remove duplicates in place. Another way is to only app ...

Dynamic Full Page Background Images in Rails

by Syed Aslam in Rails · 2 min read

You can set a background image purely through CSS thanks to the background-size property in CSS3. Using the html element is better than body as it's always at least the height of the browser window. You set a fixed and centered background on it, then adjust it's size using backgr ...

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 ...