Choosing the Right WordPress Hosting Service

I needed to choose WordPress hosting service for some of clients and decided to do some research to figure out what’s best value for each client needs. There are many service providers in this area, After lots of googling I decided to focus on the following: WordPress BlueHost Kinsta WordPress If you’re building a new site/blog without any technical knowledge, WordPress is the right place for you, owned by the official word press organization offering limited capabilities cheap plans, and more expensive plans with more options like upload a custom theme, and charging money via paypal. ...

September 10, 2018 · 2 min · Chen Kinnrot

From jQuery to Stimulus

I tried to build an SPA without a shiny client side framework, I wanted to build something fast with good user experience and keeping it as simple as possible. I decided to take rails, use turbolinks and a avoid javascript till its a must. It didn’t take more than a few hours and I found myself writing javascript. What I needed to do is simple, I had an input with number, and 2 buttons next to it, one to increase values by 1 and on to decrease it looked like this: ...

May 22, 2018 · 4 min · Chen Kinnrot

Ruby async await

There is a lot of buzz about asyc await from the javascript world, the concept is very simple and make your code much more readable. You want to execute something without blocking the main thread but you want the next line of code to run once the non blocking code finish, meaning continue code execution in its written order. Ruby has a great concurrency gem which basically encapsulate low level threading and synchronization code to common patterns like Future, Promise, Actor and much more. ...

August 8, 2017 · 3 min · Chen Kinnrot

Octopress 101

I decided to develop my own blog like all the other cool developers. If you got here, this is what I got so far, it’s not too much, but it’s a start. When I develop something my rules are very simple Avoid writing any code. Keep it simple. Easy to deploy on free hosting environment. Decent code syntax highlight So I heard(mostly in www) people talking about jekyll as a static web site generator and began to dig dipper, I searched a few ruby gems for blogging and found a gem called [octopress](https://github.com/octopress/octopress octopress v3). They, the guys who developed it, calls it Jekyll’s Ferrari, sounds good to me, looked pretty straight forward so I gave it a spin. ...

July 25, 2017 · 3 min · Chen Kinnrot

Watch out for reference duplication instead of instance duplication

# This code will generate 96 instancesViewStatData = Struct.new(:total, :target, :ratio)96.times.map {|_|ViewStatData.new(0, 0, 0)}# And this will not, it’ll generate 96 pointers[ViewStatData.new(0, 0, 0)] * 96# So Watch out!!!

July 18, 2017 · 1 min · Chen Kinnrot

Ruby Lazy chunked hash like behavior

When we want to iterate a long list, we can simply write a query and get a cursor, ActiveRecord will do all the heavy lifting for us. What happens when we need to do some complicated computations on a set of data, which sometimes can be too big to be stored in memory for the entire computing process? This is when we need to start being more creational. I’d like to introduce what I came up with. The problem: - Complex calculation on time based data series for a period of 3 months. - Each calculation may depends on previous one and on future and past data. - Must be in order. - When fetching all data server crash on memory. The solution: I wanted to do the most minor code change possible, and currently the data was accessed via a hash. I decided to encapsulate the hash with something I called lazy chunked hash (tried google it see it as standard behavior in clojure). It looks like this: class ValuesProvider def initialize() @loaded_date = nil @hash = Hash.new(0) end def [](time_slot) get(time_slot) end private def get(time_slot) relevant_date = time_slot.to_date unless relevant_date == @loaded_date load(relevant_date) end @hash[time_slot.to_i] endend Pretty simple and does the work, instead of loading the data all at once, the data is being loaded for each day separately, this way we keep it chunky but not too chunky. And best part, my code that consume the data, didn’t change because of the [] method, which makes my ValueProvider behave like an array. This solution is good when the consumer data request(call for[]) implies on what data should be loaded, which most of the times will, but in some cases it won’t)

June 5, 2017 · 2 min · Chen Kinnrot

Rubymine on OSX memory issues

I found this only today, you should run Rubymine as 32 bit process. It works much faster and consume half the memory. To set this got to the Applications folder right click on rubymine->get info and check the “open in 32 bit mode” That’s all!

January 6, 2015 · 1 min · Chen Kinnrot

Use FactoryGirl And Faker for easy data generation in unit testing (Part1)

The most irritating thing in writing tests is the data generation preparation process, sometimes you want to create an object with 20 fields that 10 of them are mandatory but you only care about the value of 1, and you don’t want to mock, cause you interact with other methods and object that fetch this model from db. To me it happens a lot so I found the FactoryGirl + Faker combination that made my life much more easy and now I can write tests in peace. To add them just put in Gemfile: gem “factory_girl_rails”, “~> 4.0” gem “faker” So lets take a complex sample to explain all there is to know. We have a User, the User belongs to a Company, User has many tasks. Company has many irritating mandatory fields Lets define the Company Factory: FactoryGirl.define do factory :company do name {Faker::Name.name} trp {Faker::Number.between(0,10)} grp {Faker::Number.between(0,5)} budget {Faker::Number.number(4)} cpm {Faker::Number.between(1,70)} trp_price {Faker::Number.between(100,700)} viewer {Faker::Number.between(0,100000)} total_viewer {Faker::Number.between(0,200000)} unique_viewer {Faker::Number.between(0,50000)} spots {Faker::Number.between(0,1000)} end end As you can see I define lots of fields with random values. Now we can create a company by writing create(:company)Or just build one (without save to db) by calling build(:company) That’s all for now, I’ll continue in part2.

November 15, 2014 · 1 min · Chen Kinnrot

Get the user locale from http headers

If you want to provide default localization support for guest user in your website yo can locate their browser locale by the following code: def extract_locale_from_header unless request.env[‘HTTP_ACCEPT_LANGUAGE’].nil? return request.env[‘HTTP_ACCEPT_LANGUAGE’].scan(/^[a-z]{2}/).first end ‘en’ end This way you can determine on server side the locale of the user currently entered your site.

November 15, 2014 · 1 min · Chen Kinnrot

Dedicating a DJ(Delayed job) worker to a specific queue in heroku.

Let’s say you have a vey important procedure that takes a while, and you need to process it in background, but you still want to execute ASAP. I’m using Delayed Job on Heroku, and could not find a lot of tutorials to do this simple task. So here is the simplest way to achieve this ability, you can raise a process/daemon that will have only one queue to work on. (Dealyed job worker by default is queue agnostic, just process all jobs) In procfile: urgentworker: QUEUE=urgent bundle exec rake jobs:work You can call the worker in any name you want and even define multiple workers for multiple queues. And in the “urgent” job just define the queue name to be “urgent” the worker will process only jobs in this queue. example: handle_asynchronously :some_job, :queue => “urgent’ This will also work for Resque. Notice that for rescue you can write QUEUE=* but for delayed job you can’t.

November 15, 2014 · 1 min · Chen Kinnrot