Skip to content

Instantly share code, notes, and snippets.

View raykao's full-sized avatar
🇨🇦
¯\_(ツ)_/¯

Raymond Kao raykao

🇨🇦
¯\_(ツ)_/¯
View GitHub Profile
@raykao
raykao / mongoid.rb
Last active October 11, 2023 13:03
Rails + Mongoid _id attribute to id and string
# config/initializers/mongoid.rb
# convert object key "_id" to "id" and remove "_id" from displayed attributes on mongoid documents when represented as JSON
module Mongoid
module Document
def as_json(options={})
attrs = super(options)
id = {id: attrs["_id"].to_s}
attrs.delete("_id")
id.merge(attrs)
resource "azurerm_user_assigned_identity" "cluster" {
location = azurerm_resource_group.example.location
name = "aks-cluster-identity-${var.cluster_uid}"
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_user_assigned_identity" "kubelet" {
location = azurerm_resource_group.example.location
name = "aks-kubelet-identity-${var.cluster_uid}"
resource_group_name = azurerm_resource_group.example.name
@raykao
raykao / run_consul.sh
Created April 5, 2019 05:44
Work around for using Azure Managed Service Identities to discover Consul Server IP addresses. Waiting for [this](https://github.com/hashicorp/go-discover/pull/102) PR on go-discover to be approved
## The Env Vars
# AZURE_SUBSCRIPTION_ID
# CONSUL_VMSS_RG
# CONSUL_VMSS_NAME
## were prepended to this script at provisioning time with Terraform via custom_data/cloud-init
AZURE_MSI_ENDPOINT="http://169.254.169.254/metadata/identity"
AZURE_MSI_OAUTH=$(curl -H "Metadata:true" $AZURE_MSI_ENDPOINT"/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fmanagement.azure.com%2F")
AZURE_MSI_JWT=$(echo $AZURE_MSI_OAUTH | jq -r '.access_token')
@raykao
raykao / get-kube-config.sh
Created September 16, 2021 01:34
used for demo environment
#!/bin/bash
# Wait for cloud-init to finish
while [ ! -f /tmp/cloud-init-done ]; do echo 'Waiting for cloud-init to complete.';sleep 5; done
ssh -o "StrictHostKeyChecking no" $USER@$CONTROL_HOST 'sudo cp /etc/rancher/k3s/k3s.yaml ~/;sudo chown $USER:$USER k3s.yaml'
mkdir .kube
scp -o "StrictHostKeyChecking no" $USER@$CONTROL_HOST:~/k3s.yaml ./.kube/config
chmod 640 ~/.kube/config
sed -i 's/127.0.0.1/'$CONTROL_HOST'/g' ./.kube/config
@raykao
raykao / Ubuntu-Creating-Swap-File
Last active March 17, 2021 14:35
How to create a swap file on ubuntu 12.04. Summary from: [Digital Ocean](https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04)
# Summary from: https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04
# 1. Check if swap exists returns single line output if swap doesn't exist
$ sudo swapon -s
Filename Type Size Used Priority
# 2. Check disk space on root (/) with DF command:
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
@raykao
raykao / Dockerfile
Created January 21, 2021 18:35
Azure Function Custom Runtime Container for Ruby app
# To enable ssh & remote debugging on app service change the base image to the one below
FROM mcr.microsoft.com/azure-functions/dotnet:3.0-appservice
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
# skip installing gem documentation
RUN set -eux; \
mkdir -p /usr/local/etc; \
{ \
# Lookup TZ
timedatectl list-timezones
# Set TZ
sudo timedatectl set-timezone America/Toronto
@raykao
raykao / fw-whitelist-fqdns.txt
Created May 10, 2020 02:46
Azure Ubuntu Update FQDNs - Required FQDNs for Ubuntu Linux Updates. These FQDNs are necessary for the operation of a given Ubuntu VM.
target_fqdns = [
"azure.archive.ubuntu.com",
"security.ubuntu.com",
]
@raykao
raykao / powerline-fonts.ps1
Created December 7, 2019 05:04
Powerline fonts
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
.\install.ps1
cd ..
rd /S /Q fonts