Skip to content

Instantly share code, notes, and snippets.

View jim80net's full-sized avatar

Jim Park jim80net

  • Scribd
  • San Francisco, CA
  • 13:59 (UTC -07:00)
  • X @jim80net
View GitHub Profile
@jim80net
jim80net / kubectl_export.sh
Last active January 24, 2024 08:35
A BASH script to export a kubernetes namespace.
# Prerequisites:
# [GNU Parallel](https://www.gnu.org/software/parallel/)
# [kubectl-neat](https://github.com/itaysk/kubectl-neat)
# [mikefarah/yq](https://github.com/mikefarah/yq)
#
# Usage:
# - Copy and paste the below into your active shell session. Alternatively, add to your shell initialization scripts.
# - kubectl_export <namespace>
# The folder structure will be created: <namespace>/<kind>/<resource_name>.yaml
#
@jim80net
jim80net / extract.mjs
Last active December 14, 2023 23:38
Extract text from a website - make sure you adjust the filter on line 20
import scrape from 'website-scraper';
import TurndownService from 'turndown';
import { JSDOM } from 'jsdom';
import path from 'path';
import fs from 'fs-extra';
const turndownService = new TurndownService();
class MyPlugin {
@jim80net
jim80net / chatGPT summarizer bookmarklet.js
Last active December 14, 2023 19:37 — forked from rynomad/chatGPT de-spinner
Summarize Long Articles in ChatGPT: highlight and drag this code into your bookmark bar. If that doesn't work, ask chatGPT how to make a bookmarklet
javascript: (function () {
main();
function extractText(element) {
if (element.nodeType === Node.TEXT_NODE) {
return element.textContent.trim() + ' ';
}
if (element.nodeType !== Node.ELEMENT_NODE) {
return '';
}
@jim80net
jim80net / vmigrate.sh
Last active November 20, 2023 14:19
Use this script to migrate a SmartOS guest to a target. ./vmigrate.sh UUID TARGETIP - or - ./vmigrate.sh UUID TARGETIP migration-snapshotdate # specify the initial snapshot timestamp to increment the snapshot on the target
#!/bin/bash
# Use this to send and receive files
# Dependencies:
# SSH-Keys setup for root users. I recommend using agent forwarding for this.
# mbuffer installed in /opt/local/bin/mbuffer. Adjust to reality.
#
# This script presumes:
# zsnapper is installed. Comment out the two lines where it is referenced if you don't use it
DATE=$(date +%Y%m%d%H%M)
@jim80net
jim80net / add_remove_terraform_quotes
Last active October 25, 2023 00:23
Terrible No Good OneLiner to Add / Remove Quotation marks from terraform files
# It should go without saying, but make sure your terraform file is checked into version control before running this.
# If you find a bug, please let me know =)
# Add quotation marks
elixir -e 'Enum.each(Path.wildcard("**/*.tf"), fn filename -> File.read!(filename) |> String.split("\n") |> Enum.map(fn line -> arraylist = line |> String.trim() |> String.split(" ") |> Enum.map(fn s -> to_charlist(s) end); case arraylist do; [a, b, c, [123]] when a in [[114,101,115,111,117,114,99,101], [100,97,116,97], [112,114,111,118,105,100,101,114], [98,97,99,107,101,110,100]] -> [a,32,34,b,34,32,34,c,34,32,123,10]; _ -> line <> "\n"; end; end) |> to_string() |> String.trim() |> (&(File.write!(filename, &1))).() end)'
# Remove quotation marks from "resource", "data", "provider", and "backend" lines
elixir -e 'Enum.each(Path.wildcard("**/*.tf"), fn filename -> File.read!(filename) |> String.split("\n") |> Enum.map(fn line -> arraylist = line |> String.trim() |> String.split(" ") |> Enum.map(fn s -> to_charlist(s) end); cas
@jim80net
jim80net / autoapprove-dependabot.yml
Created May 19, 2023 20:30
Auto approve and merge dependabot pull requests. Credit to Phillip Verheyden.
name: Dependabot auto-approve
on: pull_request_target
permissions:
pull-requests: write
# From the docs at https://github.com/dependabot/fetch-metadata#enabling-auto-merge
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
@jim80net
jim80net / multiplex.sh
Created June 27, 2023 23:54
This is why I still use vim, so that I can multiplex similar repositories.
#!/usr/bin/env bash
tmux new-session -d -s multiplex
tmux select-window -t multiplex:0
INDEX=0
for i in alice bob charles denice ephrahim fantasea greg
do
tmux split-window -h
tmux select-pane -t $INDEX
@jim80net
jim80net / add-terraform-plan-to-prs.yml
Last active January 31, 2023 08:16
Github Action to add a terraform plan to pull requests.
name: Add Terraform Plan to Pull Requests
on:
pull_request:
env:
# See page below about disabling Hashicorp Upgrade and Security Checks
# https://www.terraform.io/docs/commands/index.html#upgrade-and-security-bulletin-checks
CHECKPOINT_DISABLE: true
@jim80net
jim80net / onelinehc.sh
Last active November 1, 2022 17:15
quick and dirty ruby onliner to health check a site
ruby -rcolorize -rnet/http -e '
def check()
s_time = Time.now()
res = Net::HTTP.get_response(URI( "https://example.com/"))
ensure
e_time = Time.now()
code = defined?(res.code) ? res.code : "5xx"
return [e_time - s_time, code]
end
while true do
@jim80net
jim80net / etc_cron.hourly_10shutdown_idle
Created October 15, 2022 17:54
Shutdown idle EC2 jumpbox
#!/bin/bash
set -eu -o pipefail
[[ $(w | wc -l) -lt 3 ]] && {
echo "Nobody logged in"
sudo shutdown -hP +60 "Shutting down due to no active sessions"
} || {
echo "Users logged in" >/dev/null
}