Skip to content

Instantly share code, notes, and snippets.

Avatar

Mislav Marohnić mislav

View GitHub Profile
@mislav
mislav / unifi-controller-cert.sh
Last active May 20, 2022
Figuring how to assign your own SSL certificate to be used by the Unifi Controller web interface
View unifi-controller-cert.sh
hostname="MYHOST" # set this to where the Unifi Controller is served from
root_ca="rootCA.pem"
root_ca_key="rootCA.key"
cert="unifi.pem"
cert_key="unifi.key"
# these don't really matter
csr="unifi.csr"
pfx_password="whatever"
@mislav
mislav / config.json
Last active Jun 22, 2022
Experiment in using GitHub CLI to authenticate fetching docker images from GitHub Package Registry
View config.json
// ~/docker/config.json
{
"credsStore": "desktop",
"credHelpers": {
"docker.pkg.github.com": "gh",
"ghcr.io": "gh"
}
}
@mislav
mislav / keybindings.json
Last active Jun 18, 2021
VS Code keyboard shortcut for quickly re-running the Go test under development. Requires VS Code Go 0.26+
View keybindings.json
// > Preferences: Open Keyboard Shortuts (JSON)
[
{
"key": "shift+enter",
"command": "go.test.cursorOrPrevious",
"when": "editorTextFocus && editorLangId == 'go' && !findInputFocused && !replaceActive"
},
{
"key": "ctrl+shift+enter",
"command": "go.test.package"
@mislav
mislav / workflows-automerge.yml
Last active Apr 25, 2022
Using GitHub CLI from GitHub Actions
View workflows-automerge.yml
name: Auto-merge
on:
pull_request:
types: [opened]
jobs:
automerge:
runs-on: ubuntu-latest
View label-copy.sh
# Usage: bash label-copy.sh <source-repo> <destination-repo> <label-names>...
#
# Requirements: GitHub CLI, jq
#
# Example:
# brew install gh jq
# bash label-copy.sh owner/repo1 owner/repo2 "bug" "help wanted" "feature"
#
set -e
View die-keystone.sh
# First, close Google Chrome.
# unload the Keystone agent
find /Library/Launch* ~/Library/LaunchAgents -maxdepth 1 -iname 'com.google.*' | xargs -L1 launchctl unload
# prevent it from starting again (note: you could also back up the files by moving them elsewhere)
find /Library/Launch* ~/Library/LaunchAgents -maxdepth 1 -iname 'com.google.*' | xargs rm -v
# Warning: it's likely that running Google Chrome after this will restore these files.
# If it doesn't, consider that automatic Chrome updates will be DISABLED. Use at own risk.
@mislav
mislav / gh-rename-master
Last active Apr 24, 2022
Rename the default branch of a repository using GitHub CLI https://github.com/cli/cli/releases/tag/v0.10.0
View gh-rename-master
#!/bin/bash
# Usage: gh-rename-master <newbranch> [<remote>]
#
# Renames the "master" branch of the current repository both locally and on GitHub.
#
# dependencies: GitHub CLI v0.10
set -e
newbranch="${1?}"
remote="${2:-origin}"
@mislav
mislav / hub-graphql-mutation.sh
Created Apr 15, 2020
GraphQL mutation example with hub & jq
View hub-graphql-mutation.sh
jq -R --slurp '{query: ., variables: {input: $ARGS.named}}' \
--arg name "hello-world" \
--arg visibility "PRIVATE" \
--arg ownerId "<ORG-NODEID>" \
--arg teamId "<TEAM-NODEID>" \
<<<'
mutation ($input: CreateRepositoryInput!) {
createRepository(input: $input) {
repository {
nameWithOwner
@mislav
mislav / hub-get.sh
Created Oct 30, 2019
Download `bin/hub` for the current environment
View hub-get.sh
#!/bin/bash
set -e
latest-version() {
curl -fsi https://github.com/github/hub/releases/latest | awk -F/ '/^Location:/ {print $(NF)}'
}
HUB_VERSION="${1#v}"
if [ -z "$HUB_VERSION" ]; then
latest=$(latest-version) || true
@mislav
mislav / hub-api-comments.sh
Last active Dec 21, 2021
hub api example of how to fetch all comments over GraphQL
View hub-api-comments.sh
comments() {
local issue="${1?}"
shift 1
paginate hub api --cache 3600 graphql -F issue="$issue" "$@" -f query='
query ($owner: String = "{owner}", $repo: String = "{repo}", $issue: Int!, $per_page: Int = 30, $after: String) {
repository(owner: $owner, name: $repo) {
issueOrPullRequest(number: $issue) {
... on Issue {
comments(first: $per_page, after: $after) {
...Comments