Skip to content

Instantly share code, notes, and snippets.

@victorlin
victorlin / github-delete-stale-branches.js
Last active March 20, 2024 02:27
Delete stale branches from the GitHub repo's stale branches page (github.com/user/repo/branches/stale). Originally from https://stackoverflow.com/a/69089905
// Paste in browser console and run
async function deleteStaleBranches(delay=500) {
var stale_branches = document.getElementsByClassName('js-branch-delete-button');
for (var i = 0; i < stale_branches.length; i++)
{
stale_branches.item(i).click();
await new Promise(r => setTimeout(r, delay));
}
}
@vncsna
vncsna / bash_strict_mode.md
Created June 6, 2021 01:59 — forked from mohanpedala/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
-- get list queries and their running time
SELECT pid,query, age(clock_timestamp(), query_start), usename
FROM pg_stat_activity
WHERE datname = 'database_name'
ORDER BY query_start desc;
-- get rough count of records in table without actually running the count(*) query
-- thanks to: https://www.cybertec-postgresql.com/en/postgresql-count-made-fast/
SELECT reltuples::bigint
@Brunya
Brunya / rust.md
Created February 22, 2021 08:27
Rust coding test

Rust coding test

The motivation behind the coding test is the measurement of the qualification and testing the learning attitude of the candidate.

Task

Create a pseudorandom number generator based on Linear Congruential Generator algorithm. Pick one and use any of the following languages, and please do NOT use any library you can find on the internet.

  • C
  • C++
@LukeMathWalker
LukeMathWalker / audit.yml
Last active May 1, 2024 12:27
GitHub Actions - Rust setup
name: Security audit
on:
schedule:
- cron: '0 0 * * *'
push:
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'
jobs:
security_audit:
@LukeMathWalker
LukeMathWalker / config.yml
Last active March 29, 2024 16:13
CircleCI - Rust setup
version: 2
jobs:
build-and-test:
docker:
- image: cimg/rust:1.69
environment:
# Fail the build if there are warnings
RUSTFLAGS: '-D warnings'
steps:
- checkout
@briceburg
briceburg / mk-jwt-token
Last active December 9, 2023 03:47
mk-jwt-token -- bash shell script for generating JWT tokens. requires `openssl` and `base64` which you have.
#!/usr/bin/env bash
#
# usage: JWT_SECRET="silly" mk-jwt-token
# @WARN: modify the payload and header to your needs.
#
main(){
set -eo pipefail
[ -n "$JWT_SECRET" ] || die "JWT_SECRET environment variable is not set."
@benwillkommen
benwillkommen / _readme.md
Last active June 27, 2022 21:27
Unsubscribe from all watched repositories in a particular organization

Remove All Subscriptions from a Specific Github Organization

This script will delete all the subscriptions in your account for the Github Organization passed to it.

This script was created when I took a new job, and my notification settings inadvertantly subscribed me to all 600+ of their repos. I wanted a better signal to noise ratio in my notifications, but I didn't want to click the "Unwatch All" button, which would remove my subscriptions to repos outside my new employer's org.

How To

  1. Create a Personal Access Token with the "repo" scope, and expose it as the GITHUB_PERSONAL_ACCESS_TOKEN environment variable:
$ export GITHUB_PERSONAL_ACCESS_TOKEN=
@cb372
cb372 / riscv.md
Last active April 2, 2024 06:41
Writing an OS in Rust to run on RISC-V

(This is a translation of the original article in Japanese by moratorium08.)

(UPDATE (22/3/2019): Added some corrections provided by the original author.)

Writing your own OS to run on a handmade CPU is a pretty ambitious project, but I've managed to get it working pretty well so I'm going to write some notes about how I did it.

@briangershon
briangershon / gist:fa9feb08e6a65d52bdc35c738d8cf104
Created January 8, 2017 07:57
Log Request Body for Debugging (golang)
buf, bodyErr := ioutil.ReadAll(r.Body)
if bodyErr != nil {
log.Print("bodyErr ", bodyErr.Error())
http.Error(w, bodyErr.Error(), http.StatusInternalServerError)
return
}
rdr1 := ioutil.NopCloser(bytes.NewBuffer(buf))
rdr2 := ioutil.NopCloser(bytes.NewBuffer(buf))
log.Printf("BODY: %q", rdr1)