Skip to content

Instantly share code, notes, and snippets.

@fotinakis
fotinakis / cancan_matchers.rb
Last active December 8, 2023 14:18
Custom rspec matcher for testing CanCan abilities
# Custom rspec matcher for testing CanCan abilities.
# Originally inspired by https://github.com/ryanb/cancan/wiki/Testing-Abilities
#
# Usage:
# should have_abilities(:create, Post.new)
# should have_abilities([:read, :update], post)
# should have_abilities({manage: false, destroy: true}, post)
# should have_abilities({create: false}, Post.new)
# should not_have_abilities(:update, post)
# should not_have_abilities([:update, :destroy], post)
@fotinakis
fotinakis / nginx-default-site.conf
Created May 13, 2021 18:33
Percy GitHub Enterprise - example nginx proxy configuration
daemon off;
events {
worker_connections 1024;
}
http {
server {
listen 443 ssl;
location / {
@fotinakis
fotinakis / _mdl_accordion.sass
Created September 11, 2015 21:55
(Material Design Light) MDL Accordion
// From @nickretallack - http://nickretallack.com/experiments/mdl/collapse/index.html
.mdl-accordion.mdl-accordion--opened
border-top: 1px solid #e0e0e0
border-bottom: 1px solid #e0e0e0
margin-top: -1px
.mdl-accordion.mdl-accordion--opened + .mdl-accordion.mdl-accordion--opened
border-top: none
margin-top: 0
@fotinakis
fotinakis / example.rb
Created September 22, 2020 20:17
Percy Projects API example
# Could also use the low-level ruby API client to make these calls: https://github.com/percy/percy-client
@fotinakis
fotinakis / Jenkins auto-shudown-slaves job
Last active July 6, 2020 08:56
Auto-managed Jenkins slaves on Google Compute Engine
#!/bin/bash
# Have to redirect stderr to stdout here because slave.py uses stderr for output.
~/bin/slave.py list 2>&1 >/dev/null | grep beaker-slave- | while read slave; do
echo
echo "Checking status of $slave..."
# First, check if we can SSH into the host. If we can, then check the process and maybe shut down.
# This makes sure that we don't consider an SSH failure to be reason to shut down the node.
if ssh $slave echo < /dev/null; then
@fotinakis
fotinakis / README.md
Last active April 20, 2019 19:39
Fix Ember test timeouts on Circle CI

(See upstream testem PR: testem/testem#819)

Since around 2012, WebKit and other browsers have throttled timers (like setTimeout) to only a max of once per second in inactive tabs.

For some test suites, this may never be an issue. But, for example, in a very large Ember test suite with >1000 acceptance tests and much custom code, it manifested as often flaky and non-deterministic test timeouts, even in headless CI environments with Chrome in xvfb.

This has caused much much testing pain that might manifest as the not-obviously-related error: Error: timeout of 10000ms exceeded. Ensure the done() callback is being called in this test.

@fotinakis
fotinakis / canvas-to-image.js
Created April 17, 2019 16:38
Convert WebGL canvas to static img in place
function canvasToImage(canvas) {
const {top, left, height, width} = canvas.getBoundingClientRect();
const mapImage = document.createElement('img');
mapImage.setAttribute('src', canvas.toDataURL('image/png'));
mapImage.setAttribute('style', `position: absolute; z-index: 2147483638; top: ${top}px; left: ${left}px; width: ${width}px; height: ${height}px;`);
document.body.appendChild(mapImage);
};
// Convert all canvas elements on the page to images.
document.querySelectorAll('canvas').forEach((canvas) => {
@fotinakis
fotinakis / circle ci
Last active September 27, 2018 02:34
Percy manual build finalization for Circle 2.0 and other parallel CI workflows.
jobs:
# ...
percy_finalize:
docker:
- image: circleci/node:10
steps:
- run: npm install percy-client
- run: node .circleci/percy-finalize.js
workflows:
@fotinakis
fotinakis / gist:ea3e315d99b3a3d301fd98b74e5c0728
Created June 6, 2018 04:53
git setup for maximum risk/reward
git config --global push.default current
git config --global pull.default current
@fotinakis
fotinakis / percy_loader.rb
Created October 3, 2017 22:22
Custom Percy::Capybara SprocketsLoader that changes path
class CustomLoader < Percy::Capybara::Loaders::SprocketsLoader
def build_resources
super.map do |resource|
resource.resource_url = resource.resource_url.gsub('//localhost:3000/', '/')
end
end
end
Percy::Capybara.use_loader(CustomLoader)