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
begin
loop do
puts "in loop"
if o = IO.select([input, ssl_socket].compact, nil, nil, activity_timeout)
puts "in select if"
if (input && (o.first.first == input))
puts "in if"
data = input.readpartial(10000)
puts "read partial"
ssl_socket.write(data)
class BigDecimal
def inspect
to_s
end
end
christmas_present.price #=> #<BigDecimal:7ff71b93df40,'0.123E3',9(18)>
christmas_present.price #=> "123.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
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}
]
[
{time: 201201, x: 2, y: 7, z: 2},
{time: 201202, a: 3, b: 4, c: 0},
]
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
@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"
@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