Skip to content

Instantly share code, notes, and snippets.

View C-Saunders's full-sized avatar

Charlie Saunders C-Saunders

View GitHub Profile
@C-Saunders
C-Saunders / split_file.py
Created November 2, 2023 18:49
Split a file into chunks with a specified number of lines
import argparse
from io import TextIOWrapper
from pathlib import Path
from typing import Optional, Tuple
def split_file(*, input_path: Path, output_file_prefix: str, output_file_suffix: Optional[str], lines_per_chunk: int, has_header: bool = True) -> list[Path]:
def build_filename() -> Path:
if output_file_suffix is None:
return input_path.parent.joinpath(f'{output_file_prefix}_{chunk_number}{input_path.suffix}')
@C-Saunders
C-Saunders / extractor.rb
Last active August 15, 2023 14:20
GitHub Action Job Runtime Data Extractor
require 'date'
require 'json'
def get_seconds_difference(start, finish)
((finish - start) * 24 * 60 * 60).to_i
end
# from gh run list --branch main --event push --status completed --json displayTitle,headSha,name,databaseId,startedAt,updatedAt,workflowName --limit 1000 > run_list.json
data = JSON.parse(File.read('./run_list.json'))
@C-Saunders
C-Saunders / query.sql
Created August 1, 2023 14:28
Postgres type cast map
select s.typname as source, t.typname as target, castcontext, castmethod
from pg_cast
left join pg_type as s on castsource = s.oid
left join pg_type as t on casttarget = t.oid;
#! /bin/bash
set -eu
# Expects two Heroku app names as arguments
# Displays the diff of the environment variable *names* (ignoring their values)
args=("$@")
first_app_var_names=$(heroku config -s --app ${args[0]} | sed -E 's/=.*$//')
second_app_var_names=$(heroku config -s --app ${args[1]} | sed -E 's/=.*$//')
@C-Saunders
C-Saunders / list-heroku-buildpacks.sh
Created January 23, 2020 18:23
List Heroku buildpacks for each app using the Heroku CLI.
#! /bin/bash
app_list=$(heroku apps -A -t=${@} | grep -v '^===')
for app in $app_list; do
buildpacks=$(heroku buildpacks -a $app | grep -v '^===' | sed -E 's/[0-9]+\. //')
if [[ $buildpacks =~ "has no Buildpack URL set" ]]; then
echo $app "has no buildpacks"
else
for buildpack in $buildpacks; do
@C-Saunders
C-Saunders / addContactToTests.ts
Last active August 15, 2018 14:20
StatusCake - add contact group to multiple tests
const { StatusCake, getTests, getContactGroups, updateTest } = require('statuscakejs')
const uniq = require('lodash.uniq')
// get these from Account > User Details
const statusCake = new StatusCake('username', 'apiKey')
let allTests
getTests(statusCake).then(data => allTests = data)
let allContacts