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
@waldofe
waldofe / gist:9282553
Created March 1, 2014 00:04
Rspec failing tests rerun script
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
}
@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=$?
@skvggor
skvggor / solve.sh
Created September 8, 2013 15:54
Resolve o warning `Warning: watch ENOSPC` quando a tarefa GruntJS é chamada via terminal.
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
@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 / 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
@elgalu
elgalu / .irbrc
Last active January 29, 2018 16:33
IRB / Pry copy last result, a.k.a `_`, to your OSX / Linux / Windows clipboard using the 'clipboard' gem
require 'clipboard' #gem install clipboard
def cbcopy(value)
Clipboard.copy value unless value.empty?
flash_message = value.empty? ? "Sorry, nothing to copy" : "Copied to clipboard"
print "# #{flash_message}: "
puts %Q("#{value}")
end
# Copy last result to the Clipboard
@bricker
bricker / promises.md
Last active March 14, 2018 00:33
Promises in Rails callbacks, using after_save and after_commit together.

"Russian-Doll Caching" is great. It embraces the Rails (and Ruby) goal to "make the developer happy". And it does. Not having to worry about cache expiration is superb.

It has its limits, though. If you're trying to avoid any database queries, russian-doll caching will not work for you. If you are trying to represent thousands, or even hundreds, of objects under a single cache fragment, russian-doll caching is not the best option.

We use it whenever it makes sense, but sometimes we just have to bite the bullet and expire a cache fragment manually. When you want to start manually expiring cache on a fairly busy website, you have to start considering race conditions. I recently ran into the following scenario:

class Post < ActiveRecord::Base
  after_save :expire_cache
  
@racheldonovan
racheldonovan / wysihtml5_helper.rb
Created April 18, 2013 21:55
a helper to assit in integration testing (rspec / capybara) wysihtml5 text editors.
module Wysihtml5Helper
def fill_in_wysihtml5(text)
#js must be enabled
page.execute_script("editor.setValue('#{text}')")
end
end
@CampAsAChamp
CampAsAChamp / LetsSplitFlashingGuide.md
Last active February 3, 2021 18:46
Let's Split Flashing Guide for Windows

A Guide to Flashing a Let's Split for Beginners (Windows)


This guide is no longer being updated and instead has moved to GitHub (click and scroll down)


3 Main Steps

  • Setting Up and Installing Software
  • Building your keymap and keyboard firmware