Keep Track on Coverage

Recently I discovered Danger, an amazing tool you should check out no matter what. I can write a ton of use cases that serves me on my day to day work, but let’s start with one which I like a lot. Do you know how much of your code is covered by tests? Do you keep track on how your code coverage changes over time ? I didn’t till I installed a simple danger plugin called ‘danger-simplecov_json’, It’s a ruby gem it’s configuration is super easy (check this link to the gem), Once you configure Danger on your CI or locally, you can see after each build (spec run or whatever you use) the percentage of code coverage. ...

January 21, 2020 · 1 min · Chen Kinnrot

Building your own rails form builder

If you’re building forms with rails, whether you’re using a gem for it or working with pure rails forms, you should know this. Rails uses form builder to allow you to call all the standard label/input/select methods, the exact class name is ActionView::Helpers::FormBuilder When calling ‘form_for’ you get a fresh instance of this FormBuilder which allows you to define your form elements. Lets say you wanna add another reusable form element, for example a form section with title that uses your own custom style/classes. ...

August 7, 2019 · 2 min · Chen Kinnrot

Android Lifecycle Aware Modal

Sometimes we want to show the user an alert when somethings wrong or we just need to give some extra info, For example; Ask the user if he is sure he wanna leave the app. This can be achieved with the following code (runs inside activity): AlertDialog.Builder(this) .setMessage("Are you sure you want to exit?") .setCancelable(false) .setPositiveButton("Yes", object:DialogInterface.OnClickListener() { fun onClick(dialog:DialogInterface, id:Int) { this@YourActivity.finish() } }) .setNegativeButton("No", null) .show() This works fine, buy there is one annoying issue, If user clicks home button while dialog displayed, and go back to the app, the dialog will still be there. Now your user experience is seeing a question about getting out of the app while he just went in. ...

October 25, 2018 · 2 min · Chen Kinnrot

Live Data Pitfall You Should Be Aware Of

When working with MutableLiveData you can update the observable value in 2 ways: setValue postValue Both will update the live data value as expected as long as your code is running from the main thread. If you need to update a value from other thread you can use the postValue which is thread safe, and will make sure to notify observers on main thread. This is all nice, but be aware! ...

October 22, 2018 · 2 min · Chen Kinnrot

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