Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 PROGRAMMING


  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...

7,556 0       TUTORIAL RUBY DSL


  Difference between keystore and truststore

Security has become a vital concern in most of the online transactions nowadays. Lots of the world's most popular websites have adopted security protocols to transfer data, especially sensitive data. These security protocols including SSL/TLS which are using the private/public key exchange mechanism to establish secure connections. The private/public key cryptography is a really important invention and it allows data to be transferred securely and solves the big problem of transferring symmetric key securely over Internet at the same time. Because of this characteristic, private...

7,017 0       TRUSTSTORE KEYSTORE SSL SECURITY


  Carriage return and line feed

In programming and document editing, we may frequently encounter carriage return and line feed, i.e the well known CRLF.  But do you know about the history and difference of carriage return and line feed?Before computer came out, there was a type of teleprinter called Teletype Model 33. It can print 10 characters each second. But there is one problem with this, after finishing printing each line, it will take 0.2 second to move to next line, which is time of printing 2 characters. If a new character is transferred during this 0.2 second, then this new character will be lost.So scientists ...

12,120 0       CR CARRIAGE RETURN LINE FEED LF NEW LINE CRLF


  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...

3,851 0       RUBY EXCLAMATION MARK DOWNCASE


  Top 10 WhatsApp Tips & Tricks To Try in 2017

v\:* {behavior:url(#default#VML);}o\:* {behavior:url(#default#VML);}w\:* {behavior:url(#default#VML);}.shape {behavior:url(#default#VML);} Normal 0 false false false false EN-US X-NONE X-NONE

3,964 1      


  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...

9,636 0       RUBY UNIT TESTING RSPEC CHEFSPEC SHELL_OUT


  Ruby net-scp cannot scp multiple files with asterisk(*)

net-ssh/net-scp is a Ruby gem which can be used to scp files between different *nix machines. It's similar to how the *nix scp command. It can be used to scp a file or a directory. However, it seems it has some problem to scp multiple files using pattern *.For example, below script is supposed to download all files from remote directory to local directory:require 'net/scp'host = 'testmachine'login = 'testaccount'password = "testpassword"remote_path = '/tmp/remote_dir/*'Net::SCP.start(host, login, :password => password) do |scp| scp.download(remote_path, '.')endThe...

5,110 7       RUBY NET-SCP ASTERISK MULTIPLE FILES


  Resolve stylesheet_link_tag fails to work in Ruby on Rails

When developing Ruby On Rails application, developers sometimes will see an unexpected behavior where the application cannot be loaded due to "TypeError: Object doesn't support this property or method" when invoking stylesheet_link_tag. The symptom looks like And the Rails log will show something similar to belowThe error occurs because there is some problem finding the correct assets which are located in app/assets. To resolve the issue, you can following below steps.Add gem 'coffee-script-source', '1.8.0' into Gemfile and run bundle install thenRun bundle update coffee-script-sourceRest...

10,133 2       RUBY ON RAILS STYLESHEET_LINK_TAG JAVASCRIPT_INCLUDE_TAG TYPEERROR