Skip to content

Instantly share code, notes, and snippets.

@mycargus
mycargus / docker-reset
Created January 17, 2023 20:14
I use this script to quickly clean my docker environment as needed. See script comments for an explanation. I usually add this script as a file to ~/bin/docker-reset , and add `alias dr='docker-reset'` to my ~/.bashrc
#!/usr/bin/env bash
# Purpose: reset docker environment
# Argument (optional): all | networks
#
# "docker-reset" will kill and remove all containers (except dinghy-http-proxy),
# dangling images, and volumes. It won't remove networks.
#
# "docker-reset all" will kill and remove all containers (including
# dinghy-http-proxy) and remove all networks, too.
@mycargus
mycargus / pre-commit.sh
Last active September 27, 2018 13:34 — forked from dahjelle/pre-commit.sh
Pre-commit hook for eslint, linting *only* staged changes.
#!/bin/bash
for file in $(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|jsx)$')
do
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
exit 1 # exit with failure status
fi
done
@mycargus
mycargus / Rakefile
Created May 10, 2018 23:17
repeat spec(s) until failure
require_relative 'task_helpers'
desc 'Repeat e2e spec(s) until failure (default :max_number_of_repetitions = 100)'
task :repeat, [:max_number_of_repetitions] do |_t, args|
maximum_repetitions = args[:max_number_of_repetitions] ? args[:max_number_of_repetitions].to_i : 100
test_run = 'docker-compose run --rm testrunner bundle exec rspec spec'
Console.log_info "\n Executing #{maximum_repetitions} times (or until failure):"
Console.log_info "\n\t '#{test_run}'"
@mycargus
mycargus / suppress_output.rb
Created October 20, 2017 18:03
Ruby method to suppress output as desired on any platform. Credit: Avdi Grimm
def suppress_output(out: true, err: false)
null = open(File::NULL, "w")
old_out = $stdout.dup
old_err = $stderr.dup
$stdout.reopen(null) if out
$stderr.reopen(null) if err
yield
ensure
$stdout.reopen(old_out)
$stderr.reopen(old_err)
heroku pg:reset DATABASE_URL --app <APP>
heroku run bin/rails db:migrate --app <APP>
heroku run bin/rails db:seed --app <APP>
heroku restart --app <APP>
@mycargus
mycargus / seed.rb
Created March 31, 2017 15:44
You can save this file and run it in a rails runner like so: 'bundle exec rails runner seed.rb'. Or you can simply copy/paste into a rails console.
require 'spec/factories/course_factory'
require 'spec/factories/user_factory'
include Factories
# Create, register, and enroll teacher
course_with_teacher(
active_course: 1,
active_enrollment: 1,
course_name: 'E2E Course',
@mycargus
mycargus / .bashrc
Last active December 15, 2020 18:22
useful docker commands
# Purpose: reset docker environment
# Argument (optional): all
#
# "docker-reset" will kill and remove all containers (except dinghy-http-proxy),
# dangling images, and volumes. It won't remove networks.
#
# "docker-reset all" will do everything in 'docker-reset' and remove all
# networks, too.
#
@mycargus
mycargus / _submit.html.haml
Created March 16, 2017 16:05
example @user form for step #3
= form_for @user do |f|
.row
.small-12.columns
.field
= f.text_field :name
.field
= f.text_field :company
.field
= f.text_field :email
.field
@mycargus
mycargus / snippet.rb
Last active March 3, 2017 12:40
generate a random string of length n of single-digit numbers
Array.new(n) { [*'0'..'9'].sample }.join
# example use case: generate a random USA phone number (no parantheses or hyphens), e.g. 9875551234
Array.new(10) { [*'0'..'9'].sample }.join