Syed Aslam

Thoughts, Stories, and Ideas

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 margins. Note that the parent container must have a `position: relative` property for this to work.

Re-initializing table sequence in postgresql

in Postgresql · 1 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 original data again. Let's see how to re-initialize table sequence in PostgreSQL.

Adding close link to flash messages

by Syed Aslam in Rails · 1 min read

The flash provides a way to pass temporary objects between actions. Anything you place in the flash will be exposed to the very next action and then cleared out. Learn a way to add close buttons to flash messages in Rails templates.

Connecting to multiple databases in a Rails app

by Syed Aslam in Rails · 1 min read

A traditional Rails application uses a single application. We interact with it by writing models that inherit from `ActiveRecord::Base` which translate connection details (from config/database.yml) via the method `establish_connection`. Let's see how to connect to multiple databases from a Rails app.