Highlighting text in Ruby ### Start code def highlight(text,search_string) keywords = search_string.squeeze.strip.split(” “).compact.uniq matcher = Regexp.new( ‘(‘ + keywords.join(“|”) + ‘)’ ) highlighted = text.gsub(matcher) { |match| “<b>#{match}</b>” } return highlighted end text = “This is an example of the text.” search = “example text” puts highlight(text,search) # => This is an <b>example</b> of the… Read More


DeepDetect Client Rails Example Requirements Ubuntu 14.04 or Ubuntu 16.04 Rails 5+ Ruby 2.2+ Redis Install DeepDetect Install dependencies: sudo apt-get install build-essential libgoogle-glog-dev libgflags-dev libeigen3-dev libopencv-dev libcppnetlib-dev libboost-dev libboost-iostreams-dev libcurlpp-dev libcurl4-openssl-dev protobuf-compiler libopenblas-dev libhdf5-dev libprotobuf-dev libleveldb-dev libsnappy-dev liblmdb-dev libutfcpp-dev cmake libgoogle-perftools-dev unzip Clone & build deepdetect: cd && mkdir Projects && git clone git@github.com:beniz/deepdetect.git… Read More


UUIDs (Universally unique identifiers) are really neat as IDs, and they allow you to have the ID of a model before it is even saved and guarantee that it won’t be fail insertion due to the ID being taken already. They’re also a full class type in PostgreSQL which is even more badass because it… Read More


Building the Perfect Rails 5 API Only App Thanks to the new rails-api gem that ships as part of the Rails 5 core, Rails is now an ideal candidate for building streamlined APIs quickly and easily. Until now, arguably the best option for creating APIs in Ruby has been Grape, and while Grape is still… Read More


UUID’s I love UUID’s. You should use them. Rails 4 makes it simple to get setup and use UUID’s throughout your project. First, we enable UUID’s: rails g migration enable_uuid_extension This creates the following migration: class EnableUuidExtension < ActiveRecord::Migration def change enable_extension ‘uuid-ossp’ end end Next, create a model rails g model Book title The… Read More