Skip to content

Instantly share code, notes, and snippets.

@yob
yob / athena.sql
Created April 20, 2023 00:04
Hourly compute costs from CUR
SELECT DISTINCT
"year"
, "month"
, "bill_payer_account_id" "payer_account_id"
, "line_item_usage_account_id" "linked_account_id"
, "bill_billing_period_start_date" "billing_period"
, "date_trunc"('hour', "line_item_usage_start_date") "usage_date"
, "sum"(CASE
WHEN (((("line_item_line_item_type" = 'Usage') AND (NOT ("line_item_usage_type" LIKE '%Spot%'))) AND ("product_servicecode" <> 'AWSDataTransfer')) AND ("line_item_usage_type" NOT LIKE '%DataXfer%')) THEN
CASE
@yob
yob / ip-ranges-to-sql.rb
Last active April 2, 2023 14:06
Convert AWS ip-ranges.json into a SQL view for querying
require 'net/http'
require 'json'
require 'pp'
def die(msg)
$stderr.puts msg
exit 1
end
uri = URI('https://ip-ranges.amazonaws.com/ip-ranges.json')
response = Net::HTTP.get_response(uri)
@yob
yob / libyear-per-month.rb
Last active July 31, 2022 11:08
Calculate libyear for a ruby project over time, for charting progress
# To generate the input file, I ran this:
#
# git log --merges --date-order --pretty="format:%h%d %aI" > first-commit-per-month.txt
#
# ... and then manually edited the file to have only the first commit per month. it'd
# be neat to geneate the list of target commits automatically.
#
# Note: this doesn't work with upstreamn libyears-bundler, because https://github.com/jaredbeck/libyear-bundler/issues/4
# However, my very hacky fork can do it: https://github.com/yob/libyear-bundler
@yob
yob / README.md
Last active December 24, 2024 05:55
Installing ruby 3.0 with rbenv/ruby-build with openssl 3

Bllergh. This is a real pain.

The openssl extension that ships with ruby 3.0 only compiles against openssl <= 1.1, but now openssl 3.0 is shipped in debian testing/unstable.

Ruby bug here: https://bugs.ruby-lang.org/issues/18658

Version >= 3.0 of the openssl rubygem does compile against openssl 3.0 though.

I use rbenv to manage ruby versions on my system, which uses ruby-build to manage installs.

#!/usr/bin/env ruby
# Small script that converts an IP address into its AS number. Also provides a
# helpful link to Geoff Huston's handy AS summary page
require 'ipaddr'
require 'resolv'
USAGE = "ip-to-as <ipv4/ipv6>"
@yob
yob / characters.rb
Created September 26, 2021 12:34
pdf-reader extract characters
#!/usr/bin/env ruby
require 'pdf/reader'
PDF::Reader.open("foo.pdf") do |pdf|
pdf.pages.each do |page|
receiver = PDF::Reader::PageTextReceiver.new
page.walk(receiver)
characters = receiver.instance_variable_get("@characters")
puts characters.inspect
@yob
yob / archiving.diff
Created April 8, 2021 00:57
totally untested hack at adding archiving to thebuildkite TF provider
diff --git a/buildkite/resource_pipeline.go b/buildkite/resource_pipeline.go
index 5bc6208..aeb63b5 100644
--- a/buildkite/resource_pipeline.go
+++ b/buildkite/resource_pipeline.go
@@ -62,6 +62,11 @@ func resourcePipeline() *schema.Resource {
},
Schema: map[string]*schema.Schema{
+ "archived": {
+ Computed: true,
@yob
yob / graphql.txt
Created January 28, 2021 12:01
buildkite graphql query to filter org pipelines by repo URL
query PipelinesByRepoQuery {
organization(slug: "yob-opensource") {
pipelines(first:1, repository:{url:"https://github.com/yob/pdf-reader.git"}) {
edges {
node {
name
repository {
url
}
}
@yob
yob / download.sh
Last active December 4, 2020 03:05
#!/bin/bash
set -ux
mkdir -p logs
buildkite-agent artifact search "*" -format "%j %p %c %s %S\\n"
buildkite-agent artifact download --step ":rspec: 0" logs/the-time.txt logs
shasum -a 1 logs/the-time.txt
steps:
- label: tests
command: test.sh