Skip to content

Instantly share code, notes, and snippets.

View toreriklinnerud's full-sized avatar

Tor Erik Linnerud toreriklinnerud

  • Decibel
  • New York
View GitHub Profile
1. Grab the DB dump
curl -L "https://www.dropbox.com/s/k1ai0765gc2k98f/bug5.sql?dl=1" -o bug5.sql
2. Create an empty database and restore the dump and wait a bit:
createdb bug5 && psql -d bug5 -f bug5.sql && psql -d bug5 -c "ANALYZE"
3. Run queries:
@toreriklinnerud
toreriklinnerud / relation_difference.sql
Created April 14, 2021 14:03
Postgres: list columns in relation A that are not in relation B (works for tables, views, materialized views)
WITH relations AS (SELECT
a.attname,
pg_catalog.format_type(a.atttypid, a.atttypmod) AS type,
t.relname
FROM
pg_attribute a
JOIN pg_class t ON a.attrelid = t.oid
JOIN pg_namespace s ON t.relnamespace = s.oid
WHERE
a.attnum > 0
@toreriklinnerud
toreriklinnerud / gist:5b1849c096808e94c472d2b17a1e56b2
Last active September 3, 2019 17:23
On linux, for all connected drives under /dev/sd: unmount, wipe, format with exfat, mount
#!/bin/bash
set -e
set -o pipefail
for dev in /dev/sd?
do
if findmnt "${dev}1"
then
umount "${dev}1"
class Auth0Token
def request_token
connection = Faraday.new(url: "https://rubyfriend.auth0.com/oauth/token")
response = connection.post do |request|
request.headers['Content-Type'] = 'application/json'
request.body = payload.to_json
end
JSON.parse(response.body)
end
[
{time: 201201, x: 2, y: 7, z: 2},
{time: 201202, a: 3, b: 4, c: 0},
]
log = [
{time: 201201, x: 2},
{time: 201201, y: 7},
{time: 201201, z: 2},
{time: 201202, a: 3},
{time: 201202, b: 4},
{time: 201202, c: 0}
]
@toreriklinnerud
toreriklinnerud / gist:2400336
Created April 16, 2012 17:54
git log with nice human readable columns
git log --pretty="%ad|%an|%s" --date=short |
while IFS='|' read date author message
do
printf '%s %-20s %s\n' "$date" "$author" "$message"
done
christmas_present.price #=> "123.0"
christmas_present.price #=> #<BigDecimal:7ff71b93df40,'0.123E3',9(18)>
class BigDecimal
def inspect
to_s
end
end