Skip to content

Instantly share code, notes, and snippets.

View hectorperez's full-sized avatar

Hector Perez hectorperez

View GitHub Profile
@hectorperez
hectorperez / default text editor
Last active August 29, 2015 14:01
default text editor in Ubuntu
vim .barchrc
export VISUAL=vim
@hectorperez
hectorperez / rvm cron setup
Created May 19, 2014 16:16
Requiring a Ruby Gem in Ruby Script breaks Cron Job Execution: rvm cron setup
You need to setup your crontab with rvm e.g:
rvm cron setup
With that rvm sets your environment variables in your crontab file
then you have a crontab file having this at the top:
PATH="/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/"
rvm_env_string='ruby-1.9.3-p194'
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@hectorperez
hectorperez / Show views in MySQL
Created May 26, 2014 10:31
Show views in MySQL
SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW';
@hectorperez
hectorperez / Directory size and disk space.sh
Created May 28, 2014 08:01
Directory size and disk space
du -sh * #directory size in human format
df -h #disk space in human format
@hectorperez
hectorperez / variables2.sql
Created May 29, 2014 09:11
Variables in MySQL - set @variable, GROUP_CONCAT & FIND_IN_SET
set @checked=(select GROUP_CONCAT(id) from table_name where atribute_name=1);
UPDATE table_name
set atribute_name=0
where FIND_IN_SET(id,@checked)>0;
@hectorperez
hectorperez / focus to the first text input or textarea.js
Last active August 29, 2015 14:02
Set the focus to the first text input or textarea
$(document).ready(function() {
var first_input = $('input[type=text]:visible:enabled:first, textarea:visible:enabled:first')[0];
if(first_input != undefined){ first_input.focus(); }
});
@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.)
@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