ALL
A plugin to update last_error in Delayed Job
delayed_job is a process based asynchronous task processing gem which can be ran at background. It will fork the specified number of processes to execute the tasks asynchronously. The task status is usually stored in the database so that it can be easily integrated into a Rails application where asynchronous job execution is desired.Normally when a job fails to execute or error occurs, it would save the error into the database with the column last_error. Ideally all these will be handled by the delayed_job gem itself, we no need to worry about anything. However, in some extreme cases, we ...
4,044 0 RUBY RUBY ON RAILS DELAYED JOB LAST_ERROR
Handle NXDomain error when resolving IP address in Ruby DNS resolver
In another post, we covered how to resolve SystemStackError when resolving IP address in Ruby. In this post, we would cover another common issue where a NXDomain error is returned when resolving an IP address. The NXDomain error means that the queried domain name does not exist in the DNS.In Ruby, DNS resolver library will use /etc/resolv.conf by default get the name servers to resolve the domain name. There are multiple DNS name servers can be specified in /etc/resolv.conf with below format.nameserver nameserver nameserver ...By default, only the top MAXNS name servers(3 in Linux by...
4,534 0 RUBY RUBY ON RAILS NETWORK DNS NXDOMAIN
Resolve SystemStackError issue when resolving IP address in Ruby
In Ruby, Resolv is the default DNS resolution implementation. It can be used to resolve IP address of a hostname. To use it, one just needs to require 'resolv' in the code. But sometimes, a user would want to check /etc/hosts first or some other mechanisms to resolve an IP address. In this case, one can require 'resolv-replace' and then replace the default DNS resolvers with customized DNS resolvers.For example, using resolv-replace, one would writerequire 'resolv-replace'Resolv::DefaultResolver.replace_resolvers([Resolv::Hosts.new, Resolv::DNS.new])Resolv.getaddress 'some-site.com'In this cas...
5,736 0 RUBY RUBY ON RAILS NETWORK
Ruby WinRM undefined method `split' for nil:NilClass
WinRM service is a service provided by Windows to enable remote access a Windows system. It is similar to what SSH is for *nix. And it is frequently used in applications which want to automate process or accessing remote Windows system and perform actions on them. Ruby also provided the WinRM gem which is an implementation of the WinRM service. When using WinRM gem, one may often want to use :negotiate as the transport protocol for authentication. This transport will negotiate using different security mechanisms depends on the setting. These mechanisms include Kerberos, NTLM, Basic e...
Fix issue "cannot load such file -- bcrypt_ext (LoadError)"
bcrypt() is a sophisticated and secure hash algorithm designed by The OpenBSD project for hashing passwords. The bcrypt Ruby gem provides a simple wrapper for safely handling passwords.However, sometimes the rails application would fail to start after installing the bcrypt gem on Windows. The error would look similar to below.The issue is that it fails to load the bcrypt_ext which is the native built extension, the reason may be the library is wrongly built. To fix this issue, below steps can be followed. Open a command consolecd to the gem directory C:\RailsInstaller\Ruby2.2.0\...
9,289 1 RUBY SOLUTION RUBY ON RAILS BCRYPT LOAD ERROR
How to write your own DSL in Ruby
DSL(Domain Specific Language) is a language defined to fulfill some domain specific requirements to ease people's work. It can be used to define attributes and actions of a domain easily and cleanly. And it is often created based on some common observations or micro patterns of some domain.In Ruby world, there are quite a few places people can find DSL. For example, Ruby itself, Chef recipes.To create a class in Ruby, the traditional OOP way would look like.class User @name = nil @email = nil def name @name end def name=(val) @name = val end def email @email end def email=(va...
Use downcase! with caution in Ruby
Ruby provides ! to change state of some object in place. Hence if you see some functions have ! appended, it means the state of the caller of the function is expected to be changed. This is a very interesting Ruby feature. But sometimes one should be cautious when using this kind of functions because you would get unexpected behavior if using improperly.Let's take an example of String#downcase!. According to the documentation.Downcases the contents of str, returning nil if no changes were made. Note: case replacement is effective only in ASCII region.If there is a String pl...
4,161 0 RUBY EXCLAMATION MARK DOWNCASE
Stub Mixlib::ShellOut and shell_out in Ruby unit testing
Unit testing is part of software development to ensure the tiny component of a function can work as designed. Different frameworks and tools can be used to run unit testing for different programming languages. In Ruby, one popular unit testing framework is Rspec, or Chefspec if you are writing Chef recipes.While writing Chef recipes, some low level commands(DOS commands or shell commands) need to be executed on the managed resource to perform actions or gather information. For example, listing directory and files on an Unix system using ls command. Mixlib-Shellout can be used to execute o...
10,255 0 RUBY UNIT TESTING RSPEC CHEFSPEC SHELL_OUT