edgar
edgar
Edgar Gonzalez
149 posts
Father, husband, and software developer. I'm building web applications since 1994 for a living and I love it.Senior Engineering Manager at Blue Apron.Former Engineering Lead at StreetEasy (Zillow Group) - Co-founder & CTO of Piictu - TechStars NYC Alumnus.Rubyist, Rails developer since 2006, believer of Agile Development and Lean startups, NoSQL enthusiast, iOS and Golang developer apprentice.Born in Caracas - Venezuela, living in New York.
Don't wanna be here? Send us removal request.
edgar · 10 years ago
Quote
I am only one, but I am one. I cannot do everything, but I can do something. And because I cannot do everything, I will not refuse to do the something that I can do.
Edward Hale
6 notes · View notes
edgar · 10 years ago
Link
4 notes · View notes
edgar · 10 years ago
Text
An easy way to debug gems based on Ruby’s net::http
BEGIN { require 'net/http' Net::HTTP.module_eval do alias_method '__initialize__', 'initialize' def initialize(*args,&block) __initialize__(*args, &block) ensure @debug_output = $stderr ### if ENV['HTTP_DEBUG'] end end }
(via: https://gist.github.com/ahoward/736721)
5 notes · View notes
edgar · 10 years ago
Link
0 notes
edgar · 10 years ago
Text
How to skip all filters in controller - Rails
If you need to skip in an specific controller all the filters defined in the ApplicationController, you can do this:
class MyController < ApplicationController if Rails::VERSION::STRING > "2.3" skip_filter *_process_action_callbacks.map(&:filter) else # rails 2.3.x skip_filter filter_chain end end
0 notes
edgar · 10 years ago
Quote
If your main motivation for using containers (docker) is immutable infrastructure,then makes no sense to use them to deploy statefull systems
https://twitter.com/edgar/status/596305342054674433
0 notes
edgar · 10 years ago
Link
Time as we (engineers) know ends on January 19, 2038 - 03:14:07 UTC
3 notes · View notes
edgar · 10 years ago
Text
Handling single object and array in the same way in Ruby
In ruby instead of adding conditionals to know if an object is an array or not you can use Array(object) or [*object] and treat everything as an Array:
Array(1) => [1] Array([1,2]) => [1,2] Array(nil) => [] [*1] => [1] [*[1,2]] => [1,2] [*nil] => []
0 notes
edgar · 10 years ago
Quote
You break it, you own it, you fix it
Motto of a dev team
0 notes
edgar · 10 years ago
Text
Install pg gem in Mac OS X with Postgres.app
If you’re using Postgres.app and try to install the pg ruby gem, you probably will have an error similar to this:
ERROR: Error installing pg: ERROR: Failed to build gem native extension. ... Can't find the 'libpq-fe.h header ...
The reason of the error is that you have the wrong path for --with-pg-config, so try to install the gem using this:
$ gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.4/bin/pg_config
If you have a different version of Postgres.app, juts replace 9.4 in the path aboove for the proper version number.
3 notes · View notes
edgar · 10 years ago
Text
Rails 4.2 Server port forwarding on Vagrant
If you want to use Vagrant to develop your Rails 4.2 applications, notice that Rails 4.2 now binds to 127.0.0.1 by default and not 0.0.0.0.
So, besides the following line into your Vagrantfile:
config.vm.network "forwarded_port", guest: 3000, host: 3000
Now you need to start the server using:
$ rails server -b 0.0.0.0
0 notes
edgar · 11 years ago
Quote
The golden rule of git rebase is to never use it on public branches.
0 notes
edgar · 11 years ago
Quote
There are only two hard things in Computer Science: cache invalidation and naming things.
Phil Karlton
0 notes
edgar · 11 years ago
Text
Elasticsearch gem for Rails 2.3
Tumblr media
Currently our app is 8 years old and it's still based on Rails 2.3 .
Recently we're adding Elasticsearch to improve performance for some searches, but the existing Elasticsearch-Rails ruby gem requires Rails 3+.
For that reason I develop an Elasticsearch Rails gem for Rails 2.3.
The elasticsearch-rails2 library is based on the elasticsearch-model (one of the components of the elasticsearch-rails gem) and builds on top of the elasticsearch ruby library.
It aims to simplify integration of Ruby on Rails 2.3 models (ActiveRecord) with the Elasticsearch search.
Usage
require 'elasticsearch/rails2' class Article < ActiveRecord::Base include Elasticsearch::Rails2 end
Searching
response = Article.search 'fox dogs' response.took # => 3 response.results.total # => 2 response.results.first._score # => 0.02250402 response.results.first._source.title # => "Quick brown fox"
Search results
The returned response object is a rich wrapper around the JSON returned from Elasticsearch, providing access to response metadata and the actual results ("hits").
Each "hit" is wrapped in the Result class, and provides method access to its properties via Hashie::Mash.
The results object supports the Enumerable interface:
response.results.map { |r| r._source.title } # => ["Quick brown fox", "Fast black dogs"] response.results.select { |r| r.title =~ /^Q/ } # => [#{"title"=>"Quick brown fox"}}>]
In fact, the response object will delegate Enumerable methods to results:
response.any? { |r| r.title =~ /fox|dog/ } # => true
To use Array's methods (including any ActiveSupport extensions), just call to_a on the object:
response.to_a.last.title # "Fast black dogs"
For more info check the README in the github repo
0 notes
edgar · 11 years ago
Text
Installing ruby 1.9.3 in Yosemite (Mac OS x 10.10) via RVM
I was using an old ruby 1.9.3 version (revision p392) and when I upgraded to Yosemite, I wasn't able to install ruby gems with native dependencies.
I tried to reinstall the ruby with:
rvm reinstall 1.9.3-p392 --with-gcc=clang
and
rvm reinstall 1.9.3-p392 --disable-binary --with-gcc=clang
(see source)
Even I tried removing the ruby in RVM and install it again (and also reinstall RVM from scractch) with no success.
Then I tried with the latest 1.9.3 p545 and p547 and they worked fine, so if you need to use ruby 1.9.3 in Yosemite you'll need to install a recent version (I suggest to use the latest revision), to do that use the following:
rvm install 1.9.3 --with-gcc=clang
0 notes
edgar · 11 years ago
Text
How to create a public SSH key from the private key
Today I learned you can use the -y option in ssh-keygen command to generate a public SSH key from the private key:
ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub
12 notes · View notes
edgar · 11 years ago
Text
My Pry customizations for Rails console
I'm using Pry for my Rails console, I have defined the following alias in my ~/.zshrc to start the rails console using Pry:
alias sc='./script/console --irb=pry'
The .pryrc file is analogous to the .irbrc file for IRB. You can use the .pryrc file to customize Pry.
Below is my ~/.pryrc file:
The first line configure SublimeText 3 as Pry's editor
The methods unbundled_require and load_gem allows me to load an installed gem that is not included in the current project's Gemfile. In my case I'm loading the awesome_print gem (line 45) to pretty prints Ruby objects in full color exposing their internal structure with proper indentation
And then depending on the current Rails version, I configure the Rails logger (Rails 2) or the ActiveRecord logger (Rails 3) to use the STDOUT, in order to print the SQL statements to console.
This is how it looks my Rails console with these customizations:
Tumblr media
0 notes