Skip to content

Instantly share code, notes, and snippets.

sudo rm -rfv /Library/Caches/com.apple.iconservices.store; sudo find /private/var/folders/ \( -name com.apple.dock.iconcache -or -name com.apple.iconservices \) -exec rm -rfv {} \; ; sleep 3; killall Dock; killall Finder
@rob-murray
rob-murray / pi_fix_chrome.sh
Created June 29, 2018 08:46
Script to dismiss "Chrome did not shut down properly" when running in kiosk mode on Raspberry Pi
#!/usr/bin/sh
# Wait for a bit and then click in the top right of the screen to turn off the "chrome did not shut down properly" popup.
sleep 10
export DISPLAY=":0"
xdotool mousemove 1905 20 # change co-ords to suit
xdotool click 1
@rob-murray
rob-murray / lendingbot.service
Created May 31, 2018 20:37
Run BitBotFactory MikaLendingBot as systemd service on Raspberry Pi
[Unit]
Description=LendingBot service
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/python <CODE_DIR>/lendingbot.py
WorkingDirectory=<CODE_DIR>
RestartSec=10
Restart=on-failure
@rob-murray
rob-murray / pg_enums.sql
Last active May 31, 2018 20:27
PG list enums
select n.nspname as enum_schema,
t.typname as enum_name,
string_agg(e.enumlabel, ', ') as enum_values
from pg_type t
join pg_enum e on t.oid = e.enumtypid
join pg_catalog.pg_namespace n ON n.oid = t.typnamespace
group by n.nspname, t.typname
order by enum_name;
@rob-murray
rob-murray / db_force_drop.rake
Last active May 31, 2018 20:28
Postgres: Kill and block incoming connections and then drop the current environment's database. ⚠️:hack:
desc "Kill and block incoming connections and then drop the current environment's database."
task "db:force_drop" => "environment" do
if Rails.env.production? && ENV["DISABLE_DATABASE_ENVIRONMENT_CHECK"] !~ /true|1/
raise "Cannot drop the production database. Disable this with 'DISABLE_DATABASE_ENVIRONMENT_CHECK=true'"
end
db_config = Rails.configuration.database_configuration[Rails.env]
db_name = db_config.fetch("database")
kill_postgres_connections_sql = <<-SQL
SELECT pg_terminate_backend(pg_stat_activity.pid)
@rob-murray
rob-murray / install_ruby.md
Last active November 1, 2017 12:46
Install Ruby

How to install Ruby

MacOS

MacOS High Sierra has Ruby 2.3 installed and El Capitan has Ruby 2.0 - both these should be sufficient for most exercises, but if you would like to install a different version or have an older operating system then follow the instructions below.

Note: these instructions may vary between laptops depending on existing configuration.

  1. Install Xcode command line tools / accept licence
@rob-murray
rob-murray / class_initer.rb
Last active November 13, 2016 10:03
Dynamically instantiate classes by method call, recursive until method call is a class to work with Modules
# Dynamically instantiate classes by method call, recursive until method call is a class to work with Modules
# Given classes Foo and Bar::Foo exist
#
# app.foo => Foo.new
# app.bar.foo => Bar::Foo.new
#
# Note: requires classes to be pre-required/loaded - ie will not work with Rails
# lazy class loading
#
class App
@rob-murray
rob-murray / db_runner.rb
Created November 8, 2016 09:55
Helper to run a database command with given db config
# frozen_string_literal: true
# Helper to run a database command with given db config
class DbRunner
RESTORE_CMD_TEMPLATE = <<-CMD.squish
pg_restore -1 --disable-triggers -a -h %{host} -U %{username} -w -d %{database} #{Rails.root}/tmp/full-dump.pgsql
CMD
BACKUP_CMD_TEMPLATE = <<-CMD.squish
pg_dump --clean -w -U %{username} -d %{database} -h %{host} --format=c --compress=9 -T ar_internal_metadata -T schema_migrations -O > #{Rails.root}/tmp/full-dump.pgsql
CMD
@rob-murray
rob-murray / rails-new.bash
Last active January 14, 2017 18:35
Rails.new type: :test
suspenders test-app \
-d sqlite3 \
--skip-git true \
--skip-bundle true \
--skip-action-cable true \
--skip-test true \
--heroku true \
--heroku-flags "--region eu"
Referenced from http://edgeguides.rubyonrails.org/active_record_basics.html#naming-conventions
## Table naming conventions
Pluralised =>
* User[object] becomes `users` table name
* Person[object] becomes `people` table name