Skip to content

Instantly share code, notes, and snippets.

View convert-rails-secrets.rb
#!/usr/bin/env ruby
#
# Convert structured Ruby credentials to JSON that can be easily copy/pasted
# into an EJSON secrets file.
#
# Usage:
#
# rails credentails:show --environment staging | ./conv.rb
require 'yaml'
View captive-dns.conf
firewall {
name GUEST_IN {
default-action accept
description "packets from guest network"
rule 1000 {
action accept
description "allow DNS to pihole"
destination {
address 10.65.49.3
@mroach
mroach / magic_trackpad_battery_logger.sh
Created Jul 30, 2018
Logs Magic Trackpad 2 battery life to log file with timestamp
View magic_trackpad_battery_logger.sh
#!/bin/bash
set -e
tmpfile="${TMPDIR}sys_bluetooth_$(date +%s).plist"
# dump data to temp plist file
/usr/sbin/system_profiler -xml SPBluetoothDataType > "$tmpfile"
# read battery percentage from tempfile and delete percent sign
@mroach
mroach / wee-slack-setup.sh
Created Jun 6, 2018
Setting-up wee-slack
View wee-slack-setup.sh
# deps
pip2 install websocket-client
# weechat itself
brew install weechat --with-aspell --with-python@2
# wee-slack
mkdir -p ~/.weechat/python/autoload
curl -o ~/.weechat/python/autoload/wee_slack.py https://raw.githubusercontent.com/wee-slack/wee-slack/master/wee_slack.py
@mroach
mroach / date_time_demo.rb
Created Mar 13, 2018
DateTime and Time math
View date_time_demo.rb
# When adding or subtracting DateTime objects, the return type is a Rational expressing the fraction of a day's number of minutes (1440). So 0.5 would mean half a day, or 720 minutes, or 12 hours.
# When adding or subtracting Time objects, the return type is Float expressing the difference in seconds.
#Here's an example showing the difference between two times that are an hour apart:
MINUTES_IN_A_DAY = 1440
ref1 = "2018-03-13T08:00:00+00:00"
ref2 = "2018-03-13T09:00:00+00:00"
# -3600 = 3600 seconds ago, i.e. 1 hour ago
Time.zone.iso8601(ref1) - Time.zone.iso8601(ref2)
@mroach
mroach / Gemfile
Last active Mar 16, 2017
Bootstrapping testing
View Gemfile
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
# Spec testing
gem 'rspec-rails'
# Code coverage analysis
gem 'simplecov', require: false
View osx_pg_fix.sh
#!/bin/bash
# If your system crashes or shuts-down hard, the PostgreSQL PID file is left
# behind and then it won't startup when your system restarts. Run this script
# to check if it's ok to delete the PID file and start PostgreSQL
prefix=$(brew --prefix)
pid_path="$prefix/var/postgres/postmaster.pid"
if [ ! -f "$pid_path" ]; then
@mroach
mroach / _breadcrumbs.html.slim
Last active Aug 29, 2015
breadcrumbs_on_rails builder for Semanti UI breadcrumbs
View _breadcrumbs.html.slim
- unless breadcrumbs.empty?
div.ui.breadcrumb
= render_breadcrumbs builder: BreadcrumbsOnRails::Breadcrumbs::SemanticUiBuilder
View gist:a86279af0b027266aa7e
- name: Disable Challenge-Response authentication
lineinfile:
dest=/etc/ssh/sshd_config
regexp="^ChallengeResponseAuthentication"
line="ChallengeResponseAuthentication no"
state=present
notify: restart ssh
# OR