sabato 12 aprile 2014

[Ruby] Memory profiling of a rake task with Ruby 1.9.3

These are only some notes to remember what I did to do a memory profiling of a rake task.

The environment was Ruby 1.9.3 with a Rails application and a Rake task to run in order to import the data in the DB.

The Rake task was just a wrapper for an Importer Object Class.

First add ruby-prof to the Gemfile:

gem "ruby-prof"

Then require it into the file you want to profile, and start to profile the task you want to track:

 require 'ruby-prof'
 
 def my_method()
   # We want to profile the Memory rather than Process time

   RubyProf.measure_mode = RubyProf::MEMORY
   # Start profile!
   RubyProf.start
  
   ... do your crazy stuff here...

   # Stop profiling and get the result
   result = RubyProf.end

   # Write the result in somewhere
   RubyProf.MultiPrinter.new(result).print { :path => "#{Rails.root}/", :profile => "profiling" }
 end

Easy, right?
Yeah, too much, in fact opening the profile.html the result will be a full stack of NaN... indeed have a look to this issue for 1.9.3 in ruby-prof.

So, what to do is to use RVM to install a patched version of 1.9.3 and try again!

$ rvm install 1.9.3-p194 --patch railsexpress

Go and make a tea while waiting for building...

At this point create a new gemset, bundle install and have another go with the profiling: this time it should work!

giovedì 15 agosto 2013

Google+ invitation

Have you ever received a Google+ invitation?

Well, I didn't even know that there were invitations on Google+.
More, I didn't know any person, by default, could send you invitations for events or communities.

Everything started with this notification on my mobile:


Which look quite clear: somebody - that I don't know - invited me to something - that I don't know as well.
Ok, let's see what's that about... Top on it, Google+ app opening and... no clue: just the regular post stream of G+.

I haven't found any way to visualize what is this invitation about: a community? An event?

Ok, it is, probably, a limitation of the mobile app. Let's see on the web version... Same.

No way to find out who or what is this invitation about. There no way to visualize it - or at least I haven't found it.

So, looking around within the Google+ FAQ, there is this nice paragraph:

How can I control how many community invitations I receive?

You can control who is allowed to send you invitations as well as whether you receive invitations via email/mobile.
To control who is allowed to send you community invitations, visit the Google settings page and adjust the “Who can send you notifications” control.
To turn email and mobile notifications for community invitations on or off entirely, visit the Google settings page and toggle the “Invites me to a community” setting.
Note: Even if you have community invitations enabled via email/mobile, you won’t receive any invitations from people who you haven’t allowed to notify you.
It looks reasonable, even if nobody told me about that before.
Going to my settings page, Google+ section I can clearly see that everyone in the "Extended circles" can invite me.

Well, I don't know the guy who did invite, but he could be part of somebody else circle... but, then I find this.
Look the note at the very bottom page:
Note: In certain situations, you may still receive notifications from people outside the selected options, including information about photos and events that you created or attended as well as notifications from people who reach out to you via your email address.
Thanks Google to let everybody send me with spam invites.

But, believe or not, still no clue about that invitation: the only thing I have is that notification on my mobile.
Apparently the only way to verify that I've found is:
  • Look for the guy who sent the invite
  • On his page there was a post talking about a community with the same name of the invite
  • Enter in the community with the "Community Preview" button
  • Finally found the invite!

Easy right?

P.S. If anybody is aware of some other way to see received invites, you're very welcome to share this secret.

giovedì 20 giugno 2013

[Data] When to buy the TomTom app on iTunes

Few days ago, looking for my next holiday in Italy, I started to look around for a TomTom application for my iPhone to buy on the App Store.
I had to choose between the TomTom Italy (34,99 Euro) and the TomTom Western Europe (49,99 Euro): well, for 15 Euros more I decided for the latter, looking forward to go around the Europe later, but, because it was late night I delayed the purchase for the day after.

Surprise Surprise

