Skip to content

Instantly share code, notes, and snippets.

@NimJay
NimJay / translate-list-of-strings.go
Last active July 6, 2023 00:56
This Golang script translates a list of strings/phrases from one languages to another — using Google's translation API.
package main
import (
"context"
"fmt"
"os"
"cloud.google.com/go/translate"
"golang.org/x/text/language"
)
@NimJay
NimJay / Dockerfile
Last active December 30, 2022 03:24
Dockerfile that hosts a Preact app, using NGINX.
# Install Node dependencies.
FROM node:16-slim AS builder-stage
WORKDIR /app
COPY package.json package.json
COPY package-lock.json package-lock.json
RUN npm install
# Compile our TypeScript code.
COPY src/ src/
COPY tsconfig.json tsconfig.json
@NimJay
NimJay / check-in-cluster-anthos-service-mesh-version.sh
Created December 20, 2022 18:49
Use these commands to check the version of in-cluster Anthos Service Mesh you're running on your Kubernetes cluster.
# Check the suffix of the istiod-asm-* Service.
kubectl get service --namespace=istio-system
@NimJay
NimJay / Dockerfile
Last active March 22, 2024 13:05
Generate requirements.txt for a given requirements.in file using a Docker container.
# Set the version of Python you want to use here.
FROM python:3.12.2-slim@sha256:36d57d7f9948fefe7b6092cfe8567da368033e71ba281b11bb9eeffce3d45bc6 as base
# Ignore this. This is needed to build Online Boutique's recommendationservice.
# RUN apt-get -qq update \
# && apt-get install -y --no-install-recommends \
# wget g++ \
# && rm -rf /var/lib/apt/lists/*
# This Dockerfile assumes that the requirements.in file is in the same folder as this Dockerfile.
@NimJay
NimJay / create-gke-cluster-with-in-cluster-asm.sh
Created October 17, 2022 17:02
This is the most convenient, non-Terraform way I know to create a new Google Kubernetes Engine (GKE) cluster with in-cluster Anthos Service Mesh (ASM) installed.
# If you're not using Cloud Shell, make sure to replace $GOOGLE_CLOUD_PROJECT with your Project ID.
# Cloud Shell is a small virtual machine (in Google Cloud) that's tied to your Google Cloud account.
export PROJECT_ID=$GOOGLE_CLOUD_PROJECT
export CLUSTER_NAME=my-cluster-with-in-cluster-asm-1
export KUBECONTEXT_NAME=${CLUSTER_NAME}
export ZONE=us-central1-b
export PROJECT_NUMBER=$(gcloud projects describe ${PROJECT_ID} --format='get(projectNumber)')
export ASM_VERSION=1.14
@NimJay
NimJay / create-gke-cluster.md
Last active March 16, 2023 16:59
Create a GKE Cluster

Create Google Kubernetes Engine (GKE) Cluster

I regularly have to create new Google Kubernetes Engine (GKE) clusters (via Google Cloud Shell). I use the bash snippets below to do so.

Create cluster.

1. Set environment variables.

@NimJay
NimJay / create-gke-cluster-with-asm.sh
Last active March 22, 2023 13:37
This is the most convenient, non-Terraform way I know to create a new Google Kubernetes Engine (GKE) cluster with managed Anthos Service Mesh (ASM) installed.
# If you're not using Cloud Shell, make sure to replace $GOOGLE_CLOUD_PROJECT with your Project ID.
# Cloud Shell is a small virtual machine (in Google Cloud) that's tied to your Google Cloud account.
export PROJECT_ID=$GOOGLE_CLOUD_PROJECT
export CLUSTER_NAME=my-cluster-3
export KUBECONTEXT_NAME=my-cluster-3
export ZONE=us-central1-b
export PROJECT_NUMBER=$(gcloud projects describe ${PROJECT_ID} --format='get(projectNumber)')
echo "🏗️ Enabling necessary Google Cloud APIs..."
@NimJay
NimJay / update-address-charles-schwab.md
Last active May 16, 2023 13:44
Instructions for updating your address on the Charles Schwab online web app/portal.

The information below in now out-dated. If your address change is within the same country, you can use the "Contact Information" page to update your address.


Updating Address on Charles Schwab Web App

I wanted to update my address on the schwab.com web app, but I couldn't find proper instructions anywhere. So I called them, and here's what they said (I had to do):

Instructions

@NimJay
NimJay / bombard-with-http-request.js
Created June 12, 2020 03:30
This bit of JavaScript can be used to repeatedly make an HTTP request to an endpoint.
/**
* This script could be used to test whether an endpoint could handle an overload
* of HTTP requests.
*/
{
const URL = "https://example.com";
const MILLISEC_WAIT_PER_REQUEST = 100;
function bombardWithHttpRequest() {
fetch(URL)
{
let things = [];
let thingsElement = $0.children; // Select the DOM element that contains the list.
for (let i = 0; i < thingsElement.length; i++) {
const thing = thingsElement[i].children[1].innerHTML; // Change this. Extract the item from its HTML element.
things.push(thing);
}
let glue = "\",\n \""; // Change this.
console.log(things.join(glue));
}