Skip to content

Instantly share code, notes, and snippets.

@tomazy
tomazy / base.rb
Last active December 17, 2015 20:49
Using data- attributes in SitePrism/Capybara
Capybara.add_selector(:test_element) do
xpath { |name| XPath.css("[data-test-element='#{name}']") }
end
module TestElement
def test_element(name)
element(name, :test_element, name.to_s)
end
def test_sections(section_name, section_class, matcher_name)
require 'selenium/webdriver'
class Selenium::WebDriver::Navigation
alias_method :original_to, :to
def to(url)
url = 'file://reset-session-hack' if url == 'about:blank'
original_to(url)
end
end
@tomazy
tomazy / index.html
Last active December 27, 2015 17:59
backbone.js + knockout.js
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript' src="http://underscorejs.org/underscore-min.js"></script>
<script type='text/javascript' src="http://backbonejs.org/backbone-min.js"></script>
<script type='text/javascript' src="http://knockoutjs.com/downloads/knockout-3.0.0.js"></script>
</head>
</body>
@tomazy
tomazy / knockout-chosen.js
Last active October 6, 2017 14:11
knockout + jquery chosen binding handler http://jsfiddle.net/tomazy/6A57J/
ko.bindingHandlers.chosen = {
init: function(element, valueAccessor, allBindings, viewModel, bindingContext){
var $element = $(element);
var options = ko.unwrap(valueAccessor());
if (typeof options === 'object')
$element.chosen(options);
else
$element.chosen();
@tomazy
tomazy / disable-tests.sh
Last active August 29, 2015 14:08
Disable all javascript/coffe tests
find ./test -name "*-test.coffee"|xargs sed -i '' -e 's/ it / xit /g'
@tomazy
tomazy / console-save.js
Last active August 29, 2015 14:09
console.save
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.1.6'
gem 'rack'
gem 'pg', '0.17.1'
GEMFILE
system 'bundle'
end
@tomazy
tomazy / confirm-overwrite.js
Last active August 3, 2021 18:56
Overwrite `window.confirm` with a custom modal dialog (Rails + jquery-ujs + data-confirm attribute)
(function() { [9/55928]
'use strict';
function showConfirmBox(message, cb) {
var $modal = $('.js-modal-confirm');
var $btnYes = $modal.find('.js-yes')
var $btnCancel = $modal.find('.js-cancel')
$modal.find('.js-message').text(message)
@tomazy
tomazy / snippet.js
Created April 25, 2017 06:09
automate adding codeship env vars from .env file or json
function codeShipSetVars(vars) {
const $blocks = getBlocks();
const keys = Object.keys(vars);
function getBlocks() {
return $('.form_block.environment_variable');
}
function add() {
getBlocks().last().find('button.-good').click();
@tomazy
tomazy / docker-compose.yml
Last active May 22, 2017 15:02
Testing Rails app with Docker containers
# ./docker-compose.yml
version: "3"
services:
app:
build: .
env_file:
- .env
ports:
- 3000:3000 # app
- 35729:35729 # live reload