The few days after I go on the iTunes store to check the app and... surprise, the price jumped to 69,99 Euros! 20 Euros more, wow!
So, discouraged about the thing I started to think that it was all my fault and that probably I should have bought before, when there was the previous promotion (?): but I haven't seen anywhere about a promotion on the TomTom app, how can I figure out there was one?!

So, even if I was still tempted to buy it, I've checked a bit online to find out if TomTom had published any promotion about it's iPhone app... nothing.

Data matters

So, when I was about to buy the app at the new price it comes back to my mind that a site that tracks all the price changes in the App Store, so looking for another promotion from TomTom I gave it a try.

Filtering all the apps (in the right market), I've found this small table, in the corner:

Looking at that table it's easy to see that there's something strange going on with the price: why so many changes in the period?

Collecting and playing a bit with the data I manage to have a representation of the trend of the changes of the app on the store:
Don't you see a strange accelleration of the changes during the last period? If they change so quick the price it might happen a price drop soon, so waiting a bit it might be worth...
Starting from the statement above let's filter out the data by week days and see if I have any chance to buy the app with a lower price:
Mmmmm... still too generic: I can only see that they're changing the price usually during Wednesday and Saturday more often than the other week days. But I cannot see if the change is positive or negative! Luckily Google Spreadsheet can handle multiple criteria so with a formula like:
=COUNT(FILTER(C2:C;C2:C=0;D2:D="Positive"))
The spreadsheet starts to count only the positive and negative change occurrencies in the data for each weekday.*
At the end something more interesting comes out of the data:
More, for the year 2013:

Conclusions

So, because it was Wednesday when the price was 69,99 Euros there's still a small chance to buy the app for 20 Euros less the day after: maybe it was worth to try for a 30% sale...

And there it is: the day after it comes the price drop again and I've got now my TomTom app at a very good price!

This the story on why study the data, sometimes, it's worth. At least 20 Euros.
Now just remember to buy the TomTom app only on Thursdays!

* The Column "C" had the Weekday number (0->6) and the Column "D" was a boolean column filled with the strings "Positive" and "Negative".

giovedì 24 gennaio 2013

[Skype] Screen sharing still free

Did you find last version of Skype (> 6.1.0 on OsX) doesn't let you share the screen while you're having a one-to-one chat?

Before what you had to do to share your screen during the video-call was to select 'Share Screen', right?

Now it asks you to buy Skype premium to restore the old feature you used a lot since they decided to take it off few days ago... but wait, the feature is not gone: it just became longer to activate.

So, during the next video-call, if you want to share your screen again, do the following:
  • Turn off your video
  • Activate 'Share Screen'
That's it.
Easy. Simple.
It can be done even by a script.

But some smart guy at Skype decided the user now has to do 2 more clicks for something like that.

So now say thanks to Skype for this nice move.

domenica 19 febbraio 2012

[Mac][OsX] Uninstall XCode 4

If you're having trouble with XCode 4 and want to uninstall it you have to use the following command from the Terminal:
sudo /Developer/Library/uninstall-devtools --mode=all
Or, more in general:
sudo your-xcode-folder/Library/uninstall-devtools --mode=all
And restart the system if you're planning to install a previous version of Developer Tools.
That's all folks!

venerdì 10 febbraio 2012

[Ruby][Rake] Importing task is taking too long?

Working with big set of data it could happen to import a very large amount of objects from CSV to your SQL database. And if you have hundreds thousand of rows for a particular model in your CSV it could take too long and too many memory...
It means that during your coding you have been too optimistic about the data size to import.
So, what is the solution?
Actually I found two solutions for this problem: use the Crewait gem, or a better use of transactions.

mercoledì 8 febbraio 2012

[Ruby][Rake] Problem with migrations?

First of all, this happened to me trying to migrate db with a rake task on the production server. NOTE: please take a snapshot or a backup of your database data before starting with migrations.
Are you developing a Rails 3.0.x app? Are you using slim_scrooge gem?
Did your migration worked on development/test environment, but it looks having problem on production server?
Better: it looks like working but when you check your DB or schema.rb file you see nothing happened?