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

Overriding default id in mongoid

This is an easy one, just want to make sure it’s clear. Add the following field to your model: field :_id, type: Moped::BSON::ObjectId And to allow setting it: 1 def id=(id) 2 self[:_id] = id 3 end Now you can just do obj.id=[Some ObjectId] and save the object.

November 15, 2014 · 1 min · Chen Kinnrot

Nice post about cyber war

Popular Science: The War Of Zeros And Ones. http://google.com/newsstand/s/CBIwvZm5zho

October 5, 2014 · 1 min · Chen Kinnrot

ClusteTV is hiring

Cluster TV is looking for it's next programmer/Superstar! If you can: * Write code like an Effin' machine* Test your OWN code* Speak English like it's your mother's tongue* Handle challenges* Be self-driven & independent We would also appreciate if you'll have: * Great communications skills* Independent thinking* Passion to learn new things* RoR or Angular experience* Coffee script knowledge* NOSQL understanding Then we want you! What we offer: * Great and professional team.* Opportunity to become an integral part of an innovative TV solution.* A chance to learn from the best in the industry.* Full time job in the Tel Aviv area.* Unlimited supply of food and beer. Really.* Flexible work hours. If you like what you see and have da skillz, drop us an email at chen@clustertv.com Or, call me tel: +972 542124335. Good luck!

August 8, 2014 · 1 min · Chen Kinnrot

Karma Rails Angular Jasmine testing - set up in 5 minutes

It took me about an hours and a half because google is not up to date, so here it is: First - as a rails developer, if you don’t have node.js, this is the time to install it. If you don’t use RubyMine as you IDE, I recommend it as well, but whatever you prefer is fine by me. Here you’ll fins instructions about karma installation, follow them carefully. You’ll see that you need to tell karma where is your sources and test sources. I’m working with jasmine, and using angular as a gem, check my configuration: frameworks: [‘jasmine’], // list of files / patterns to load in the browser files: [ //libs ‘http://0.0.0.0:3000/assets/application.js’, ’/Users/chen/.rvm/gems/ruby-1.9.3-p448/gems/angularjs-rails-1.2.9/vendor/assets/javascripts/angular-mocks.js’, ‘spec/javascripts/controllers/sample.js’, ‘spec/javascripts/controllers//_spec.js.coffee’, ‘spec/javascripts/controllers//*_spec.js.coffee’, ‘spec/javascripts/controllers//_spec.coffee’, ‘spec/javascripts/controllers/**/_spec.js’ ] To things you should notice: 1. I use rails assets pipeline to give all my app code js, (just run your server before you test) 2. I add the angular mocks lib All other stuff are basic, I got code in coffee and js so needed a little more lines to find all my tests. this is the way to make this work pretty fast.

February 2, 2014 · 1 min · Chen Kinnrot

Export Hebrew (or any non english language) with php to excel

I found it very annoying that php data to excel is not so straight forward as one might think ,lots of wrong stuff here. The thing is, as a developer you don’t know a lot about encoding. So you don’t really think about it until you have bugs, than you start searching for a better solution, I found this. Meaning you manually convert encoding to support excel, and add BOM. Just wanted to gather a few links together for future use. Enjoy.

January 12, 2014 · 1 min · Chen Kinnrot

Home Base SDK

As a developer@widdit’s incredible android team, I decided to write a how to embed Widdit’s home base sdk in 5 minutes guide, so here it is: Step 1: go to widdit.com and create an account. Step 2: create your first home base in the home base section at widdit site. step 3: go to sdk’s tab and follow the installation instructions step 4: upload your new apk to the market step 5: make money! Good luck.

January 28, 2013 · 1 min · Chen Kinnrot