Syed Aslam

Thoughts, stories, and ideas.

How to use forked NPM dependencies

by Syed Aslam in Node · 3 min read

When using open-source NPM packages in your project, odds are you will run into a dependency that is missing a feature. This dependency doesn't do quite do what you want or has a bug that needs to be worked around for your use-case. What do you do in these situations, if your tea ...

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

Understanding Linked Lists

by Syed Aslam in Data Structures · 5 min read

Linked List was developed in 1955 by Allen Newell, Cliff Shaw, and Herbert A. Simon at RAND Corporation. The Linked List is a dynamically-allocated data structure, meaning it grows dynamically in memory on its own very time-efficiently (as opposed to an Array List, for which we n ...

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