Skip to content

Instantly share code, notes, and snippets.

@brasic
brasic / main.go
Created February 14, 2024 20:19 — forked from pteich/main.go
Example for using go's sync.errgroup together with signal detection signal.Notify to stop all running goroutines
package main
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"syscall"
"time"
@brasic
brasic / digest_dir.sh
Last active February 6, 2023 15:12
Digest dir
#!/usr/bin/env bash
# Return a recursive digest of all files in the current directory, including modified ones.
set -eo pipefail
# ensure we're in a git repo and running from its root.
cd "$(git rev-parse --show-toplevel)"
# If the repo is completely clean, we can just print the current tree OID.
if [ -z "$(git status --porcelain)" ]; then
@brasic
brasic / script.sh
Created January 18, 2023 23:45
fetching all participants in a discussion
gh api graphql \
--paginate \
--jq 'tostream | select(.[0][-1]=="login" and .[1]!=null) | .[1]' \
-F owner=community \
-F name=community \
-F number=12341 \
-f query='
query($owner: String!, $name: String!, $number: Int!, $endCursor: String) {
repository(name: $name, owner: $owner) {
discussion(number: $number) {
@brasic
brasic / bush.sh
Last active January 13, 2023 12:19
homer bush
#!/bin/sh
set -euxo
cleanup() {
rm -f 1.mp4 2.mp4 3.mp4 4.mp4 palette.png
}
trap cleanup EXIT
# extend the last frame
@brasic
brasic / create-branch-and-commit.sh
Created November 1, 2022 21:27
create-branch-and-commit.sh
#!/usr/bin/env sh
set -euo pipefail
remote=`git remote |head -1`
repoNwo=`git remote get-url $remote | sed 's/.*://;s/\.git//'`
repoNodeId=`gh api repos/$repoNwo --jq '.node_id'`
branch=`git rev-parse --abbrev-ref HEAD`
newBranch="new-branch-$RANDOM"
contents=`echo -e 'Hello, GraphQL!\n' | base64`
expectedHeadOid=`git rev-parse HEAD`
@brasic
brasic / locale-c
Created October 12, 2022 15:52 — forked from kxxoling/locale-c
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.utf8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
@brasic
brasic / pr_branches.sh
Created September 19, 2022 21:20
list_all_pr_branches
gh api graphql --paginate -f query='
query($endCursor: String) {
repository(owner: "OWNER", name:"REPO") {
pullRequests(first: 3, after: $endCursor, states: [OPEN], baseRefName: "master") {
nodes {
headRefName
}
pageInfo { endCursor hasNextPage }
}
}
@brasic
brasic / codesaces.txt
Created August 26, 2022 15:48
codespaces tricks
alias ports="gh codespace ports forward 80:80 2222:2222 3003:3003 3033:3033 3034:3034 3035:3035 3306:3306 8025:8025 9092:9092 9293:9293 15000:15000 15001:15001 15306:15306 18081:18081 8091:8091 9002:9002 28081:28081 9200:9200 40427:40427 45621:45621 35317:35317 45939:45939 43577:43577 33207:33207 38081:38081"
# until https://github.com/cli/cli/issues/6148 is fixed:
# copy from codespace
gh cs ssh --codespace $CODESPACE_NAME 'gzip < /path/to/some_file' | gunzip > some_file
# copy to codespace
gzip < some_file | gh cs ssh --codespace $CODESPACE_NAME 'gunzip > /path/to/some_file'
@brasic
brasic / wrap.rb
Created August 19, 2022 22:06
wrap long text to 72 chars
def wrap(text)
result = []
fenced = false
text.split(/\r?\n/).each do |line|
if line.start_with?("```")
fenced = !fenced
end
if fenced || line.size <= 72
result << line
else
@brasic
brasic / all_repos_graphql.sh
Last active July 14, 2022 01:46
all_repos_graphql.sh
gh api graphql --paginate -f query='
query($endCursor: String) {
organization(login: "rails") {
repositories(first: 10, after: $endCursor,
orderBy: { field: STARGAZERS, direction: DESC }
) {
nodes {
url
stargazers {
totalCount