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 / 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 / Dockerfile
Created November 23, 2014 20:48
Docker + fig with mounted volume for dev environment (and correctly handles bundle install).
# Base image.
FROM fotinakis/baseimage-ruby:2.1.3
# System dependencies for gems.
RUN apt-get update
RUN apt-get install -y --no-install-recommends libmysqlclient-dev
# Add 'web' user which will run the application.
RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos ""
@fotinakis
fotinakis / target-application-actions.js
Last active August 29, 2015 14:14
Mixin to make nested Ember components skip bubbling actions to parent components (slightly hacky)
import Ember from 'ember';
/**
Targets a component's actions to bubble immediately to the application controller and
through the route hierarchy, skipping any parent component action handlers.
This allows us to avoid passing redundant args like:
<my-component myAction={{action "myAction"}} myOtherAction={{action "myOtherAction"}}>
...through many layers of nested components, at the cost of highly-coupling the actions
@fotinakis
fotinakis / hide-text.js
Last active January 31, 2017 21:04
Pure JavaScript: Hide all text on the page but preserve element spacing.
function textNodesUnder(el){
var n, a = [];
var walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT, null, false);
while (n = walk.nextNode()) { a.push(n); }
return a;
}
// Normalize all text nodes (merge adjacent nodes).
var elements = document.getElementsByTagName('*');
for (var i = 0; i < elements.length; i++) {
@fotinakis
fotinakis / gist:9c52c0b1180ca71faaaf
Created April 17, 2015 21:04
Sublime reveal_in_side_bar key binding
[
{ "keys": ["alt+."], "command": "reveal_in_side_bar" }
]
@fotinakis
fotinakis / do.sql
Created May 6, 2015 01:28
SQL: create a new user, grant all privileges, and require SSL
CREATE USER 'some_user'@'%' IDENTIFIED BY '<autogenerated password here>';
GRANT ALL PRIVILEGES ON dbname.* TO 'some_user'@'%' REQUIRE SSL;
@fotinakis
fotinakis / spec_helper.rb
Last active August 29, 2015 14:20
Pure-Rails timefreeze and flaky-ness removal for all specs
RSpec.configure do |config|
# Freeze time and truncate microseconds in all examples.
config.around(:each) do |example|
# Truncate microseconds to avoid test flakiness when the DB truncates microseconds
now_without_microseconds = Time.now.in_time_zone.change(usec: 0)
travel_to(now_without_microseconds) do
example.run
end
end
end
@fotinakis
fotinakis / percy-uploader.rb
Last active August 29, 2015 14:21
Upload a static website folder to Percy
#!/usr/bin/env ruby
#
# Usage:
# chmod +x percy-uploader.rb
# PERCY_TOKEN=<PERCY-REPO-WRITE-TOKEN> ./percy-uploader.rb
require 'percy'
require 'find'
require 'digest'
@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