27 Jul 2020
JetBrains recently released JetBrains Mono fonts for free.
It is very friendly to developers as the font has,
- Increased height and letter spacing for a better reading experience(study says we spend 80%+ time on reading code)
- Code-specific ligatures merges multiple symbols helps eyes to process less
With Ligature ❤
- And it’s free & open source
How install in Ubuntu?
Download and Install
Use browser to download zip from Jetbrains Mono page and
unzip it in
~/.local/share/fonts/ to use it for specific user or
/usr/share/fonts for system wide use.
Use command line
$ wget https://download.jetbrains.com/fonts/JetBrainsMono-2.001.zip
$ unzip JetBrainsMono-2.001.zip
To use it for specific user:
$ mv JetBrainsMono-*.ttf ~/.local/share/fonts/
To use it sysem-wide:
$ sudo mv JetBrainsMono-*.ttf /usr/share/fonts/
How to enable in Sublime Text?
Download latest version from here
Preferences > Settings
"font_face": "JetBrains Mono" on the User’s pref
- Save (
24 Jul 2020
Suddenly I noticed a peculiar deprecation warning on
.pluck in log everywhere.
DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): [:client_id, :duns, :legal_business_name]. Non-attribute arguments will be disallowed in Rails 6.1. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql()
Here is a simplified snippet which was generating the warning:
ERRORED_RECORDS_FIELDS = %i(client_id duns legal_business_name)
However, the result returns just fine. Reading a bit around the warning I relized that I have been passing array if fields which at first point looks ok but it’s not.
So instead of passing array, splat the array so that all elements are received as separate column value in the
args of the
So following fixes the issue.
06 May 2020
Most people in the world who use smartphones don’t own/use email. However they know how to operate the mobile and apps.
What if you need to build an app for such users who want to access your app and it requires some kind of authentication mechanism?
If you are building a web application using rails, the natural choice for authentication would be Devise. Conventionally Device’s promotes email to authenticate users. Replacing email with mobile as authentication key needs some tweaks in configurations.
Ensure you have configured
root in your application inside
config/routes.rb. You can skip this section and jump to Install Devise step
If you just created a new rails app, let us create a simple
index action for demo purpose. Run following from command line
rails g controller Home index
config/routes.rb and configure
You can skip this step if you have already set up the Device.
gem 'devise' to your
Gemfile and run
bundle install from the command line
Run Devise Generator
rails generate devise:install from the command line
Follow instructions appear in the console to complete configuration.
Create a model for authentication passing
mobile as additional field
rails generate devise User mobile
Modify Generated Migration
Devise is going to use
mobile to find matching user in the app so we should add index to
mobile to make searching faster. This command creates
User model, creates a migration for it and changes
routes.rb to add Devise specific routes.
Open the generated migration and make following changes
mobile field as not
t.string :mobile, null: false
Add following line below the the index for
add_index :users, :mobile, unique: true
rails db:migrate from the command line to create
Assuming you want to protect all views/controllers, add following to enable authentication for all controllers in
rails server and hit
http://localhost:3000 to verify the setup. You should get a login page.
Override Devise’s Default Views
Devise provides default views for Sign In, Sign Up, Reset Password etc. All those views are configured to use
email which we need to replace with
Copy views from Devise to your app
rails generate devise:views from command line
mobile in Sign In and Sign Up devise views
app/views/devise/registrations/new.html.erb to replace
telephone_field. The updated configuration will look like in both views
<%= f.label :mobile %><br />
<%= f.telephone_field :mobile, autofocus: true, autocomplete: "mobile" %>
Whitelist mobile param via Strong parameters
Devise controllers santize parameters to ensure only require parameters are sent and rest are ignored. We added
mobile field which is not in the whitelist provided by Deviase. We need to add it to ensure it is allowed to use by Devise. Here is how it looks like:
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
devise_parameter_sanitizer.permit(:sign_up, keys: [:mobile])
devise_parameter_sanitizer.permit(:sign_in, keys: [:mobile])
Check Whitelisting Custom Fields for more details.
Override Devise’s Default Model Configuration
Add following to your
User model to avoid
email as authentication key
validates :email, uniqueness: true
validates :mobile, uniqueness: true
# Search user by mobile(not email)
conditions = warden_conditions.dup
# Stop using email as authentication key
Refer How To: Allow users to sign in using their username or email address For more details
Change Initializer to support mobile as authentication key
config/initializers/devise.rb and ensure following configuration:
config.authentication_keys = [:mobile]
config.case_insensitive_keys = [:mobile]
config.strip_whitespace_keys = [:mobile]
And….That’s it. Now restart the rails server and we are done!
You can find the working application here on Github and take a look at commits.
P.S. You can use any custom field instead of
01 Apr 2020
I suddenly started facing this issue one fine morning when I tried to use a well maintained gem in a rails app. There was absolutely nothing changed per say anywhere in the codebase since I did last commit. The build passed on CI server.
I tried stumbling around for a solution but couldn’t figure out. I tried couple of solutions one by one mentioned below form StackOverflow, Github issues and other forums:
http in Gemfile source URL
- Try to update gem
gem update --system
- Updated RVM to latest
ruby -ropen-uri -e 'eval open("https://git.io/vQhWq").read as per RVM doc to troubleshoot the issue but end up with following error
I tried it with different apps on my machine with different ruby and rails versions but same error.
Suddenly there is a message from inside that there must be problem with the internet. That unfortunate day my broadband network was down. I was using a hotspot from my mobile. I tried with my wife’s mobile as well but no luck. Both were using same service provider.
In the evening after spending hours, I managed to get the broadband connection back. I tried to install gem again and voila!!! The problem absolutely did not exist.
So first check your internet connection before looking into other solutions.