Skip to content

Instantly share code, notes, and snippets.

View mble's full-sized avatar
🏠
Working from home

Matthew Blewitt mble

🏠
Working from home
View GitHub Profile
#!/usr/bin/env python3
# NAME
# cidr-press - quickly validate a CIDR block without having to think about it
#
# SYNOPSIS
# cidr-press [--cidr-block CIDR_BLOCK] [--file FILE]
import argparse
import ipaddress
@mble
mble / joins_oh_my.sql
Last active August 1, 2017 19:19
Some join benchmarking
-- create some data
create table users (
id serial primary key,
shadowbanned boolean default false
);
create table posts (
id serial primary key,
user_id integer references users(id)
);
@mble
mble / .psqlrc
Created June 23, 2017 15:08
My psqlrc
-- Don't display the "helpful" message on startup.
\set QUIET 1
\pset null '[NULL]'
\pset linestyle unicode
\pset border 2
-- http://www.postgresql.org/docs/9.3/static/app-psql.html#APP-PSQL-PROMPTING
\set PROMPT1 '%[%033[1m%]%M %n@%/%R%[%033[0m%]%# '
-- PROMPT2 is printed when the prompt expects more input, like when you type
-- SELECT * FROM<enter>. %R shows what type of input it expects.
@mble
mble / relational_division_example.sql
Last active June 5, 2017 21:14
Relational Divison
-- Fetch all films two actors appeared in together and order alphabetically
-- film, film_actor and actor tables, with a simple schema
select f.title
from film f
inner join (
select fa.film_id
from film_actor fa
where fa.actor_id in (105, 122)
group by fa.film_id
@mble
mble / median_example.sql
Created June 3, 2017 12:06
Calculating the min, median and max in PostgreSQL
-- Small example demonstrating to calculate the median without using an custom built aggregate function
select
min(score)
-- percentile_cont is a function that returns a value corresponding to the specified fraction in the ordering,
-- interpolating between adjacent input items if needed. By setting the fraction to 0.5, this essentially works
-- as the median of the ordered set provided by the grouping.
, percentile_cont(0.5) with group (order by score) AS median
, max(score)
from result;
  1. Are all builds handled automatically by a Continuous Integration server?
  2. Do you make and use daily builds?
  3. Do you use an issue tracker?
  4. Do you fix bugs before writing new code?
  5. Do you have an up-to-date schedule?
  6. Do you have up to date information on your products performance and usage?
  7. Do you use the best tools money can buy?
  8. Do you have a comprehensive test plan?
  9. Do you have dedicated UI and UX designers?
  10. Does all code go through code review?
@mble
mble / sshd_config
Created March 19, 2017 13:48
Secure SSHD Config
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com
Protocol 2
HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_rsa_key
PasswordAuthentication no
ChallengeResponseAuthentication no
@mble
mble / keybase.md
Created January 24, 2017 17:29
Keybase Verification

Keybase proof

I hereby claim:

  • I am mble on github.
  • I am mble (https://keybase.io/mble) on keybase.
  • I have a public key whose fingerprint is F8EB 5FA1 AF31 4841 A12E 1DCD FA17 3BD9 9CB2 5A39

To claim this, I am signing this object: