Skip to content

Instantly share code, notes, and snippets.

View johnmeehan's full-sized avatar
:octocat:

John Meehan johnmeehan

:octocat:
  • Meetyl
  • Ireland
View GitHub Profile
@johnmeehan
johnmeehan / Readme.md
Created November 13, 2020 11:21
Personal Gitignore within a project

Add a personal .gitignore to a project.

Within the project git config --local -e

[core]
    ... (existing configurations)
    excludesfile = ~/Documents/my_repo/.john_gitignore
[remote "origin"]
@johnmeehan
johnmeehan / index.html
Created October 18, 2020 18:34
Stimulus js Checkbox toggle
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="main.css">
<script src="bundle.js" async></script>
</head>
<body>
<div data-controller="toggler">
<label>Toggle Me</label>
@johnmeehan
johnmeehan / README.md
Created June 4, 2020 08:56
Log a timeout warning before it times out and unicorn kills the worker.

Log Before Timeout

Logs a timeout warning before unicorn kills the worker.

If something is running long enough for unicorn to want to kill it then its worth spending the time fixing. If the process is killed you will never know why it failed.

This will add a warning after 30 seconds and another one 1second before unicorn kills it.

How it works:

It adds a middleware that sits on the Rack layer between Unicorn and Rails. It creates a timer Thread that sleeps for a set amount of time and if the current thread is still running then log a warning.

@johnmeehan
johnmeehan / settings.json
Created November 19, 2019 23:41
Vscode settings
{
"workbench.colorTheme": "Monokai",
"workbench.iconTheme": "city-lights-icons-vsc-light",
// Basic settings: turn linter(s) on
"ruby.lint": {
"rubocop": {
"lint": true, //enable all lint cops.
"only": [/* array: Run only the specified cop(s) and/or cops in the specified departments. */],
"except": [/* array: Run all cops enabled by configuration except the specified cop(s) and/or departments. */],
"forceExclusion": true, //Add --force-exclusion option
@johnmeehan
johnmeehan / development.rb
Created June 18, 2018 14:55
Middleware to print to the screen so I can see the responses when streaming data
# app/config/environments/development.rb
# Middleware to print to the screen so I can see the responses when streaming data
config.middleware.use(
Class.new do
def initialize(app)
@app = app
end
def call(env)
@johnmeehan
johnmeehan / directions.rb
Created May 21, 2018 13:04
Google Distance Matrix and Directions API
# lib/google_map/directions.rb
# Calls the google maps directions api
# https://developers.google.com/maps/documentation/directions/intro
# Useage:
# gm = GoogleMap::Directions.new({origin: '52.662377,-8.630171', destination: '52.635720, -8.654714'})
# gm.call
module GoogleMap
class Directions
include HTTParty
base_uri 'https://maps.googleapis.com/maps/api'
@johnmeehan
johnmeehan / attachment.rb
Last active October 6, 2017 10:31
Obfuscated Download Links - How to add an obfuscated download link to a downloadable attachment.
# Rails side:
# 1. Attachment.rb model needs a token method that encrypts the model id.
class Attachment < ActiveRecord::Base
mount_uploader :file, AttachmentUploader
# Add this
def self.find_by_token(token)
begin
find(UrlParamEncryptor.decrypt(token))
@johnmeehan
johnmeehan / README.md
Last active July 4, 2017 13:09
Homebrew: reinstall packages on another computer

Transfer Homebrew Packages

I want to install my homebrew packages on another computer.

brew leaves - shows you all top-level packages.

brew leaves > installed_homebrew_packages.txt

cat installed_homebrew_packages.txt | xargs brew install
@johnmeehan
johnmeehan / browserstack.md
Last active March 1, 2020 22:10
Browserstack + Rails5 + RSpec + Capybara

Browserstack

My setup for configuring a Rails app with RSpec Feature tests that uses Capabara to test on a browserstack remote browser.

The browserstack docs only show either an RSpec or a Capabara setup.

What I wanted:

  1. In development run my tests quickly with poltergiest.
  2. Run nightly builds on CI to test against different web browsers using browserstack.
  3. Have the option to visually run my tests with selenium with Chrome, Firefox etc.
@johnmeehan
johnmeehan / wait_for_ajax.rb
Created March 8, 2017 15:39
RSpec, Capyabara, Poltergiest, Angular, jQuery wait_for_ajax
# spec/support/wait_for_ajax.rb
# # Angular, Rails, Capybara, wait for ajax
# Useage:
# click_link("Send an ajax request")
# wait_for_ajax
# expect(page).to have_content("expected ajax response message")
module WaitForAjax
def wait_for_ajax(max_wait_time = 30)
Timeout.timeout(max_wait_time) do
while pending_ajax_requests?