Skip to content

Instantly share code, notes, and snippets.

View hectorperez's full-sized avatar

Hector Perez hectorperez

View GitHub Profile
@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 / 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 / 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 / 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';
=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 / 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'
@hectorperez
hectorperez / default text editor
Last active August 29, 2015 14:01
default text editor in Ubuntu
vim .barchrc
export VISUAL=vim
require 'active_support/core_ext'
Time.now + 2.days
@hectorperez
hectorperez / sed
Last active August 29, 2015 14:01
sed: Find this text and remove everything that follows
sed '/Find this text and remove everything that follows/q' filename > new_filename
@hectorperez
hectorperez / Self Signed SSL Certificate
Last active August 29, 2015 14:01
Self Signed SSL Certificate
sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt
The most important line is "Common Name". Enter your official domain name here or, if you don't have one yet, your site's IP address.
https://www.digitalocean.com/community/articles/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-12-04