Pair programming com Visual Studio Code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def change_state | |
object = Object.find(params[:object_id]) | |
object.send(params[:event] + '!') | |
redirect_to params[:redirect_to] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def changing_ending_char(string) | |
ending_chars = { | |
'!' => :_dangerous, | |
'?' => :_question | |
} | |
string.gsub(/(?<char>[\?|\!])/, ending_chars) | |
end | |
changing_ending_char('asd') # => 'asd' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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=$? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="import" href="../components/polymer/polymer.html"> | |
<polymer-element name="my-element"> | |
<template> | |
<style> | |
:host { | |
position: absolute; | |
width: 100%; | |
height: 100%; |
NewerOlder