Skip to content

Instantly share code, notes, and snippets.

View cam8001's full-sized avatar
💭
lol no

Cameron Tod cam8001

💭
lol no
  • Amazon Web Services
  • Wellington, New Zealand
  • 00:31 (UTC +12:00)
View GitHub Profile
@cam8001
cam8001 / awscli.bash
Created May 6, 2019 04:55
awscli quick reference
# From here:
# https://blog.ashiny.cloud/page/awscli-query-quickref/
#!/bin/bash -ex
export AWS_REGION=your-region-here
export AWS_PROFILE=your-cli-access-profile-here
export AWS_DEFAULT_OUTPUT=text
# Get your user ARN
aws iam get-user --query 'User.Arn'
@cam8001
cam8001 / purge_buckets.sh
Created February 5, 2019 02:16
Remove all s3 buckets in AWS CLI
#!/bin/bash
aws s3 ls | cut -d" " -f 3 | xargs -I{} aws s3 rb s3://{} --force
@cam8001
cam8001 / all_apple_ips.txt
Created January 26, 2019 07:21
All Apple IP address ranges. Useful for firewall rules.
# Generated by:
# ASN=AS714; whois -h whois.radb.net -- "-i origin $ASN" | awk '/^route:/ {print $2;}' | sort | uniq
# @see https://ipinfo.io/AS714
#
# ASN=AS6185; whois -h whois.radb.net -- "-i origin $ASN" | awk '/^route:/ {print $2;}' | sort | uniq
# @see https://ipinfo.io/AS6185
144.178.0.0/18
144.178.0.0/19
144.178.48.0/21
144.178.56.0/21
@cam8001
cam8001 / yum-debug-variables.py
Created July 17, 2018 01:04
Show yum variables as referenced in the files in /etc/yum.repos.d/
python -c 'import yum, pprint; yb = yum.YumBase(); pprint.pprint(yb.conf.yumvar, width=1)'
@cam8001
cam8001 / apple_font_fix.md
Last active July 6, 2018 09:26
Fix for fonts appearing bold in web sites (Verdana in my case)

Fonts appear bold across webpages

I installed a new Mac and was perplexed by fonts appearing bold across both Safari and Firefox.

It turns out, for some reason, the 'Regular' font weight for Verdana had been disabled system wide.

To fix:

  • Using browser dev tools, inspect an element, and use the 'computed' tab to figure out which font is looking incorrect
  • Open Font Book.app
  • Find the font
@cam8001
cam8001 / show_passwords.js
Created January 8, 2018 03:15
Convert password fields to plain text
// Readable version
inputs = document.getElementsByTagName('input');
for (i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'password') {
inputs[i].type = 'text'
}
}
// Bookmarklet version
javascript:(function()%7Binputs%20%3D%20document.getElementsByTagName('input')%3Bfor%20(i%3D0%3B%20i%20%3C%20inputs.length%3B%20i%2B%2B)%20%7B%20if%20(inputs%5Bi%5D.type%20%3D%3D%20'password')%20%7Binputs%5Bi%5D.type%20%3D%20'text'%7D%7D%7D)()
@cam8001
cam8001 / mysql_performance.sql
Created November 12, 2017 23:27
See average length of queries
Select * From Information_Schema.Query_Response_Time;
+----------------+-------+------------+
| time | count | total |
+----------------+-------+------------|
| 0.000001 | 0 | 0.000000 |
| 0.000010 | 17 | 0.000094 |
| 0.000100 | 4301 | 0.236555 |
| 0.001000 | 1499 | 0.824450 |
| 0.010000 | 14851 | 81.680502 |
| 0.100000 | 8066 | 443.635693 |
@cam8001
cam8001 / dump_all_mysql_dbs.sh
Created October 6, 2017 02:02
Dump all databases on local machine to seperate, gzipped files in local directory.
#!/bin/bash
# Dumps all databases into separate, gzipped files.
DATABASES=`mysql -NB -e "SHOW DATABASES;" | \egrep -v "Database|information_schema|performance_schema|mysql"`
DUMP_DATE=`date +%Y-%m-%d`
for DB in $DATABASES; do
FILENAME=$DUMP_DATE.$DB.sql
echo "Dumping database: $DB to $FILENAME"
mysqldump $DB | pv > $FILENAME
@cam8001
cam8001 / find_largest_tables.sql
Created October 4, 2017 04:38
Find largest tables in database
SELECT CONCAT(table_schema, '.', table_name),
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length + index_length DESC
LIMIT 10;
@cam8001
cam8001 / innodb_index_size.sql
Last active October 4, 2017 04:37
Find overhead of MyISAM or InnoDB
SELECT IFNULL(B.engine,'Total') "Storage Engine",
CONCAT(LPAD(REPLACE(FORMAT(B.DSize/POWER(1024,pw),3),',',''),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Data Size", CONCAT(LPAD(REPLACE(
FORMAT(B.ISize/POWER(1024,pw),3),',',''),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Index Size", CONCAT(LPAD(REPLACE(
FORMAT(B.TSize/POWER(1024,pw),3),',',''),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Table Size"
FROM (SELECT engine,SUM(data_length) DSize,SUM(index_length) ISize,
SUM(data_length+index_length) TSize FROM information_schema.tables
WHERE table_schema NOT IN ('mysql','information_schema','performance_schema')