May 2013
2 posts
7 tags
Migrating FasterCSV from ruby 1.8 to CSV in 1.9+
Currently in StreetEasy we’re moving a Rails app from Ruby 1.8 to 1.9
In Ruby 1.9 FasterCSV is already included as standard library’s CSV. And in Ruby 1.9 you can’t continue using FasterCSV, if you do, you’ll get an error message like this:
Please switch to Ruby 1.9's standard CSV library.
It's FasterCSV plus support for Ruby 1.9's m17n encoding engine.
The workaround...
6 tags
How to install RMagick (2.13.1) with latest...
I need to use RMagick v2.13.1 in a current project, but RMagick v2.13.1 doesn’t works with the latest ImageMagick (6.8.0-10).
The workaround I found is: first install ImageMagick via Homebrew:
brew install imagemagick
and then:
$ ln -s /usr/local/Cellar/imagemagick/6.8.0-10/lib/libMagick++-Q16.7.dylib libMagick++.dylib
$ ln -s...
April 2013
1 post
4 tags
MongoDB shell inserts Float when try to insert an...
Because of numbers are doubles in Javascript, when yo do this:
> db.test.insert({name: ‘foo’, value: 1});
you get this:
> db.test.findOne({name: ’foo’}); {‘name’: ‘foo’, ‘value’: 1.0}
To avoid this you can use NumberInt or NumberLong:
> db.test.insert({name: ‘foo’, value: NumberLong(1)});
February 2013
1 post
5 tags
RubyCheckOnSave Sublime Text 2 Plugin
More than one year ago, I created a very simple script that enable Sublime Text 2 to automatically check the syntax of ruby files when they are saved
Three months ago I finally found the time to convert that script into my first Sublime Text 2 plugin: the RubyCheckOnSave plugin.
January 2013
3 posts
3 tags
RVM: How to remove all gems from default gemset
To remove all gems from a gemset you use the gemset empty command:
$ rvm gemset empty <my_gemset_name>
And to remove the gems from default gemset, you must supply an empty string as the gemset name:
$ rvm gemset empty ""
3 tags
How to cURL and JSON prettyprint
cUrl is a simple and powerful tool to test RESTful APIs, but sometimes the output could be messy, specially when the response is a long JSON.
To improve the output readability, I’m using cUrl with jsontool (a node.js script).
After you install it:
$ npm install -g jsontool
Then pipe the cUrl output to jsontool
$ curl -is http://search.twitter.com/search.json\?q\=foo | json -i
Below an...
2 tags
How to remove a Git submodule and put the code...
You need to remove the submodule and re-add the files into the main repo.
Edit the .gitmodules and .git/config files and remove the lines that specify the submodule, then;
git rm --cached path/to/submodule # delete reference to submodule HEAD (no trailing slash)
rm -rf path/to/submodule/.git
git add path/to/submodule # add files instead of commit reference
git commit -m "remove submodule"
December 2012
3 posts
3 tags
Permission denied (publickey) when deploying...
Today I tried to deploy to heroku a new version of an application (that not has been deployed in several months):
git push heroku master
but I got the following error:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
The weird part is that I can deploy other 3 apps without problem, that means that my public SSH key is properly stored on Heroku.
If the Heroku api is...
5 tags
How to sort in ruby an enumerable by an attribute...
I have an Enumarable of tokens, and I need to sort them descending by the last_access attribute, but for some objects this attribute could be nil. One OOP approach to do it, is defining the <=> method (Comparable) in the Token class:
class Token
include Comparable
define <=> other
...
end
end
Then I’ll only need to call tokens.sort. But I’m not ready to change...
3 tags
How to delete large amount of data of a MongoDB...
We have a db collection that is around 30 million documents, and I need to trim it down, to only keeping the documents created on the last month.
One approach would be use the remove command with a condition on the created_at field (the collection already have an index on this field):
db.my_collection.remove({created_at: {$lte: new Date("11/01/2012")}});
But this approach will be very slow,...
October 2012
1 post
We live in a world where there is more and more information, and less and less...
– Jean Baudrillard
August 2012
4 posts
5 tags
Ruby on Rails :: How to add HTTP basic...
First you set up your staging app following the Heroku’s guide for Managing Multiple Environments for an App
Then edit the config/environments/staging.rb:
#config/environments/staging.rb
MyApp::Application.configure do
# Basic authentication
config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "My App") do |u, p|
[u, p] == [ENV['HTTP_USER'], ENV['HTTP_PASSWORD']]
...
1 tag
TextMate is now open-source →
Interesting move, … maybe the only possible move for Text Mate
3 tags
How to list all Rails 3 rake tasks
If you run the “classic” rake -T, only the tasks with descriptions will be appear, for instance:
$ rake -T db
Will display something like:
rake db:create # Create the database from config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config)
rake db:drop # Drops the database for the current Rails.env (use db:drop:all to drop...
July 2012
2 posts
look how much we’ve failed. That’s how smart we’ve become
– Nate St. Pierre (Vooza)
2 tags
The annoying “warning: useless use of == in void...
If in your specs you have something like this:
it "should be bar" do
foo.should == 'bar'
something_else
end
The ruby -w command will throw the following warning:
warning: useless use of == in void context
The way to avoid this is using this:
foo.should eql('bar')
Or:
foo.should be == 'bar'
Or move the statement
foo.should == 'bar'
so that it’s the last line inside the it block
June 2012
2 posts
6 tags
Ruby 1.8.7 and multi_json
I’m starting to work on a gem for Singly API that uses multi_json. The tests for the gem worked in 1.9.2 and 1.9.3 but I got the following runtime error in 1.8.7:
missing dependency for FaradayMiddleware::ParseJson: no such file to load -- json
I have been using 1.9.3 more and more lately and I forgot that json was added to the stdlib in 1.9. So that’s why it works in 1.9.x. while...
2 tags
May 2012
3 posts
4 tags
Startup Metrics for Pirates
One of most important thing about startups is that you can collect usage metrics in real time. However, being able to make decisions with this data is not easy. It’s important to understand how to collect and use these metrics, and develop a decision-making framework for startup development. The framework should be based on goals that are measured through discrete users or startup events...
4 tags
An introduction to Stock & Options for the Tech...
In Scribd there is a good introduction about stock & options for tech entrepreneur or startup employee
(Also there is a kindle version available in amazon)
Bijan Sabet: Is 20k installs per day the new norm? →
bijan:
Thanks to the combination of smartphone proliferation, the app store distribution model, FB Open Graph integration and Twitter, we are seeing mobile apps reach incredible metrics very fast - particularly in daily installs and sign ups.
It’s has me thinking about a number of things:
FB Open…
April 2012
2 posts
1 tag
Fixing git: "interactive rebase already started"
If you’re like me, a fan of rebasing local work before publishing, maybe you receive this error:
"interactive rebase already started"
This happens when you abort in the middle of a rebase.
The way to fix it is using:
git rebase -i --abort
3 tags
March 2012
6 posts
2 tags
How emacs changed my life →
(or Ruby is what it is, thanks to emacs)
by @yukihiro_matz
5 tags
Sync your passwords and sensitive data between...
I sync automatically my passwords between my macbook, ubuntu laptop and iPhone, using KeePass and Dropbox.
KeePass is a cross-platform (Windows, Linux, Mac) open-source password manager that enables you to safely lock away your passwords, PINs, credit cards in a local encrypted file.
Create a Dropbox account, and install the Dropbox client to all your devices you want to sync (in my case...
Seriously, most of the problems that you’re solving are social, not...
– Nobody Understands REST or HTTP by Steve Klabnik
My conscience won’t let me call Ruby a computer language. That would imply that...
– _why’s poignant guide to Ruby (via thoughtbot)
3 tags
Entrevista sobre Piictu en Makina con La Mega
Hace un par de semanas conversé con Anairene (@edelweiss) sobre Piictu en el programa de radio Makina con La Mega.
Para los que quieran oirla aquí les dejo el link al podcast del Programa No 208 - Piictu de Makina con La Mega.
Gracias una vez más a Nacarid y Anairene
2 tags
If you’re debating a point for more than 30 min, shut up and vote. You’ll move...
– Via 10-lean-startup-machine-tips-and-tricks
January 2012
1 post
Command-Line Javascript (CLI) On Mac OS-X →
December 2011
1 post
6 tags
Configurar el Huawei E1756 de Movistar en Mac OS X...
Movistar no da soporte para el uso de su Internet Móvil en Mac OS X 10.7 (Lion), solamente soportan desde 10.4 hasta 10.6. Sin embargo, si funciona, he aquí lo que yo hice para configurarlo:
De la página de Movistar sigues las instrucciones para descargar e instalar el Escritorio Movistar.
Cuando lo instales es muy probable que te de un error como me ocurrió a mi
No te preocupes, hazle un...
November 2011
3 posts
5 tags
Rails 3 :: Not abandon sending mail within...
In ActionMailer (Rails 3) you can’t decide not to send an email. For instance, you have the following mailer:
class FooMailer < ActionMailer::Base
def bar_email
if some_condition
mail(...)
else
# Can I do nothing? No :-(
end
end
end
If you invoke FooMailer.bar_email.deliver!, when same_condition is false you will get the following error:
ArgumentError: A...
How to link your git project with an existing...
To add your Heroku application as a remote in your git repository, use the following command:
git remote add heroku-remote git@heroku.com:project.git
Where project.git is your heroku application, and heroku-remote the name you want for the remote, in my case I usually have several remotes, one for production, staging and dev
3 tags
Introduccion a NoSQL
Esta es la presentacion que di en el BogotaConf (@bogotaconf) sobre NoSQL
(Update 19/Abr/2012): Agregado el video de la charla
October 2011
3 posts
4 tags
SublimeText2 - Check ruby syntax after save
Edit the file: /path/to/SublimeText2/Packages/Ruby/Ruby.sublime-build to contain this:
{
"cmd": ["/path/to/ruby/bin/ruby", "-cw", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}
Then create the following file /path/to/SublimeText2/Packages/User/ruby_check.py:
import sublime, sublime_plugin
class rubyCheck(sublime_plugin.EventListener):
def...
I’m still a work in progress
– from: me
to: my future me
All things in the universe start from a point and return to a point. One point...
– Lee Ufan
September 2011
10 posts
1 tag
Git pull from a wrong branch?
If you’re working in your feature-branch:
git checkout feature-branch
and by mistake you pull from a wrong branch (usually master or develop):
git pull origin different-branch
You can fix it with this:
git reset --hard origin/feature-branch
3 tags
How to return a real empty response in Rails
I’m building a JSON API using rails. In several places I only need to send a 200 http code, without response body.
So, I used the head method:
head :ok
But this returns a response body with one blank character, this single space body causes the mobile client to fail (parse error). Below the response (notice the Content-Length):
HTTP/1.1 200 OK
Server: nginx/0.7.67
Date: Tue, 06 Sep 2011...
2 tags
Evolution of Piictu
2 tags
Piictu is Twitter for pictures, no typing allowed →
With Noah (left) at Techstars
Article by Business Insider
3 tags
Drop a database in MongoDB
If you want to delete a database named ‘dummy_db’ just do this:
$ mongo
> use dummy_db
switched to db dummy_db
> db.dropDatabase()
{ "dropped" : "dummy_db", "ok" : 1 }
4 tags
Developing Apps for iOS (free Stanford course) →
3 tags
Using github compare view to generate change log...
Github’s ‘compare views’ feature is owosome! I use a lot, in particular to generate change log for releases.
The Compare View URL structure is:
http://github.com/edgar/<repository>/compare/<start branch>...<end branch>
More info in:
https://github.com/blog/612-introducing-github-compare-view
5 tags
How to configure you Google App account in Empathy...
Recently I try to added mi Google App account to Empathy (chat client for linux), but wasn’t works at the first try, so I tried different settings and the trick is just “Ignore SSL certificate errors”
Now my setup is:
Login ID: [my full e-mail address]
Advanced
Encryption required (TLS/SSL): checked
Ignore SSL certificate errors: checked
Override server settings
Server:...
4 tags
"Building mobile applications" free course from... →
August 2011
2 posts
3 tags
How compare versions strings in ruby
There is a lot of way to compare versions strings in ruby, for instance you turn each version string in to an array of integers and then use the array comparison operator. But I prefer this one:
Gem::Version.new('0.3.2') < Gem::Version.new('0.10.1')
Any fool can write code that a computers can understand. Good programmers write...
– Martin Fowler