Skip to content

Instantly share code, notes, and snippets.

View andyatkinson's full-sized avatar

Andrew Atkinson andyatkinson

View GitHub Profile
@dhh
dhh / linux-setup.sh
Last active November 15, 2024 19:55
linux-setup.sh
# THIS LINUX SETUP SCRIPT HAS MORPHED INTO A WHOLE PROJECT: HTTPS://OMAKUB.ORG
# PLEASE CHECKOUT THAT PROJECT INSTEAD OF THIS OUTDATED SETUP SCRIPT.
#
#
# Libraries and infrastructure
sudo apt update -y
sudo apt install -y \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
-- Carefull setup script is slow
-- SETUP SCRIPT :: START --
DROP TABLE IF EXISTS docs;
CREATE TABLE docs (
id SERIAL PRIMARY KEY,
type varchar(40) DEFAULT 'pdf' NOT NULL,
status varchar(40) NOT NULL,
sender_reference varchar(40) NOT NULL,
sent_at TIMESTAMPTZ,
@GlenCrawford
GlenCrawford / schema_dumper.rb
Created April 17, 2020 13:59
Patching Rails database schema dumps to support multiple PostgreSQL schemas.
# Overrides Rails file activerecord/lib/active_record/schema_dumper.rb to
# include all schema information in the db/schema.rb file, for example, in the
# create_table statements. This allows for a working development database
# to be built from a schema.rb file generated by rake db:schema:dump.
#
# This is essentially a rebuild of the "schema_plus_multischema" gem (which is
# unfortunately only compatible with Rails ~> 4.2).
#
# Tested with Rails 6.0.
@paydro
paydro / default-config-postgres.sql
Last active September 14, 2023 16:24
A base setup for new self-managed postgres databases. See related guide (https://tightlycoupled.io/my-goto-postgres-configuration-for-web-services/). Also, please make sure to change all the passwords from `secret` to something suitable. !! Update !! see this gist for a config that works for self-managed and RDS databases: https://gist.github.co…
CREATE ROLE owner LOGIN ENCRYPTED PASSWORD 'secret' CONNECTION LIMIT 3;
ALTER ROLE owner SET statement_timeout = 20000;
ALTER ROLE owner SET lock_timeout = 3000;
ALTER ROLE owner SET idle_in_transaction_session_timeout = 3000; -- v9.6+
CREATE ROLE readwrite_users NOLOGIN;
CREATE ROLE readonly_users NOLOGIN;
CREATE DATABASE exampledb WITH OWNER owner ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
@mgrider
mgrider / vim-swift-setup.sh
Last active March 22, 2024 01:55 — forked from jlehikoinen/setup.sh
Swift syntax highlighting for Vim
# Swift syntax highlighting for Vim
# Original Source: http://wingsquare.com/blog/swift-script-syntax-highlighting-and-indentation-for-vim-text-editor/
# Another helpful article: https://billyto.github.io/blog/swift-syntax-vim
# More about Vim packages: http://vimcasts.org/episodes/packages/
echo "--- creating ~/.vim/pack/bundle/start dir.."
mkdir -p ~/.vim/pack/bundle/start
echo "--- Cloning Apple's Swift repo.."
@ardentperf
ardentperf / psqlrc.sql
Created May 8, 2019 16:47
ardentperf psqlrc
-- Jeremy Schneider's psqlrc http://ardentperf.com
--
-- see also https://www.citusdata.com/blog/2017/07/16/customizing-my-postgres-shell-using-psqlrc/
--
\set QUIET 1
select case when count(*)=0 then 'select ''not-aurora'' as avers'
else 'select aurora_version() as avers'
end as aurora_version_query
from pg_settings where name='rds.extensions' and setting like '%aurora_stat_utils%' \gset
@fernandoaleman
fernandoaleman / mysql2-mojave.md
Last active February 7, 2024 19:19
Install mysql2 on MacOS Mojave

For MacOS Catalina, visit Install mysql2 on MacOS Catalina

Problem

Installing mysql2 gem errors on MacOS Mojave.

Solution

Make sure openssl is installed on Mac via Homebrew.

@johncip
johncip / rails_eager_load.md
Last active December 23, 2023 15:35
Active Record eager loading strategies

N+1 query problem

  • ORMs make it easy to a query per loop iteration, which we want to avoid

eager_load

  • single query (left outer join)
  • can reference the other table's columns in where

preload

  • a few queries (one per table)
  • typically faster
@a1ip
a1ip / one-liners.md
Last active December 24, 2022 16:02
Useful Mac OS X terminal one-liners in fish shell.
  1. Get your external IP:
    curl -s ipecho.net/plain
  2. Get your internal IP:
    ipconfig getifaddr en0
  3. Test http with netcat: