nix Using custom/older versions of libraries and packages using nix. Install custom or older versions of package(Ruby or Node or any other) using nix by overriding the package derivation using overrideAttrs
ruby Custom types using dry-logic and predicates Build custom types for IPv4 and IPv6 using dry-logic and predicates.
rspec Fixing Rspec tests involving timestamps on CircleCI. Use TimeCop gem or rspec be_within built in matcher to fix specs involving timestamps in CircleCI
ruby Disable pry and exit debugger without killing the main program in Ruby You ever ran into a situation where you had a huge loop running and you put a binding.pry within that loop for debugging and wondered how the hell you would exit the debugger? The answer is simple disable-pry is your saviour.! via GIPHY
rake Passing multiple options/argument with default options in rake Rake task allows you to accept multiple arguments which can be used within the task, and also allows us to specify default options for these arguments. Accept multiple arguments/options Lets say we have a simple rake task to sync data from/across our
ruby Script/runner vz Rake tasks When it comes to running Rails tasks the common question that comes to mind is whether to use script/runner or to call a rake task script/runner long_running_task VZ rake long_running_task To understand it better we need to understand
ruby Elegant way to silently ignore a Ruby exception I was working on a small hobby project and wanted to ignore some of the Exceptions that were raised. The first version of the code that I wrote was something similar to: def ignore_exception begin yield rescue Exception end end and using ignore_
ruby How to load rake task from a custom file or directory If you are wondering how you can load a rake task from a custom file, then this is guide will help you to accomplish your task. Lets assume you have a rake task named hello.rake under your project directory's lib folder like: <
ruby Active Model Serializer vz Jbuilder vz Rabl vz Grape-entity for rendering JSON When architecting an API only application one the of the most important points of discussion among the team members is which framework to use ? Should we be using Rails and render JSON ? Should we be using Grape ? Should we be using Rails-API ? Also, how
ruby Error handling with Grape, Rails and ActiveRecord CanCan I have been working on a project developing the backend API using Rails and Grape. One fine morning I pulled the latest code from the git repo that my colleague wrote, and was going to review the code. As usual, the first thing I
grape Using helper methods and helper modules in Rails Grape to keep the code DRY I was working with a Grape API and got into a situation where I was kind of reimplementing some methods on more than one mounted API. So naturally, I wanted to refactor the code, keep it DRY and extract it as helper methods and
rails Rails : Devise : Send different Emails for Confirmation based on the presence of attribute or parameter So what am I up to today? - I thought of scribbling down some pieces of code that I wrote to help one of my interns in my company to help complete a task. I was juggling with my daily work and I suddenly
rails Testing carrierwave file uploads with RSpec and FactoryGirl. TLDR; In this blog post, I am gonna focus only on testing carrierwave. So if you are looking for instruction on installing/setting up carrierwave in your project I would suggest you looking at the carrierwave's wiki over here. So let's assume we have
ruby Visualise your Gemfile dependencies If you ever wanted to visualise the gem dependencies of in your ruby/rails app, then bundler is there for rescue. Type in the following from your terminal: bundle viz Viz generates a PNG file of the current Gemfile as a dependency graph. Viz
ruby Connecting Ruby & Active Record Without Rails require 'active_record' require 'mysql2' # or 'pg' or 'sqlite3' # Change the following to reflect your database settings ActiveRecord::Base.establish_connection( adapter: 'mysql2', # or 'postgresql' or 'sqlite3' host: 'localhost', database: 'your_database', username: 'your_username', password: 'your_password' ) # Define your classes based on the
ruby Problem installing puma on OS X with openssl When installing puma on OSX 10.11 El Capitan, if you are facing issues compiling mini_ssl.c fatal error: 'openssl/bio.h' file not found. all you need to do is to specify --with-opt-dir You can make this applicable for all your Gemfiles:
ruby Pundit for authorization with Rspec Rails Authorization is one of the important feature of any web app. With rails you can leverage the power of all those wonderful open source gems that are available to you or you can code your own authorization module. The most commonly used gems for
ruby Ruby: delete multiple hash keys Returns a hash that includes everything but the given keys. hash = { a: true, b: false, c: nil} hash.except(:c) # => { a: true, b: false} hash # => { a: true, b: false, c: nil} This is useful for limiting a set of parameters to everything
git “bin/rails: No such file or directory” w/ Ruby 2 & Rails 4 on Heroku Rails apps with version 4 or above has some files under the bin folder namely bundle, rails, rake, setup, spring. But since I had bin folder gitignored, these files dint make it to heroku. To fix this: Remove bin from ~/.gitignore Run bundle install
ruby Calling View helper methods from Controller / Model in Rails Recently I was researching a way to use link_to inside my Rails 3 controller, and learned about the method view_context. So if you ever want to access view helper methods from controller / models in rails 3 you have to use view_context
til How do I make --no-ri --no-rdoc the default for gem install? If you are deploying to a server, or you do not want to wait around for rdoc and ri to install for each gem, you can disable them for gem installs and updates. Just add the following line to your ~/.gemrc or /etc/gemrc: