Skip to content

Instantly share code, notes, and snippets.

@rgarner
rgarner / monkey_futz.rb
Last active August 29, 2015 14:03
Futz random-ish input to import_mappings
#!/usr/bin/env ruby
if ARGV.length != 1
puts 'Usage: monkey-futz <host>'
exit 1
end
@host = ARGV.first
TYPES = [:archive,
@rgarner
rgarner / thing.md
Last active August 29, 2015 14:03
Silly Postgres truth

SELECT L <> R FROM table;

L R L <> R L IS DISTINCT FROM R
NULL NULL NULL f
1 NULL NULL t
NULL 1 NULL t
1 1 f f
1 2 t t
@rgarner
rgarner / fix.sh
Created June 27, 2014 17:46
Fix invalid UTF8 byte sequences in TSVs
##
# Find CDN output that has invalid UTF8 byte sequences.
# Fix them.
#
# NB: This requires an iconv that supports --byte-subst
#
FAILURES=utf8_failures
FAILURE_STRING=__WUBWUB__
@rgarner
rgarner / fix_bad_cdn_utf8.sh
Last active August 29, 2015 14:03
Find CDN failures
##
# Find CDN output that has invalid UTF8 byte sequences.
# Fix them.
#
# NB: This requires an iconv that supports --byte-subst
#
FAILURES=utf8_failures
FAILURE_STRING=__WUBWUB__
@rgarner
rgarner / psql-cheat-sheet.md
Last active August 29, 2015 14:02
Developer's new-to-PSQL cheat sheet

PSQL cheat sheet

Starting it (examples)

Command (shell) Does this
psql Starts psql connected to your own user's database
psql -d <database> Starts psql connected to the given <database>
cat some.sql | psql -d <database> Runs the SQL script in some.sql on <database>
@rgarner
rgarner / progress.sh
Created June 10, 2014 07:48
Track the progress of an index build for a table in a mysql database directory
ls -alh | awk -v table_name=$1 '
BEGIN {
if(table_name == "") {
print "table_name required"
exit(1)
}
myi = table_name ".MYI"
myd = table_name ".MYD"
}
$9 ~ /#.*MYD/ {
for i in {5..100..5}
do
PATHS="coverage/defra_darwin.txt"
bin/hits coverage -t $i logfiles/defra_darwin/darwin.defra.gov.uk > $PATHS
COUNT=`wc -l $PATHS`
git add $PATHS
git commit -m "$COUNT paths with >= $i all-time hits"
done
@rgarner
rgarner / Worst.sql
Created April 8, 2014 14:01
Worst things first things
SELECT m.path,
Sum(h.count) AS hit_count
FROM mappings m
INNER JOIN sites s
ON m.site_id = s.id
LEFT JOIN hits h
ON h.mapping_id = m.id
WHERE s.id = 50
GROUP BY m.path_hash
ORDER BY hit_count DESC
@rgarner
rgarner / 5.5.output.sql
Last active August 29, 2015 13:57
MySQL go home you're drunk #12476424
mysql> INSERT INTO hosts (site_id, hostname, created_at, updated_at) VALUES (NULL, 'test.me', '2014-01-01', '2014-01-01');
ERROR 1048 (23000): Column 'site_id' cannot be null
mysql> INSERT INTO hosts (site_id, hostname, created_at, updated_at) VALUES (1, 'test.me', '2014-01-01', '2014-01-01');
Query OK, 1 row affected (0.00 sec)
mysql> UPDATE `hosts` SET `site_id` = NULL WHERE `hosts`.`site_id` = 1 AND `hosts`.`id` IN (1)
-> ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
@rgarner
rgarner / postgres_spell.csv
Created February 6, 2014 09:53
Spelling Postgres the same way twice in a row
first_spelling second_spelling
postgres postgres