How to fix « invalid byte sequence in US-ASCII » in bundler installation

When trying to push to Heroku I came accross this nasty bug :

   /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/specification.rb:519:in `normalize_yaml_input': invalid byte sequence in US-ASCII (ArgumentError)
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/specification.rb:479:in `from_yaml'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/package/tar_input.rb:183:in `load_gemspec'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/package/tar_input.rb:51:in `block in initialize'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/package/tar_reader.rb:64:in `block in each'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/package/tar_reader.rb:55:in `loop'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/package/tar_reader.rb:55:in `each'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/package/tar_input.rb:32:in `initialize'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/package/tar_input.rb:17:in `new'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/package/tar_input.rb:17:in `open'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/package.rb:58:in `open'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/format.rb:63:in `from_io'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/format.rb:51:in `block in from_file_by_path'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/open-uri.rb:35:in `open'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/open-uri.rb:35:in `open'
    from /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/format.rb:50:in `from_file_by_path'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/source.rb:72:in `fetch'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/installer.rb:45:in `block in run'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `block in each'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in `each'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/installer.rb:44:in `run'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/installer.rb:8:in `install'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/cli.rb:225:in `install'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in `run'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in `dispatch'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/vendor/thor/base.rb:389:in `start'
    from /usr/ruby1.9.2/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/bin/bundle:13:in `<top (required)>'
    from /usr/ruby1.9.2/bin/bundle:19:in `load'
    from /usr/ruby1.9.2/bin/bundle:19:in `<main>'

Basically it is saying that one of the Gemspec of one of my gems in containing UTF8 characters and so the slug compilation can’t go forward. Even by adding LANG = « en_US.UTF-8 » to the heroku config vars.

What did the trick was to add these two lines to the Gemfile :

LANG="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

I didn’t know that a Gemfile could contain ruby code and get evaluated, there you go.

Serializeable with rails, real world use.

I’ve been using the serialize extension from greg moreno for a few weeks now. But I’ve always been thrown of by the way the initialization of values is done.

Let’s say I create a User model with a :settings hash, containing :notify_mail => true as a default value. All the new created users are going to have the notify_mail value set. Now if I had another attr say :invites_count => 10. All users created afterwards are going to inherit from the two attributes, but what about all the previously created users ? They are still stuck with the only one attribute.

Since I didn’t want to have to refresh all the values for everyone every time I added another attribute to the :settings Hash, I modified the AttributeSerializer to make the setter return the default value if nothing is set.

Here is the gist :

Android GridView, CursorAdapter and Imageview sizing.

Alright, a geeky post for today, and in English so it might be useful to someone, maybe.

I had a problem with my GridView content jumping around, and here is how I fixed it :

public class PhotosGridAdapter extends CursorAdapter {
	
	public PhotosGridAdapter(Context context, Cursor c) {
		super(context, c);
	}
 
	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		
		ImageView photo = (ImageView) view;
        String url_medium = cursor.getString(cursor.getColumnIndex(KarmaDbAdapter.PHOTO_URL_MEDIUM));
        ImageCache.download(url_medium, photo);

	}
 
	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		ImageView v = new ImageView(context);
		v.setLayoutParams(new GridView.LayoutParams(100, 100));
		v.setScaleType(ImageView.ScaleType.FIT_CENTER);
		bindView(v, context, cursor);
		return v;
	}
}

Basically you need to set the layout params in the newView, and not in the bindView, otherwise the previous content get shrank down.

There you go, I’m going back to my nexus.

Kubrick on Life

Playboy: If life is so purposeless, do you feel its worth living?

Kubrick: Yes, for those who manage somehow to cope with our mortality. The very meaninglessness of life forces a man to create his own meaning. Children, of course, begin life with an untarnished sense of wonder, a capacity to experience total joy at something as simple as the greenness of a leaf; but as they grow older, the awareness of death and decay begins to impinge on their consciousness and subtly erode their joie de vivre (a keen enjoyment of living), their idealism – and their assumption of immortality.

As a child matures, he sees death and pain everywhere about him, and begins to lose faith in the ultimate goodness of man. But if he’s reasonably strong – and lucky – he can emerge from this twilight of the soul into a rebirth of life’s élan (enthusiastic and assured vigour and liveliness).

Both because of and in spite of his awareness of the meaninglessness of life, he can forge a fresh sense of purpose and affirmation. He may not recapture the same pure sense of wonder he was born with, but he can shape something far more enduring and sustaining.

The most terrifying fact about the universe is not that it is hostile but that it is indifferent; but if we can come to terms with this indifference and accept the challenges of life within the boundaries of death – however mutable man may be able to make them – our existence as a species can have genuine meaning and fulfilment. However vast the darkness, we must supply our own light.

— Stanley Kubrick in interview for Playboy, Stanley Kubrick Interviews, University Press of Mississippi, 2001, p.73
trouvé chez Ellga