This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feedjira.parse(URI.open("https://blog.booko.com.au/feed/").read).entries.max_by {|e| e.categories.max_by {|c| c.length }.then {|c| c.length } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://isni.org/page/linked-data/ | |
# https://isni.oclc.org:2443/isni/public_export/ISNI_persons.jsonld.gz | |
wget https://isni.oclc.org:2443/isni/public_export/ISNI_persons.jsonld.gz | |
# The file I downloaded was full of the 0x1E character, or ^^ in ASCII. This will strip that | |
sed 's/\x1E//g' ISNI_persons.jsonld > cleaned_ISNI_persons.jsonld | |
# Then use JQ to convert the file into the way more sane JSONL format. By default, it tries to read it all into |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_isbn13 | |
isbn12 = rand(978_000_000_000..979_999_999_999).to_s | |
chksum = (10 - isbn12.each_char.with_index.sum { |digit, i| digit.to_i * (i.even? ? 1 : 3) } % 10 ) % 10 | |
"#{isbn12}#{chksum}" | |
end | |
def risbn13 = rand(978_000_000_000..979_999_999_999).then {|isbn12| "#{isbn12}#{(10 - isbn12.to_s.each_char.with_index.sum { |digit, i| digit.to_i * (i.even? ? 1 : 3) } % 10 ) % 10}" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Favicon | |
def initialize(doc, url: nil) | |
@doc = doc | |
@url = if url | |
@url = URI(url.to_s) | |
elsif canonical | |
URI(canonical) | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This ( https://gist.github.com/hatarist/675dc3debf6cf5f825b5c15aed4cbac0 ) with TOAST size formatting | |
SELECT | |
table_name, | |
pg_size_pretty(table_bytes) AS table, | |
pg_size_pretty(index_bytes) AS index, | |
pg_size_pretty(toast_bytes) AS toast, | |
pg_size_pretty(total_bytes) AS total | |
FROM ( | |
SELECT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'cgi' | |
require 'net/http' | |
require 'json' | |
abort("songlink <url>") if ARGV[0].nil? | |
def copy_to_clipboard(text) = IO.popen('pbcopy', 'w') { |clipboard| clipboard.puts text } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URI(url).tap {|u| u.query = URI.encode_www_form(CGI.parse(u.query || "").merge({ref: 123})) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make add tags to the normal rails logger, accessed like `hc_logger.info("my log message")` | |
def hc_logger = @hc_logger ||= logger.tagged("HttpClients").tagged(self.class.name) | |
# Create a new logger as an instance variable for a class: | |
class MyServiceClass | |
# .... | |
def my_logger = @my_logger ||= create_logger.tagged(self.class.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bot_shedding(wait: 600, threshold: 1) | |
require "sys/cpu" | |
require "etc" | |
# normalize the 1-minute load average based on processor count | |
return unless Sys::CPU.load_avg[0] / Etc.nprocessors > threshold | |
return unless DeviceDetector.new(request.user_agent).bot? | |
logger.info("Shedding bots: Returning 503 / Retry-After: #{wait} for #{request.remote_ip} / #{request.user_agent}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/\b(?:97[89]-?)?(?:\d{1,5}-?)?(?:\d{1,7}-?)?(?:\d{1,6}-?)?\d{1,3}\b/ |