tag:blogger.com,1999:blog-89088294525165734892022-08-15T10:42:45.470-07:00https://kinnrot.github.io - Chen Kinnrot - Keep it simple - go to kinnrot.github.ioMy new blog is at https://kinnrot.github.ioAnonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.comBlogger47125tag:blogger.com,1999:blog-8908829452516573489.post-21602059278896256512017-07-18T04:42:00.003-07:002017-07-18T04:49:45.290-07:00Watch out for reference duplication instead of instance duplication<br />
<pre style="background-color: #2b2b2b; color: #c7bab9; font-family: 'mononoki'; font-size: 11.3pt;"><span style="color: white;"># This code will generate 96 instances</span></pre>
<pre style="background-color: #2b2b2b; color: #c7bab9; font-family: 'mononoki'; font-size: 11.3pt;"><span style="color: white;">ViewStatData </span><span style="color: #cc7833;">= </span><span style="color: #6d9cbe;">Struct</span>.new(<span style="color: #6d9cbe;">:</span><span style="background-color: #283b5e; color: #6d9cbe;">total</span>, <span style="color: #6d9cbe;">:target</span>, <span style="color: #6d9cbe;">:ratio</span>)</pre>
<pre style="background-color: #2b2b2b; color: #c7bab9; font-family: 'mononoki'; font-size: 11.3pt;"><pre style="font-family: mononoki; font-size: 11.3pt;"><span style="color: #a5c261;">96</span>.times.map {<span style="color: #cc7833;">|</span>_<span style="color: #cc7833;">|</span><span style="color: #6d9cbe;">ViewStatData</span>.new(<span style="color: #a5c261;">0</span>, <span style="color: #a5c261;">0</span>, <span style="color: #a5c261;">0</span>)}</pre>
<pre style="font-family: mononoki; font-size: 11.3pt;"></pre>
<pre style="font-family: mononoki; font-size: 11.3pt;"># And this will not, it'll generate 96 pointers</pre>
<pre style="font-family: mononoki; font-size: 11.3pt;"><pre style="font-family: mononoki; font-size: 11.3pt;"><span style="color: #6d9cbe;">[ViewStatData</span>.new(<span style="color: #a5c261;">0</span>, <span style="color: #a5c261;">0</span>, <span style="color: #a5c261;">0</span>)] * 96</pre>
<pre style="font-family: mononoki; font-size: 11.3pt;"># So Watch out!!!</pre>
</pre>
</pre>
Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-198824981987277422017-06-05T05:11:00.001-07:002017-06-05T05:11:10.286-07:00Ruby Lazy chunked hash like behavior<span style="font-family: Courier New, Courier, monospace;">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.</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">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?</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">This is when we need to start being more creational.</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">I'd like to introduce what I came up with.</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">The problem:</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">- Complex calculation on time based data series for a period of 3 months.</span><br />
<span style="font-family: Courier New, Courier, monospace;">- Each calculation may depends on previous one and on future and past data.</span><br />
<span style="font-family: Courier New, Courier, monospace;">- Must be in order.</span><br />
<span style="font-family: Courier New, Courier, monospace;">- When fetching all data server crash on memory.</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">The solution:</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">I wanted to do the most minor code change possible, and currently the data was accessed via a hash. </span><br />
<span style="font-family: Courier New, Courier, monospace;">I decided to encapsulate the hash with something I called lazy chunked hash (tried google it see it as standard behavior in clojure).</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">It looks like this:</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<pre style="background-color: #2b2b2b; color: #e6e1dc; font-family: 'mononoki'; font-size: 11.3pt;"><span style="color: #cc7833;">class </span><span style="color: white;">ValuesProvider</span><span style="color: white;"> </span><span style="color: #cc7833;">def </span><span style="color: #ffc66d;">initialize</span>()
<span style="color: #d0d0ff;">@loaded_date </span><span style="color: #cc7833;">= nil</span></pre>
<pre style="background-color: #2b2b2b; color: #e6e1dc; font-family: 'mononoki'; font-size: 11.3pt;"><pre style="font-family: mononoki; font-size: 11.3pt;"><span style="background-color: #3c3c57; color: #d0d0ff;"> @hash</span><span style="color: #d0d0ff;"> </span><span style="color: #cc7833;">= </span><span style="color: #6d9cbe;">Hash</span>.new(<span style="color: #a5c261;">0</span>)</pre>
<span style="color: #cc7833;"> end</span><span style="color: #cc7833;">
</span><span style="color: #cc7833;"> def </span><span style="color: #ffc66d;">[]</span>(time_slot)
get(time_slot)
<span style="color: #cc7833;">end</span><span style="color: #cc7833;">
</span><span style="color: #cc7833;"> private</span><span style="color: #cc7833;">
</span><span style="color: #cc7833;"> def </span><span style="color: #ffc66d;">get</span>(time_slot)
<span style="color: #d0d0ff;">relevant_date </span><span style="color: #cc7833;">= </span>time_slot.to_date
<span style="color: #cc7833;">unless </span><span style="color: #d0d0ff;">relevant_date </span><span style="color: #cc7833;">== </span><span style="color: #d0d0ff;">@loaded_date</span><span style="color: #d0d0ff;"> </span>load(<span style="color: #d0d0ff;">relevant_date</span>)
<span style="color: #cc7833;">end</span><span style="color: #cc7833;">
</span><span style="color: #cc7833;"> </span><span style="color: #d0d0ff;">@hash</span>[time_slot.to_i]
<span style="color: #cc7833;">end</span></pre>
<pre style="background-color: #2b2b2b; color: #e6e1dc; font-family: 'mononoki'; font-size: 11.3pt;"><span style="color: #cc7833;">end</span></pre>
<br />
<span style="font-family: Courier New, Courier, monospace;">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.</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">And best part, my code that consume the data, didn't change because of the [] method, which makes my ValueProvider behave like an array. </span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">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)</span><br />
<br />Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-38785502714010096422015-01-06T13:32:00.001-08:002015-01-06T13:32:50.639-08:00Rubymine on OSX memory issuesI found this only today, you should run Rubymine as 32 bit process.<br />
It works much faster and consume half the memory.<br />
<br />
To set this got to the Applicaitons folder right click on rubymine->get info and check the "open in 32 bit mode"<br />
<br />
Thats all!<br />
<br />Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-2845023071797313032014-11-15T07:52:00.001-08:002014-11-15T07:52:28.548-08:00Use 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.<br />
<br />
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.<br />
<br />
To add them just put in Gemfile:<br />
<br />
gem "factory_girl_rails", "~> 4.0"<br />
gem "faker"<br />
<br />
So lets take a complex sample to explain all there is to know.<br />
<br />
We have a User, the User belongs to a Company, User has many tasks.<br />
<br />
Company has many irritating mandatory fields<br />
<br />
Lets define the Company Factory:<br />
<br />
<pre style="background-color: #2b2b2b; border: 0.01mm solid rgb(0, 0, 0); font-size: 12pt; line-height: 100%;"><span style="color: #6d9cbe;">FactoryGirl</span><span style="color: #e6e1dc;">.define </span><span style="color: #cc7833;">do
</span><span style="color: #e6e1dc;"> factory </span><span style="color: #6d9cbe;">:company</span><span style="color: #e6e1dc;"> </span><span style="color: #cc7833;">do
</span><span style="color: #e6e1dc;"> name {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Name</span><span style="color: #e6e1dc;">.name}
trp {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Number</span><span style="color: #e6e1dc;">.between(</span><span style="color: #a5c261;">0</span><span style="color: #e6e1dc;">,</span><span style="color: #a5c261;">10</span><span style="color: #e6e1dc;">)}
grp {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Number</span><span style="color: #e6e1dc;">.between(</span><span style="color: #a5c261;">0</span><span style="color: #e6e1dc;">,</span><span style="color: #a5c261;">5</span><span style="color: #e6e1dc;">)}
budget {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Number</span><span style="color: #e6e1dc;">.number(</span><span style="color: #a5c261;">4</span><span style="color: #e6e1dc;">)}
cpm {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Number</span><span style="color: #e6e1dc;">.between(</span><span style="color: #a5c261;">1</span><span style="color: #e6e1dc;">,</span><span style="color: #a5c261;">70</span><span style="color: #e6e1dc;">)}
trp_price {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Number</span><span style="color: #e6e1dc;">.between(</span><span style="color: #a5c261;">100</span><span style="color: #e6e1dc;">,</span><span style="color: #a5c261;">700</span><span style="color: #e6e1dc;">)}
viewer {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Number</span><span style="color: #e6e1dc;">.between(</span><span style="color: #a5c261;">0</span><span style="color: #e6e1dc;">,</span><span style="color: #a5c261;">100000</span><span style="color: #e6e1dc;">)}
total_viewer {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Number</span><span style="color: #e6e1dc;">.between(</span><span style="color: #a5c261;">0</span><span style="color: #e6e1dc;">,</span><span style="color: #a5c261;">200000</span><span style="color: #e6e1dc;">)}
unique_viewer {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Number</span><span style="color: #e6e1dc;">.between(</span><span style="color: #a5c261;">0</span><span style="color: #e6e1dc;">,</span><span style="color: #a5c261;">50000</span><span style="color: #e6e1dc;">)}
spots {</span><span style="color: #6d9cbe;">Faker</span><span style="color: #e6e1dc;">::</span><span style="color: #6d9cbe;">Number</span><span style="color: #e6e1dc;">.between(</span><span style="color: #a5c261;">0</span><span style="color: #e6e1dc;">,</span><span style="color: #a5c261;">1000</span><span style="color: #e6e1dc;">)}
</span><span style="color: #cc7833;">end
</span><span style="color: #e6e1dc;"> </span><span style="color: #cc7833;">end</span></pre>
<br />
As you can see I define lots of fields with random values.<br />
<br />
Now we can create a company by writing<br />
<blockquote class="tr_bq">
create(:company)</blockquote>
Or just build one (without save to db) by calling<br />
<br />
<blockquote class="tr_bq">
build(:company) </blockquote>
<br />
That's all for now, I'll continue in part2.<br />
<blockquote class="tr_bq">
</blockquote>
<blockquote class="tr_bq">
</blockquote>
Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-76430802983440450092014-11-15T07:42:00.001-08:002014-11-15T07:42:21.105-08:00Get the user locale from http headersIf you want to provide default localization support for guest user in your website yo can locate their browser locale by the following code:<br />
<br />
<br />
<pre style="background-color: #2b2b2b; border-color: #000000; border-style: solid; border-width: 0.01mm; font-family: monospace; font-size: 14pt; line-height: 100%; padding: 4px;"><pre style="border: 0.01mm solid rgb(0, 0, 0); font-size: 12pt; line-height: 100%;"><span style="color: #cc7833;">def</span><span style="color: #e6e1dc;"> extract_locale_from_header
</span><span style="color: #cc7833;">unless</span><span style="color: #e6e1dc;"> request.env[</span><span style="color: #a5c261;">'HTTP_ACCEPT_LANGUAGE'</span><span style="color: #e6e1dc;">].nil?
</span><span style="color: #cc7833;">return</span><span style="color: #e6e1dc;"> request.env[</span><span style="color: #a5c261;">'HTTP_ACCEPT_LANGUAGE'</span><span style="color: #e6e1dc;">].scan(</span><span style="color: #a5c261;">/</span><span style="color: #e6e1dc;">^[a-z]{2}</span><span style="color: #a5c261;">/</span><span style="color: #e6e1dc;">).first
</span><span style="color: #cc7833;">end
</span><span style="color: #e6e1dc;"> </span><span style="color: #a5c261;">'en'
</span><span style="color: #e6e1dc;"> </span><span style="color: #cc7833;">end</span></pre>
</pre>
<br />
This way you can determine on server side the locale of the user currently entered your site.Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-19488178470410716382014-11-15T07:34:00.002-08:002014-11-15T07:35:37.413-08:00Dedicating 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.<br />
<br />
I'm using Delayed Job on Heroku, and could not find a lot of tutorials to do this simple task.<br />
<br />
So here is the simplest way to achieve this ability, you can raise a process/deamon that will have only one queue to work on. (Dealyed job worker by default is queue agnostic, just process all jobs)<br />
<br />
In procfile:<br />
<br />
<blockquote class="tr_bq">
urgentworker: QUEUE=urgent bundle exec rake jobs:work</blockquote>
<br />
You can call the worker in any name you want and even define multiple workers for multiple queues.<br />
And in the "urgent" job just define the queue name to be "urgent" the worker will process only jobs in this queue.<br />
<br />
example:<br />
<br />
<blockquote class="tr_bq">
handle_asynchronously :some_job, :queue => "urgent'</blockquote>
<br />
This will also work for Resque.<br />
<br />
Notice that for rescue you can write QUEUE=* <b>but for delayed job you can't.</b>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-40846656677640290322014-11-15T07:20:00.000-08:002014-11-15T07:20:24.581-08:00Overriding default id in mongoidThis is an easy one, just want to make sure it's clear.<br />
<br />
Add the following field to your model:<br />
<br />
<pre style="background-color: #2b2b2b; border-color: #000000; border-style: solid; border-width: 0.01mm; font-family: monospace; font-size: 14pt; line-height: 100%; padding: 4px;"><span style="background-color: #2b2b2b; color: #e6e1dc;">
</span></pre>
<pre style="background-color: #2b2b2b; border-color: #000000; border-style: solid; border-width: 0.01mm; font-family: monospace; font-size: 14pt; line-height: 100%; padding: 4px;"><span style="background-color: #2b2b2b; color: #e6e1dc;">field </span><span style="background-color: #2b2b2b; color: #6d9cbe;">:_id</span><span style="background-color: #2b2b2b; color: #e6e1dc;">, type: </span><span style="background-color: #2b2b2b; color: #6d9cbe;">Moped</span><span style="background-color: #2b2b2b; color: #e6e1dc;">::</span><span style="background-color: #2b2b2b; color: #6d9cbe;">BSON</span><span style="background-color: #2b2b2b; color: #e6e1dc;">::</span><span style="background-color: #2b2b2b; color: #6d9cbe;">ObjectId</span></pre>
<pre style="background-color: #2b2b2b; border-color: #000000; border-style: solid; border-width: 0.01mm; font-family: monospace; font-size: 14pt; line-height: 100%; padding: 4px;"></pre>
<pre style="background-color: #2b2b2b; border-color: #000000; border-style: solid; border-width: 0.01mm; font-family: monospace; font-size: 14pt; line-height: 100%; padding: 4px;"></pre>
<br />
And to allow setting it:<br />
<br />
<pre style="background-color: #2b2b2b; border-color: #000000; border-style: solid; border-width: 0.01mm; font-family: monospace; font-size: 14pt; line-height: 100%; padding: 4px;"><span style="background-color: #2b2b2b; color: #e6e1dc;">1 </span><span style="background-color: #2b2b2b; color: #cc7833;">def</span><span style="background-color: #2b2b2b; color: #e6e1dc;"> id=(id)
2 </span><span style="background-color: #2b2b2b; color: #cc7833;">self</span><span style="background-color: #2b2b2b; color: #e6e1dc;">[</span><span style="background-color: #2b2b2b; color: #6d9cbe;">:_id</span><span style="background-color: #2b2b2b; color: #e6e1dc;">] </span><span style="background-color: #2b2b2b; color: #cc7833;">=</span><span style="background-color: #2b2b2b; color: #e6e1dc;"> id
3 </span><span style="background-color: #2b2b2b; color: #cc7833;">end</span></pre>
<br />
<br />
Now you can just do obj.id=[Some ObjectId] and save the object.<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-34967894017242519432014-10-05T00:42:00.001-07:002014-10-05T00:42:04.610-07:00Nice post about cyber warPopular Science: The War Of Zeros And Ones. http://google.com/newsstand/s/CBIwvZm5zhoAnonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-16806747784908112352014-08-08T07:40:00.000-07:002014-08-11T02:14:03.014-07:00ClusteTV is hiring<div dir="ltr" style="line-height: 1.15; margin-bottom: 0pt; margin-top: 0pt;">
<div class="p1">
Cluster TV is looking for it's next programmer/Superstar!</div>
<div class="p2">
<br /></div>
<div class="p1">
If you can:</div>
<div class="p2">
<br /></div>
<div class="p1">
* Write code like an Effin' machine</div>
<div class="p1">
* Test your OWN code</div>
<div class="p1">
* Speak English like it's your mother's tongue</div>
<div class="p1">
* Handle challenges</div>
<div class="p1">
* Be self-driven & independent</div>
<div class="p2">
<br /></div>
<div class="p2">
<br /></div>
<div class="p1">
We would also appreciate if you'll have:</div>
<div class="p2">
<br /></div>
<div class="p1">
* Great communications skills</div>
<div class="p1">
* Independent thinking</div>
<div class="p1">
* Passion to learn new things</div>
<div class="p1">
* RoR or Angular experience</div>
<div class="p1">
* Coffee script knowledge</div>
<div class="p1">
* NOSQL understanding</div>
<div class="p2">
<br /></div>
<div class="p1">
Then we want you!</div>
<div class="p2">
<br /></div>
<div class="p1">
What we offer:</div>
<div class="p2">
<br /></div>
<div class="p1">
* Great and professional team.</div>
<div class="p1">
* Opportunity to become an integral part of an innovative TV solution.</div>
<div class="p1">
* A chance to learn from the best in the industry.</div>
<div class="p1">
* Full time job in the Tel Aviv area.</div>
<div class="p1">
* Unlimited supply of food and beer. Really.</div>
<div class="p1">
* Flexible work hours.</div>
<div class="p2">
<br /></div>
<div class="p1">
If you like what you see and have da skillz, drop us an email at <a href="mailto:chen@clustertv.com">chen@clustertv.com</a><br />
Or, call me <a href="tel: +972 542124335" target="_blank">tel: +972 542124335</a><span style="line-height: 1.15;">.</span></div>
<div class="p2">
<br /></div>
<br />
<div class="p1">
Good luck!</div>
</div>
Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-19419718029597694752014-02-02T23:32:00.001-08:002014-02-02T23:32:50.546-08:00Karma Rails Angular Jasmine testing - set up in 5 minutesIt took me about an hours and a half because google is not up to date, so here it is:<br />
<br />
First - as a rails developer, if you don't have node.js, this is the time to <a href="http://nodejs.org/">install</a> it.<br />
If you don't use RubyMine as you IDE, I recommend it as well, but whatever you prefer is fine by me.<br />
<a href="http://www.jetbrains.com/ruby/webhelp/preparing-to-use-karma-test-runner.html">Here</a> you'll fins instructions about karma installation, follow them carefully.<br />
<br />
You'll see that you need to tell karma where is your sources and test sources.<br />
<br />
I'm working with jasmine, and using angular as a gem, check my configuration:<br />
<br />
frameworks: ['jasmine'],<br />
<br />
<br />
// list of files / patterns to load in the browser<br />
files: [<br />
//libs<br />
<br />
'http://0.0.0.0:3000/assets/application.js',<br />
<span style="background-color: yellow;">'/Users/chen/.rvm/gems/ruby-1.9.3-p448/gems/angularjs-rails-1.2.9/vendor/assets/javascripts/angular-mocks.js',</span><br />
'spec/javascripts/controllers/sample.js',<br />
<br />
'spec/javascripts/controllers/*/*_spec.js.coffee',<br />
'spec/javascripts/controllers/**/*_spec.js.coffee',<br />
'spec/javascripts/controllers/**/*_spec.coffee',<br />
'spec/javascripts/controllers/**/*_spec.js'<br />
]<br />
<br />
<br />
To things you should notice:<br />
1. I use rails assets pipeline to give all my app code js, (just run your server before you test)<br />
2. I add the angular mocks lib<br />
<br />
<br />
All other stuff are basic, I got code in coffee and js so needed a little more lines to find all my tests.<br />
<br />
this is the way to make this work pretty fast.<br />
<br />Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-35648590918709313172014-01-12T14:09:00.002-08:002014-01-12T14:09:52.550-08:00Export Hebrew (or any non english language) with php to excelI found it very annoying that php data to excel is not so straight forward as one might think <a href="http://stackoverflow.com/questions/15699301/export-mysql-data-to-excel-in-php">,lots of wrong stuff</a> here.<br />
<br />
The thing is, as a developer you don't know a lot about <a href="http://www.joelonsoftware.com/articles/Unicode.html">encoding</a>.<br />
<br />
So you don't really think about it until you have bugs, than you start searching for a better solution, I found <a href="http://stackoverflow.com/a/3466065/67505">this</a>.<br />
<br />
Meaning you manually convert encoding to support excel, and add <a href="http://en.wikipedia.org/wiki/Byte_order_mark">BOM</a>.<br />
<br />
Just wanted to gather a few links together for future use.<br />
<br />
Enjoy.<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-16240557998067624602013-01-28T06:10:00.001-08:002013-01-28T06:10:20.424-08:00Home Base SDKAs 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:<br />
<br />
<b>Step 1:</b><br />
go to widdit.com and create an account.<br />
<br />
<b>Step 2:</b><br />
create your first home base in the home base section at widdit site.<br />
<br />
<b>step 3: </b><br />
go to sdk's tab and follow the installation instructions<br />
<br />
<b>step 4:</b><br />
upload your new apk to the market<br />
<br />
<b>step 5:</b><br />
make money!<br />
<br />
Good luck.<br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-18495869490675035052012-12-05T06:02:00.003-08:002013-05-11T22:05:31.688-07:00SpineJS Tip<p dir=ltr>Never create multiple instances of a controller that generates the same view, cause you're event's registrations will be duplicated over and over again!</p>
Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-24050900668082293842012-09-26T09:40:00.001-07:002012-10-03T10:47:33.393-07:00Avoid usage of AsyncTask Class on android<div><p>Just noticed this method available from API 11 only, so you should find another implementation to avoid unexpected behaviour.</p>
<p>Or don't call the execute method,  why?  If you'll check documentation you'll see that in some versions of android all tasks will run synchronouslly on the same background thread and on some versions it'll run on a pool of threads. Always use the executeOnExecutor option for consistent behaviour between platform version and avoid unexpected behaviour.</p>
<p>See <a href="http://developer.android.com/reference/android/os/AsyncTask.html">docs</a><br></p>
</div>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-74691823246912941302012-08-31T01:05:00.001-07:002012-08-31T01:05:18.809-07:00Nice idea for what's new in my app<div><p>People probably don't read/understand what's new in an app when they update it. Skype did a very nice screen that shows you that something did <u>change</u></p>
<br/><img src='http://lh5.ggpht.com/-bYmkNttd2ag/UEBwPRS7gPI/AAAAAAAAGRA/3w6ThmzjH2c/Screenshot_2012-08-31-11-02-09.png' /></div>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0Tel Aviv, Tel Aviv32.06616 34.77782tag:blogger.com,1999:blog-8908829452516573489.post-89564885877804379292012-07-08T15:18:00.004-07:002012-07-08T15:18:46.983-07:00coffee-script is another piece of shitHi,<br />
<br />
A few months ago I discovered this new stuff called coffee script, and thought to myself, "this is awesome I'll write less and do more" Today, I tried to continue a development of a pretty fat client side and tried to find myself in the 1000 lines of code I wrote so far (not so many). It was pretty hard, and I'm the only programmer for now, can't imagine how a new programmer would enter to this project.<br />
<br />
<span style="background-color: white;">So...</span><br />
<span style="background-color: white;">coffee-script is </span><span style="background-color: white;">java-script that look better, no other benefits, and if you plan to write a little more than 200 lines of code, consider using some strongly typed language(that can generate debugable java script) with good IDE that'll help you maintain your code. </span>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-22533491485299668802012-07-07T09:27:00.003-07:002013-05-11T22:05:28.755-07:00php post response script executionI guess it's nice to have so here you go<br />
<br />
<br />
<pre class="lang-php prettyprint" style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; text-align: left; vertical-align: baseline; width: auto;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="com" style="background-color: transparent; border: 0px; color: grey; margin: 0px; padding: 0px; vertical-align: baseline;">/*
* basically allow a php script to return a response and continue with
* code execution, good for statistics.
* before echo anything to user call begin and after call end, than you can continue doing stuff
*/</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">class</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">ScriptContinuationManager</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="com" style="background-color: transparent; border: 0px; color: grey; margin: 0px; padding: 0px; vertical-align: baseline;">/**
* this is the point where we need to give a sign to this class
* that we wanna write our response.
* @return void
*/</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">public</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">function</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> beginRespone</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">()</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
ob_end_clean</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">();</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
header</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"Connection: close"</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">);</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
ignore_user_abort</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">();</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="com" style="background-color: transparent; border: 0px; color: grey; margin: 0px; padding: 0px; vertical-align: baseline;">// optional</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
ob_start</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">();</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="com" style="background-color: transparent; border: 0px; color: grey; margin: 0px; padding: 0px; vertical-align: baseline;">/*
* after this function execution the response will be sent to the
* client, and code continue without client need to wait.
*/</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">public</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">function</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> endResponse</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">()</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
$size </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> ob_get_length</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">();</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
header</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"Content-Length: $size"</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">);</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
ob_end_flush</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">();</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="com" style="background-color: transparent; border: 0px; color: grey; margin: 0px; padding: 0px; vertical-align: baseline;">// Strange behaviour, will not work</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
flush</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">();</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="com" style="background-color: transparent; border: 0px; color: grey; margin: 0px; padding: 0px; vertical-align: baseline;">// Unless both are called !</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span></code></pre>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-91598447435028855342012-06-12T04:57:00.003-07:002012-06-12T04:57:40.508-07:00For all you android developers, If you ever installed a new rom and didn't see any logs from your cat, just do this:<br />
<br />
<a href="http://stackoverflow.com/a/7272831/67505">http://stackoverflow.com/a/7272831/67505</a>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-6845204974401378102012-03-28T17:12:00.001-07:002013-05-11T22:06:45.247-07:00Rails + Mongo + Heroku how?<p dir=ltr>After a few hours of fighting with google I decided to write it all here:</p>
<p dir=ltr>*This post is more relevant for windows users but can help others.</p>
<p dir=ltr>What do you need to have:<br>
First you need to have ruby 1.9.2+<br>
Devkit<br>
then you need rails 3+<br>
then u need the bundler gem<br>
then go to getting started with mongoid <br>
then install mongo locally<br>
then check it all good<br>
then add acoount in heroku<br>
then create app<br>
then add your key<br>
then push</p>
Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-56762982012633847082012-02-18T06:30:00.000-08:002012-02-18T06:30:54.153-08:00CoffeeScript - language reviewThis weekend I learned a new programming language, called coffee script, It's not a real language it's actually compiled to JavaScript, so it's a way to write JavaScript differently.<div><br />
</div><div>After a little hands-on and one <a href="http://arcturo.github.com/library/coffeescript/index.html">book</a> read I can say that this is a good language for experienced and non experienced JavaScript programmers. </div><div><br />
</div><div>What's awesome about this language is that is fills like someone took all the good stuff from ruby python and java, and put it in one language that eliminates all the crap you need to take form JavaScript programming.</div><div><br />
</div><div>I can start writing all the good stuff about coffee but there is no need just dive into </div><div><a href="http://coffeescript.org/">http://coffeescript.org/</a> and you'll understand all the benefits.</div>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-10127028671612975492012-01-07T14:42:00.000-08:002012-01-07T14:42:55.351-08:00PHP SessionsOne more thing,<br />
<br />
If you do stuff like put instances of classes inside a session and expect to call methods of this classes later, you must put the session start after you include the classes definitions.<br />
<br />
But I suggest not to do this kind of stuff.Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-25840574700696768582012-01-06T01:49:00.000-08:002012-01-06T01:49:42.197-08:00PHP sessions - stuff to check when things goes wrong.<span style="font-family: 'Courier New', Courier, monospace;">There is too much information about problems with sessions in PHP, every dude got it's own problem and it's own solution.</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">The probability that the problem you experiencing is the same is very low. </span><br />
<span style="font-family: 'Courier New', Courier, monospace;">So here is what my little (and very annoying) google journey came up to:</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br />
</span><br />
<br />
<ul><li><span style="font-family: 'Courier New', Courier, monospace;">You must call session_start(); on each page</span></li>
<li><span style="font-family: 'Courier New', Courier, monospace;">If you use the header('Location: blabla'); you should use relative url to keep preserve session </span></li>
<li><span style="font-family: 'Courier New', Courier, monospace;">some people say before using the header action you need to call <span class="methodname" style="background-color: white;">session_write_close(); - I'm not using it.</span></span></li>
<li><span class="methodname" style="background-color: white;"><span style="font-family: 'Courier New', Courier, monospace;">session_write_close(); could be the reason to your problems, cause after calling it you can't modify the session (in the current http context), that was my problem.</span></span></li>
<li><span style="font-family: 'Courier New', Courier, monospace;">on php docs, they say that "<span style="background-color: white;">Session ID is not passed with Location header even if </span><a class="link" href="http://www.php.net/manual/en/session.configuration.php#ini.session.use-trans-sid" style="background-color: white; border-bottom-color: rgb(0, 0, 153); border-bottom-style: solid; border-bottom-width: 1px; color: #000099; text-decoration: none;">session.use_trans_sid</a><span style="background-color: white;"> is enabled. It must by passed manually using </span><span style="background-color: white;"><tt>SID</tt></span><span style="background-color: white;"> constant."</span></span></li>
</ul><div><span style="font-family: 'Courier New', Courier, monospace;">So first make sure you use session start, if you passed this search for voodoos like <span class="methodname" style="background-color: white;">session_write_close() in the middle of your infrastructure and remove them.</span></span></div><div><span style="font-family: 'Courier New', Courier, monospace;"><br />
</span></div><div><span style="font-family: 'Courier New', Courier, monospace;">If I didn't help, continue the journey.</span></div>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-71342329642957781822011-11-16T00:30:00.000-08:002011-11-16T00:30:43.396-08:00End of job check list<div><div>I'm about to end my first gig(already end! yay I'm free!) as a programmer, and want to leave a clean desk. So here is a list of things I'm doing and suggest you all do before you move to your next gig:<br />
<br />
1. Write about your major infrastructure developments on your wiki or any other system you got, in an easy to understand language.<br />
2. Start lecturing your co-workers about complex parts you developed.<br />
3. Make sure you got full code coverage with unit tests.<br />
4. Search for to-do comments and make sure you do those todo's.<br />
5. If you got unfinished work and think it's worth something make sure someone complete.<br />
<br />
And the most important: change your phone number :-) (Bazinga).<br />
<br />
</div></div>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-76780890286810472252011-10-28T02:00:00.001-07:002011-10-28T02:00:29.235-07:00Startups: reshare very nice research<div><p><a href="http://dailyinfographic.com/the-startup-gamble-infographic?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+DailyInfographic+%28Daily+Infographic%29">The Startup Gamble [infographic] | Daily Infographic</a><br>
</p>
</div>Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0tag:blogger.com,1999:blog-8908829452516573489.post-30221185030893038572011-09-27T06:43:00.000-07:002011-09-27T06:43:40.113-07:00Rubymine recommended font for windowsDidn't find a lot about it on internet so:<br />
<br />
File->Settings->Editor->colors & fonts->Font<br />
first save as current schema<br />
than click the ... button choose Consolas and set size to 14<br />
<br />
looks much better!Anonymoushttp://www.blogger.com/profile/08105846409079487588noreply@blogger.com0