Saturday, September 14, 2013

VirtualBox is slow !

So my host OS is Windows 8 and I wanted to separate my everyday stuff from my projects (coding) stuff.
I created a virtual machine, guest OS is Linux Mint.
My PC is: intel i3570K, 8GB DDR3, 64SSD + 128SSD, Asus Z77. Not a bad one!


So when I was in Mint, it was kind of slow.

 In settings > System > Processor, I had only 1 processor and when I selected 2 processors, I could see a warning message saying something like "this is not the most efficient setup". I ignore this message and in settings > System > Accelation, I checked "Enable VT-x/AMD-v".
When I start my virtual machine, I add an error message and the machine didn't start at all.


After searching on the Web, I found out that I had to go to the bios and activate a feature.
I don't remember exactly the name of the feature (and I guess it depends of the motherboard), but it was in the CPU section, and the feature was like "activate virtualization something".

After activating it, I could select 2 CPU and now my virtual machine is not slow anymore!

And that's it!

Thursday, May 30, 2013

imageMagick on mac os

Recently, I'm working on a mac os, creating a website using Rails.
I want the user to be able to upload a picture as an avatar. I found excellent
information on Internet. The most popular library is probably Paperclip (
Paperclip is intended as an easy file attachment library for Active Record.

After installing Paperclip and  ImageMagick (with brew), I added the code in my model :
attr_accessible :avatar, :name
has_attached_file :avatar, :styles => { :medium=>"300x300>", :thumb => "100x100>"},
  :url  => "/assets/restaurants/:id/:style/:basename.:extension",
  :path => ":rails_root/public/assets/restaurants/:id/:style/:basename.:extension"

It's exactly like in the wiki page of Paperclip (nothing fancy).

Problem :
But when I tried to upload an image, I had this error :
 ... is not recognized by the 'identify' command.

On Internet, many people said to do:
which identify
And then add in config/environment.rb:
Paperclip.options[:command_path] = "/usr/local/bin"

But this didn't work for me.
If I just tried the command "identify", I could see this error :
dyld: Library not loaded: /usr/local/lib/libtiff.3.dylib
  Referenced from: /usr/local/bin/identify
  Reason: image not found
Trace/BPT trap: 5

So I was thinking there is a problem with the file "libtiff.3.dylib".

Solution :
I copied the file libtigg.3.dylib :
from : /opt/local/lib/libtiff.3.dylib
to : /usr/local/lib/libtiff.3.dylib

I restarted my rails server, and now it's working !
It's probably not the best solution, but at least it's working so far.
I think ImageMagick is looking for the file libtiff.3.dylib in a wrong folder.
Maybe if I could modify ImageMagick config file and change to the good folder, this
would be a better solution.

And that's it !

Monday, March 4, 2013

Twitter bootstrap rails could not find in any of the sources

For my website, I'm using Twitter Bootstrap and it is cool !
So easy to use and my website have a nice look.

I'm using the gem Twitter-bootstrap-rails.
It is working great on my development environment. I followed the step by step and added this to my Gemfile:
gem 'twitter-bootstrap-rails'

When I deploy on production, I have to do "bundle install". No problem, everything is installed. But when I start the server I have this error:
Could not find twitter-bootstrap-rails-2.2.0 in any of the sources

A little bit surprised, because "bundle install" was ok, and I can see the gem.

In fact, my Gemfile should look like this:

gem 'twitter-bootstrap-rails', :git => 'git://'

I don't know if the latest build fix this problem or if it's using Git, but it is working!

And that's it!

Tuesday, February 19, 2013

Paperclip order of params

In my website I'm using Paperclip to take care of the attached files.

I have a model "image" who has many "collections".
A "collection" belongs to a "resolution".

I'm displaying the form of an image with a list of available resolutions.

In the model Collection:
has_attached_file :picture,
    :url => "...",
    :path => "...",
    :styles => { :custom => { |col| "#{col.resolution.width}x#{col.resolution.height}" }}

When an image is updated, the Proc is executed and I have a "nil" exception.
I'm wondering why "resolution" is nil because the params contain a resolution_id.

In fact, it depends of the order you pass the parameters.

At first, the view was like this :
= f.file_field :picture
= f.hidden_field :resolution_id

But I should do like this:
= f.hidden_field :resolution_id
= f.file_field :picture

The "resolution_id" should be first !
By doing so, Rais is creating the relation between "resolution" and "collection" first, and then he is applying the style.

So, sometimes the order of the params is important!

And that's it!

Too bad for me, in fact the order is not sure... It is working on my development environment, but not in my production environment...

Friday, February 15, 2013

Rails default_scope delete

I have a model called User with a default_scope where('deleted_at is null'), because I'm using some kind of "soft delete".

I want to delete an object who has been soft deleted.

First, I create an object :
user =

Then I soft delete it:
# this set deleted_at =

Then I want to delete it:
# nothing happen !
# the query looks like this: delete from users where id = 1 and deleted_at is null

I can think about 2 solutions:

1) Is to execute sql code directly:

ActiveRecord::Base.connection.execute("delete from ...");

2) Use "unscoped"
User.unscoped.where(:id => 1).delete_all

And that's it!

If you know a better solution, please let me know

Wednesday, January 30, 2013

Rewrite no-www to www with nginx

I had to redirect all users who entered the address without "www" to the address with "www".
For example:

  •  "" -> ""
  •  "" -> ""

I'm using Engine Yard and the nginx configuration files are there :

Here you can see DOMAIN.conf. Do not modify this file ! I did it and later I found out that my modification was removed. This happened when you "apply" or "upgrade" your environment, this file is re-created.
The file you should modify is /data/nginx/servers/DOMAIN/custom.conf
(If you look at the bottom of DOMAIN.conf, you can see that custom.conf is included)
Here is the code:

if ($host = {
    rewrite ^(.*)$1;

Then I was doing "touch tmp/restart.txt" and the redirection was not working...
Because in fact you should do this:
sudo /etc/init.d/nginx reload

Of course if you're using "https", you should modify "custom.ssl.conf" !

Saturday, January 5, 2013

Android source code

For a project, I'm looking at the source code of Android.
And I could find this comment in
// This is hardcoded IP addr. This is for testing 
// We would need to get rid of this before release.

Looks like they forgot to remove it.