Yes. Getting Adequate Sleep night in night out.


Image for post
Disclaimer: You may or may not have improved your curry making skills by the end of this blog

So you’re going to build the next-gen eCommerce company selling dog supplies and you’ve decided to use React to build it with coz, you know, its all the rage now and choosing a front-end framework is the “first and most important responsible step” towards building any successful online business.

I’d like to share a neat trick I learned while building my own eCommerce website, obviously next-gen coz React!

Filtering products based on various aspects is a staple in any shopping site and so let’s add some filters to the product results page.


Whenever I wanted to use placeholders in raw SQL query fragments in Rails, I would use ? and end up writing —

Post.where('published_at > ?', some_time)

What if I wanted to add another condition that checks against the same value in some_time ?

Post.where('published_at > ? OR saved_at > ?', some_time, some_time)

To be perfectly honest, writing such code never bothered me and I did not put in the little effort that was needed to see if there was a better way to do this.

One day I was pairing with one of my colleagues, Preethi Kumar, and she had something that looked like symbols in her query fragments, like this — published_at > :date . …


I’ve been doing a lot of Rust recently together with my colleague and friend Preethi Kumar. If you’ve been following us over at Adventures in Rust, you’ll know we’re building a toy HTTP server as our learning project.

While getting help from the #rust-beginners IRC channel, which is excellent for newbies btw, I came across people talking about this Rust HTTP client project, reqwest.

Looked at the issues posted at the repo and immediately felt motivated to solve atleast one of those issues. I tried to find the easiest one based on the issue title and this one seemed doable.

Image for post

Checked with the maintainer Sean McArthur if I can work on this and he gave me the green signal. …


Image for post

If you’ve been following our stories closely, you would know that we had planned to implement the following three features for our little Rust web server.

  1. Serve static files
  2. CGI
  3. Reverse Proxy

With static file serving completed, implementing the CGI (Common Gateway Interface) Protocol was next on our plate.

For those who do not know what CGI is, it’s an age-old protocol for serving dynamic content on the web. Think Apache executing a PHP or a Ruby script and talking back to clients with dynamic responses. …


After much reading, Rust started to really attract us into it.

Something that really awed us was Rust’s enforcement on us to handle every possible scenario.

Image for post

Let’s say we’re trying to find the index of a string within an array.

Here’s what one would do in Ruby —

["Adam", "Josh", "Jackson"].find_index("Jackson") #=> 2

All good! What if the element is not in the array?

["Adam", "Josh", "Jackson"].find_index("Mat") #=> nil

Yes! nil. Ruby programmers (for that matter, most other programmers who work with languages that have the concept of nothing) would not find this behaviour surprising or troublesome.

We’re used to dealing with nil values all the time in Ruby. We might do something like this…


Image for post
Flamegraph generated for a Rails application’s request

Flamegraphs can be a valuable tool in helping you debug your application’s performance woes. But they can be pretty overwhelming when you’re using it for the first time, especially when you’re dealing with complex Rails applications with a lot of things going on inside of it.

But all we need is a little bit of intuition on how a flamegraph is built and what it represents and we’re good to go on our performance optimization journey. This post is aimed at helping you gain that valuable intuition.

What are flamegraphs?

A flamegraph is simply a visualization of the output of a sampling profiler.

Sampling Profiler? Alright, lets break things down. Firstly, a profiler is a tool that lets you inspect a running program and collect statistics that tell you how much resources (think memory, disk, etc.) the program is using, how long method calls are taking, how much time is spent executing each part of the code, etc. These stats are useful in helping you optimize your program. …


Dependency Injection (DI) is not a very well received idea in the Ruby world. But once you understand what its all about, its not at as scary as many people consider it to be.

Image for post

Let me explain it to you using a very simple example. Take a look at this method from my application —

def setup
Subscriptions::Manage.new(subscription).setup(Plan.base_plan)
end

This allows me to create subscriptions for our user accounts using the plan obtained from Plan.base_plan.

Everything was fine until one day I wanted to use this method to setup some users with a different plan via the rails console. Boom! …


The idea of having small objects that are each responsible for just one thing has grown on me gradually. In this blog I want to write about one such object that I introduced into my current application recently.

The object was a Policy Object. Here’s a simple definition —

Policy Objects encapsulate and express a single business rule .

In our applications we might have different business rules coded mostly as if-else or switch statements. These rules represent concepts in your domain like whether “a customer is eligible for a discount” or whether “an email is supposed to be sent or not” or even whether “a player should be awarded a point”.


TL;DR
1. Perform debouncing to avoid unnecessary requests
2. Remember to cancel old pending requests

Often times our apps need that sleek and handy search box to filter various things. Not a bunch of fields that combine with different logical operators but just one single text field to get the job done. In case your back-end is Rails, you might quickly put together this feature leveraging the Server generated JavaScript Response (SJR) technique (I can foresee some outrage — hold it.) and you might have something similar to below in your front-end.

The server returns a script file that will essentially update the document with the search results (or you might do something else if you do not like SJR). …

About

Steve Robinson

Software guy. #Ruby #ObjectDesign #Teams #DevOps

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store