Skip to content

Instantly share code, notes, and snippets.

View jim80net's full-sized avatar

Jim Park jim80net

  • Scribd
  • San Francisco, CA
  • 09:40 (UTC -07:00)
  • X @jim80net
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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
}
@jim80net
jim80net / tf_move_state.sh
Last active February 25, 2022 10:21
Move terraform state between projects.
#!/usr/bin/env bash
##
# Usage: tf_move_state.sh source_directory target_directory source_resource_name <target_resource_name (uses source_resource_name if not provided)>
# Provide source and target directories using relative paths.
# WARNING: TEST ON AN INCONSPICUOUS AREA AS STAINING MAY OCCUR
# Credit to https://github.com/mcalhoun
set -e
@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 / empty.sh
Created November 4, 2021 21:48
Empty a AWS Cloud Map Namespace
for i in $(aws servicediscovery list-services --filter Name=NAMESPACE_ID,Values=[ns-MYNAMESPACEIDHERE],Condition=EQ --query "Services[].Id" --output text) ; do aws servicediscovery delete-service --id $i; done