Skip to content

Instantly share code, notes, and snippets.

View passalini's full-sized avatar

Pedro Henrique Passalini passalini

  • Campos dos Goytacazes
View GitHub Profile
@passalini
passalini / gist:6614466
Last active December 23, 2015 09:29
test chosen (ajax) with capybara
within('.chzn-search') do
find('input').set element_name
end
sleep(1)
within(".chzn-results") do
find('li.active-result').click
end
@passalini
passalini / foo.rb
Created November 26, 2013 17:38
Multiple assertions with rspec change
class Foo
attr_reader :bar, :buzz
def initialize
@bar = 1
@buzz = 1
end
def add
@bar += 1
@passalini
passalini / gist:9388731
Last active August 29, 2015 13:57 — forked from waldofe/gist:9282553
zrun, to run specs and save the ones tha fail
function zrun() {
SPEC_FILE=$1
SPEC_LOG=/tmp/rspec.log
if [ $SPEC_FILE ]; then
rspec $SPEC_FILE 2>&1 | tee $SPEC_LOG
else
cat $SPEC_LOG | grep "^rspec" | cut -d ' ' -f 2 | xargs rspec 2>&1 | tee $SPEC_LOG
fi
}
<link rel="import" href="../components/polymer/polymer.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
@passalini
passalini / directive.js
Created July 14, 2014 19:51
check passwords with angularjs's directive
.directive('equals', function() {
return {
restrict: 'A', // only activate on element attribute
require: '?ngModel', // get a hold of NgModelController
link: function(scope, elem, attrs, ngModel) {
if(!ngModel) return; // do nothing if no ng-model
// watch own value and re-validate on change
scope.$watch(attrs.ngModel, function() {
validate();
@passalini
passalini / upload_to_upl_io.sh
Last active August 29, 2015 14:04
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
#
# install: copy this code to your .bashrc or .zshrc
# dependencies: curl and xclip
# example: $ upload ~/Images/image.png
upload_file() {
echo 'Uploading...'
url=`curl http://upl.io -F file=@$1 -s -f`
curl_response=$?
@passalini
passalini / to_timestamp.rb
Created October 24, 2014 12:43
Milliseconds to timestamp
# based in http://stackoverflow.com/a/10874157
def to_timestamp(x)
y = 60*60*1000
h = x/y
m = (x-(h*y))/(y/60)
s = (x-(h*y)-(m*(y/60)))/1000
mi = x-(h*y)-(m*(y/60))-(s*1000)
string = "#{h.to_s.rjust(2, '0')}:#{m.to_s.rjust(2, '0')}:#{s.to_s.rjust(2, '0')},#{mi.to_s.rjust(3, '0')}"
end
@passalini
passalini / wait_for_ajax.rb
Last active April 7, 2017 14:08
Rspec/Capybara configuration to wait ajax
# 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
@passalini
passalini / changin_ending_char.rb
Created November 13, 2014 18:19
Using gsub with strings and hash
def changing_ending_char(string)
ending_chars = {
'!' => :_dangerous,
'?' => :_question
}
string.gsub(/(?<char>[\?|\!])/, ending_chars)
end
changing_ending_char('asd') # => 'asd'
@passalini
passalini / object_controller.rb
Last active August 29, 2015 14:27
RailsAdmin aasm
def change_state
object = Object.find(params[:object_id])
object.send(params[:event] + '!')
redirect_to params[:redirect_to]
end