Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
DATABASE_URL="postgres://MyPostgresUser:[email protected]:5432/MyPostgresDB"
# `cut` is used to cut out the separators (:, @, /) that come matched with the groups.
DATABASE_USER=$(echo $DATABASE_URL | grep -oP "postgres://\K(.+?):" | cut -d: -f1)
DATABASE_PASSWORD=$(echo $DATABASE_URL | grep -oP "postgres://.*:\K(.+?)@" | cut -d@ -f1)
DATABASE_HOST=$(echo $DATABASE_URL | grep -oP "postgres://.*@\K(.+?):" | cut -d: -f1)
DATABASE_PORT=$(echo $DATABASE_URL | grep -oP "postgres://.*@.*:\K(\d+)/" | cut -d/ -f1)
@rmoorman
rmoorman / normcore-llm.md
Created September 4, 2023 12:25 — forked from veekaybee/normcore-llm.md
Normcore LLM Reads
@rmoorman
rmoorman / .pylintrc
Created October 26, 2022 21:03 — forked from joepreludian/.pylintrc
Pylint rc file template for django projects. Ignores migrations and test suites.
[MASTER]
profile=no
persistent=yes
ignore=tests.py, urls.py, migrations
cache-size=500
[MESSAGES CONTROL]
# C0111 Missing docstring
# I0011 Warning locally suppressed using disable-msg
# I0012 Warning locally suppressed using disable-msg
@rmoorman
rmoorman / update_primary_key.py
Created October 25, 2022 21:50
Management command to update a primary key and update all child-tables with a foreign key to this table. Updates primary key (and cascade to child tables); Django Version: 1.3
# -*- coding: utf-8 -*-
# code is in the public domain
# (c) 2012 Thomas Güttler http://www.thomas-guettler.de/
#
# http://djangosnippets.org/snippets/2691/
# myapp/management/commands/update_primary_key.py
u'''
Management command to update a primary key and update all child-tables with a foreign key to this table.
@rmoorman
rmoorman / sqlite.abnf
Created October 7, 2022 22:57 — forked from hoehrmann/sqlite.abnf
ABNF for SQLite 3.28 SQL
; FIXME: The grammar has been transformed so that `w` appears after a
; token, but there is no way in ABNF to define it as token-separator
; that can optionally contain a mix of comments and white-space. Take
; `;;` as an example, for that to match `sql-stmt-list` `w` would
; have to match the empty string. But if `w` matches the empty string
; then `ISNOT` is the same as `IS NOT`.
sql-stmt-list = [ sql-stmt ] *( ";" w [ sql-stmt ] )
sql-stmt = [ "EXPLAIN" w [ "QUERY" w "PLAN" w ] ] ( alter-table-stmt / analyze-stmt / attach-stmt / begin-stmt / commit-stmt / create-index-stmt / create-table-stmt / create-trigger-stmt / create-view-stmt / create-virtual-table-stmt / delete-stmt / delete-stmt-limited / detach-stmt / drop-index-stmt / drop-table-stmt / drop-trigger-stmt / drop-view-stmt / insert-stmt / pragma-stmt / reindex-stmt / release-stmt / rollback-stmt / savepoint-stmt / select-stmt / update-stmt / update-stmt-limited / vacuum-stmt )
alter-table-stmt = "ALTER" w "TABLE" w [ schema-name w "." w ] table-na
@rmoorman
rmoorman / sshrc
Created September 18, 2022 20:28 — forked from adzhurinskij/sshrc
/etc/ssh/sshrc example
#!/bin/bash
ip=`echo $SSH_CONNECTION | cut -d " " -f 1`
hostname=`hostname`
fqdn=`hostname -f`
logger -t ssh-wrapper $USER login from $ip
sendmail -t <<EOF
To: Alex <[email protected]>
@rmoorman
rmoorman / ec2hostname.rb
Created June 3, 2022 11:27 — forked from kixorz/ec2hostname.rb
EC2 Instance Route53 Hostname registration init.d script. Instance needs to have the attached IAM instance role policy applied.
#!/usr/bin/ruby
# chkconfig: 35 99 01
# description: EC2 DNS registration
# processname: ec2hostname
require 'aws-sdk'
require 'net/http'
`touch /var/lock/subsys/ec2hostname`
@rmoorman
rmoorman / ec2hostname.rb
Created June 3, 2022 11:26 — forked from kixorz/ec2hostname.rb
EC2 DNS load-balancing init.d script. Instances automatically register themselves in Route53 RecordSets and properly update their records when starting/shutting down. Instances need to use attached IAM role allowing them to modify the Route53 zone.
#!/usr/bin/ruby
# chkconfig: 35 99 01
# description: EC2 DNS loadbalancing
# processname: ec2hostname
require 'aws-sdk'
require 'net/http'
`touch /var/lock/subsys/ec2hostname`
@rmoorman
rmoorman / README.md
Created June 3, 2022 11:25 — forked from tcbyrd/README.md
Route53 CNAME Update

AWS CLI command to update CNAME

When you have a set of application servers running in EC2 in an active/passive configuration, the easiest way to failover is to simply update the DNS to point to the second server as soon as it's available to serve requests. If you are using Route 53 to manage your DNS configuration, with the AWS CLI you can make this change in a single command.

Initial Setup

The CLI expects the change to be submitted via a JSON-formatted configuration file. I've inclu

@rmoorman
rmoorman / email.exs
Created November 20, 2021 12:42 — forked from daemonfire300/email.exs
Simple shot at implementing an email validator for use with `Ecto.Changeset`
defmodule YourApp.Validators.Email do
use Ecto.Changeset
@mail_regex ~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/
# ensure that the email looks valid
def validate_email(changeset, field) do
changeset
|> validate_format(field, @mail_regex)
end
end