Skip to content

Instantly share code, notes, and snippets.

@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 <adzhurinskij@gmail.com>
@rmoorman
rmoorman / install-ghc-cabal.md
Created November 22, 2012 10:28 — forked from ion1/install-ghc.md
Installing GHC and Cabal under the home directory

Installing GHC and Cabal under the home directory

  1. Install libgmp-dev libgmp3c2 or equivalent using the system package manager.
  2. Add export PATH="$HOME/.ghc/bin:$HOME/.cabal/bin:$PATH" to your .<shell>rc.
  3. Also run the command above now.
  4. Get the [GHC binary tarball][ghc] and extract it.
  5. ./configure --prefix="$HOME/.ghc" && make install
  6. Get the [cabal-install source tarball][cabal] and extract it.
  7. EXTRA_CONFIGURE_OPTS=-p sh bootstrap.sh
  8. cabal update
@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 / Makefile
Created October 17, 2017 16:33 — forked from pitchart/Makefile
makefile for symfony projects
CONSOLE=php app/console
COMPOSER=php -d "apc.enable_cli=0" ../composer.phar
PHPUNIT=php bin/phpunit
init: git-clone install
install: git-subup composer-install cache-clear assets db cache-clear
update: git-update git-subup composer-install db-update cache-clear composer-optimize test-unit
@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
@rmoorman
rmoorman / registration_controller.ex
Created November 20, 2021 12:29 — forked from abitdodgy/registration_controller.ex
Medium Article: Building Many-To-Many Associations with Embedded Schemas in Ecto and Phoenix
defmodule App.RegistrationController do
use App.Web, :controller
alias App.{Registration, Repo}
def new(conn, _params) do
changeset = Registration.changeset(%Registration{})
render conn, :new, changeset: changeset
end
def create(conn, %{"registration" => registration_params}) do
@rmoorman
rmoorman / instructions.md
Created September 12, 2021 22:21 — forked from wosephjeber/instructions.md
Ecto migration for renaming table with indexes and constraints

Renaming table in Ecto migration

I recently wanted to rename a model and its postgres table in a Phoenix app. Renaming the table was simple and documented, but the table also had constraints, sequences, and indexes that needed to be updated in order for the Ecto model to be able to rely on default naming conventions. I couldn't find any examples of what this would look like but was eventually able to figure it out. For anyone else in the same situation, hopefully this example helps.

In the example below, I'm renaming the Permission model to Membership. This model belongs to a User and an Account, so it has foreign key constraints that need to be renamed.

defmodule MyApp.Repo.Migrations.RenamePermissionsToMemberships do
  use Ecto.Migration