Skip to content

Instantly share code, notes, and snippets.

View hugomaiavieira's full-sized avatar

Hugo Maia Vieira hugomaiavieira

View GitHub Profile
@hugomaiavieira
hugomaiavieira / presence.rb
Created July 24, 2014 19:36
Do not use present? on ternary
# you may think to do this:
bar = foo || {}
# but foo can and empty string that is not falsy, so you do this:
bar = foo.present? ? foo : {}
# a better way to do it is this one:
bar = foo.presence || {}
@hugomaiavieira
hugomaiavieira / typewatch.js
Created September 3, 2014 12:07
type watch for search
$(document).ready(function() {
var typewatch = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
}
})();
$('#search-modal').on('input', function () {
def insert_select2(team_name = nil)
# When it simulates an existing record, id is passed, and controller take it by id.
# It's simulating Select2 request for getting record on the query.
# When name is passed, it indicates that no record was found, creating a new one.
# This behavior is implemented on SalespointController#create.
execute_script("$('#app-team-modal .select2-focusser').val('#{team_name}').trigger('keyup')");
find('.select2-chosen').click
sleep 2
@hugomaiavieira
hugomaiavieira / wait_for_ajax.rb
Last active August 29, 2015 14:08
Ajax testing with ruby and capybara
# Ajax testing with ruby and capybara
#
# Add this to spec/support
#
# When a link or button starts an ajax request, instead of use Capybara
# click_link, click_button and click_link_or_button methods use click_ajax_link,
# click_ajax_button and click_ajax_link_or_button methods. You can still use
# capybara methods and right after it, call wait_for_ajax method.
#
# This methods will wait until Capybara.default_wait_time for the ajax request
@hugomaiavieira
hugomaiavieira / upl.sh
Last active August 29, 2015 14:08 — forked from passalini/upload_to_upl_io.sh
Upload files to upl.io through command line
# This command receives a file as param, upload it to upl.io and copy the url to
# the clipboard
#
# Dependencies: curl and xclip
#
# Install: copy this code to your .bashrc or .zshrc
#
# Example:
#
# $ upload_file ~/Images/algorich-logo.png
@hugomaiavieira
hugomaiavieira / consoles.md
Last active August 29, 2015 14:09
Xbox One vs PS4 (preço)
@hugomaiavieira
hugomaiavieira / bootbox-init.js
Created May 7, 2015 19:40
Js to use bootbox with links
//= require bootbox.min
//
// Open a confirm modal when click in a link.
//
// Dependencies: JQuery and http://bootboxjs.com
//
// Usage:
//
// Add attributes data-confirm-title and data-confirm-message to a link tag or
class MyArray < Array
def initialize(array=[])
super(self.class.ordenar(array))
end
# Utilizando o algorítimo quicksort
def self.ordenar(array)
return array if array.size <=1
pivot = array[0]
@hugomaiavieira
hugomaiavieira / internet-test.sh
Last active September 28, 2015 05:27
Script para verificar se a internet voltou. Quando volta, toca um alarme.
# Verify it a website is back, or the internet access is back. When it is back,
# an alarm rings.
#
# Depends of ticktimer: https://github.com/algorich/ticktimer
#
# Author: Hugo Maia Vieira <hugomaiavieira@gmail.com>
#
while :
do
@hugomaiavieira
hugomaiavieira / all2pdf.sh
Created December 27, 2011 12:17
Script to convert all kind of files in a directory to pdf
#!/bin/bash
#
# a2pdf: Script to convert all kind of files in a directory to pdf
#
# Author: Hugo Maia Vieira <hugomaiavieira@gmail.com>
#
# Dependencies: tree, cedilla, ps2pdf
#
# TODO: Separar em funções "concatenar", "converter" e "concatenar e converter"
# para poderem ser chamadas separadamente.