Skip to content

Instantly share code, notes, and snippets.

View hectorperez's full-sized avatar

Hector Perez hectorperez

View GitHub Profile
# Gemfile
gem 'debugger', group :development, :test
include 'debugger' where you want to debug
Commands:
- help
- list
- pp variable (print variable content)
- irb (enter in irb; well, rails console)
@hectorperez
hectorperez / beginning_and_end_of_day.rb
Created July 14, 2014 20:38
DateTime: beginning_of_day and end_of_day
date.beginning_of_day
date.end_of_day
within "#id" do
expect(page).to have_content("hello")
end
@hectorperez
hectorperez / __calleee__method_name.rb
Created July 14, 2014 19:51
__callee__ method name
def yep
puts "method_name: #{__callee__}"
end
> yep
method_name: yep
Also: __method__
@hectorperez
hectorperez / Vim_notes.vim
Last active August 29, 2015 14:02
Vim: Notes
:e. (e-space-dot) gives a browsable current directory - then you can /-search for name fragments
# http://stackoverflow.com/questions/573039/any-shortcut-to-open-file-in-vim
Others:
:split
:vsplit
Ctrl+w+w / Ctrl+Shift+w
:res +10 # http://vim.wikia.com/wiki/Resize_splits_more_quickly
@hectorperez
hectorperez / jQuery find events handlers registered with an object.js
Created June 16, 2014 16:21
jQuery find events handlers registered with an object
jQuery._data( elem, "events" );
// http://stackoverflow.com/questions/2518421/jquery-find-events-handlers-registered-with-an-object
@hectorperez
hectorperez / Delete all lines containing a pattern in Vim
Last active August 29, 2015 14:02
Delete all lines containing a pattern in Vim
# to delete all lines containing "profile" (remove the /d to show the lines that the command will delete):
:g/profile/d
# to delete all lines that do not contain a pattern, use 'g!' (equivalent to 'v'), like this command to delete all lines that are not comment lines in a Vim script:
:g!/^\s*"/d
:v/^\s*"/d
# to delete all lines except those that contain "error" or "warn" or "fail"
:v/error\|warn\|fail/d
@hectorperez
hectorperez / callback in a module in Ruby on Rails.rb
Last active August 29, 2015 14:02
Callback in a module in Ruby on Rails
# http://stackoverflow.com/questions/7444522/is-it-possible-to-define-a-before-save-callback-in-a-module
class Model
include MyModule
#...
end
# lib/my_module.rb
module MyModule
extend ActiveSupport::Concern
@hectorperez
hectorperez / time-zones-in-ruby-on-rails.rb
Last active August 29, 2015 14:02
Time zones in Ruby on Rails
# http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails
# DOs
2.hours.ago # => Fri, 02 Mar 2012 20:04:47 JST +09:00
1.day.from_now # => Fri, 03 Mar 2012 22:04:47 JST +09:00
Date.today.to_time_in_current_zone # => Fri, 02 Mar 2012 22:04:47 JST +09:00
Date.current # => Fri, 02 Mar
Time.zone.parse("2012-03-02 16:05:37") # => Fri, 02 Mar 2012 16:05:37 JST +09:00
Time.zone.now # => Fri, 02 Mar 2012 22:04:47 JST +09:00
Time.current # Same thing but shorter. (Thank you Lukas Sarnacki pointing this out.)