Use ActiveRecord::Enum for your enumerations

I’ve recently started working on a rails codebase, where I noticed something quite interresting. Let’s say we have a model called Post. A post can either be draft or published. This data is saved in the status column. In programming, we say that status is an enumeration, because it has a finite number of possible values (draft and published). In this post, I’ll try to show you what is wrong with the way post status is handled in that codebase, and how we can do better using ActiveRecord::Enum

Value vs Reference in Javascript: A complete Guide

A better understanding of the value and reference concept, can help a developer writing better code and avoiding bugs, due to unexpected side effects. In this article I’ll explain the concept of value and reference in Javascript, but you should be able to understand from here, how it works in your favorite programming language. Immutables and Mutables In programming, a variable can either be an immutable or a mutable. A mutable can be changed after it’s created, while an immutable can’t.

Submit static forms to Google Sheet: The Easy Way

When building static sites, you may not want to implement a backend for handling your form submissions. Google sheet are a great way to store/use that data. Here, I’m going to show you how to send your data, directy into a google sheet via a google form. Write a static form Let’s build a simple form, that we will use through this article. Go ahead, and create a file (index.html), containing this code.

Writing your own ORM in Ruby

TLDR: In this post, we’re going to write a basic ORM (Object-Relational Mapper) in Ruby. If you don’t know what an ORM is, or never used one before, I recommend reading this article before. Our ORM will implement the Active Record pattern. This post assumes you know about Ruby, Gems, Bundler and SQL. Getting ready Our ORM, let’s call it LiteRecord , will be very basic and will only support SQLite3, but will be good enough for you to understand how an ORM works under the cover and from there, you can build a more powerful one.

TAXE PAS MES MOs (in French)

Dans la journée du 18 Septembre 2018, les opérateurs GSM au Bénin, ont changé leurs offres d’abonnement internet, augmentant de manière extravagante les prix pour accéder aux réseaux sociaux, relativement à la décision du gouvernement de percevoir une taxe sur les débits de navigation sur les médias sociaux. Depuis l’annonce de ce décret, beaucoup ont manifesté leur mécontentement, d’une manière qui n’aurait pas pu être inaudible au gouvernement. Les conséquences que peuvent engendrer cette taxe, font tout un chapelet.

Do you use feature flags ?

What are feature flags ? When adding new features to production, problems often happen and their impact can range from simple bugs to a whole application shutdown. Feature flags provide a way to: - Roll out features to specific users or groups of users instead of everyone - Enable/Disable features in real-time without altering your code or rolling back your release Usage of feature flags in a Rails application Install and configure the rollout gem The rollout gem is based on `Redis`, so we need to have it installed as well.

No YODA conditions, please !

One of the Wordpress Coding Standards rules is: You must use YODA conditions What are YODA conditions and why don’t I like them much ? YODA conditions YODA conditions stipulates that, instead of: if ($role == ‘admin’) { // some logic } You should write: if (‘admin’ == $role) { // some logic } What we did in the above code, is permuting $role and 'admin' positions, by putting the constant before the variable.

Export a Github wiki as PDF

At Botamp, we use the Koala library to interract with the Facebook Graph API. Thus, I happen to read their wiki a lot so that I decided to turn it into a well structured PDF ebook that I can quickly and easily read. If you don’t have time for the reading, check this project out. What is a Github wiki ? According to the Github documentation about wikis, GitHub Wikis are a place in your repository where you can share long-form content about your project, such as how to use it, how it’s been designed, manifestos on its core principles, and so on.

Implement smooth scrolling in pure Javascript

Smooth scrolling is something very cool, we all like. Most of the time, people add it to their websites via jQuery plugins. Although those plugins are great, they might not be a good fit if your are a guy called Jimmy who doesn’t want to add jQuery to his project. If you are this guy, stay with me, I will show you how to implement smooth scrolling yourself, with vanilla Javascript.

Generate PDF files from your Rails app

Working recently on a Rails project, I needed to generate PDF files from the app. After searching on Github (specifically in Awesome Ruby) for open source solutions that fit my needs , I ended up choosing wicked_pdf. Let’s see how to make the magic happen. Why wicked_pdf ? I chosen Wicked PDF for 3 specific reasons, It’s very easy to use It helps you generate your PDF files from HTML & CSS (& JS) It’s easy to integrate into a Rails project (It’s actually a Rails plugin) Wicked_pdf uses the awesome wkhtmltopdf project, to create PDF files.