Skip to content

Instantly share code, notes, and snippets.

View wu0407's full-sized avatar

wowqing wu0407

View GitHub Profile
@zjeaton
zjeaton / _Google Analytics 4 with Hugo.md
Last active May 23, 2024 01:13
Google Analytics 4 (with Measurement ID) in Hugo

Google Analytics 4 in Hugo

Blog post with slightly more detail can be found here. If you want to just get to it, read on.

I (very) recently decided to reimplement GA in my site, and found that existing implementation in Hugo was not compatible with GA4's new Measurement ID. This is an easy way to drop your Measurement ID into your site. I'm not going to go into how to sign up for GA.

This implementation requires that you create a site parameter for analytics, create a partial, and call the partial. I tweaked the names of the parameters and files so they didn't collide with the built-in hugo code.

Place the GoogleAnalyicsID (Measurement ID) in config.toml within [params].

#!/bin/bash
# If only one argument is given when calling this script, we do a namespace switch.
# If a second argument exists when calling this script, we do a cluster switch.
# When switching clusters, alert the user if that cluster is not found.
# The trap provides the current context on exit. The context names are sorted to provide consistency.
LRED=$(echo -en '\033[01;31m')
RESTORE=$(echo -en '\033[0m')
trap 'CURRENT_CONTEXT=$(kubectl config current-context) && echo && kubectl config get-contexts | head -n1 && kubectl config get-contexts | sed 1d | sort --key=1 -b | sed "s|\*\(.*\)${CURRENT_CONTEXT}\(.*\)$|${LRED}\*\1${CURRENT_CONTEXT}\2${RESTORE}|g"' 0 1 3 15
package main
import (
goflag "flag"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"k8s.io/klog"
)
@ykfq
ykfq / Kubernetes 调度优化--重平衡策略方案整理.md
Created January 29, 2019 06:50
Kubernetes 调度优化--重平衡策略方案整理
<title>Kubernetes 调度优化--重平衡策略方案整理</title>
@Integralist
Integralist / Long and Short Flag.go
Last active January 3, 2024 19:35
[Golang Long and Short Flags] #go #golang #flags
var myFlagType string
func init() {
const (
flagValue = "default value is foo"
flagUsage = "this is my flag explanation"
)
flag.StringVar(&myFlagType, "foo", flagValue, flagUsage)
flag.StringVar(&myFlagType, "f", flagValue, flagUsage+" (shorthand)")
flag.Parse()
@miguelmota
miguelmota / userhomedir.go
Last active April 11, 2022 00:33
Golang get user home directory path
package main
import (
"fmt"
"os"
"runtime"
)
func userHomeDir() string {
if runtime.GOOS == "windows" {
@yonglai
yonglai / playbook_centos_install_docker.yaml
Created November 15, 2017 18:04
An Ansible playbook to install docker-ce on Centos
---
- name: Install docker
gather_facts: No
hosts: default
tasks:
- name: Install yum utils
yum:
name: yum-utils
state: latest
@baymaxium
baymaxium / content.md
Created October 18, 2017 09:17
孙宇聪:来自Google的DevOps理念及实践

原文:中生代技术

经过数年蛰伏,DevOps成为了业界焦点,不过如何实现DevOps,依然路漫漫,本期文章转载自数人云组织的DevOps系列分享实录,了解并学习Google的DevOps实践

SRE(Site Reliability Engineering)是最早由Google提出,又经由Google发展完善的一个崭新运维理念。如今SRE已成为一个涵盖运维理念、思路、组织架构和具体实践的完整体系。数人云推出SRE系列教程,由SRE经验丰富的技术大牛们为大家分享运维一线的独家干货,揭示SRE背后的秘密。

数人云邀请了前Google SRE、《SRE:Google运维解密》的译者孙宇聪与大家进行了线上分享。本文讲述了SRE的基本概念和核心原理。与孙老师本人一样风趣幽默的文章,小数希望大家阅读愉快:)

PS:文末线下活动有孙老师翻译著作书籍赠送

@navicore
navicore / jsonpath.md
Last active January 24, 2024 17:25
for getting multiple kubernetes yaml fields from kubectl via jsonpath

get name and image and startTime

kubectl get pods -Ao jsonpath='{range .items[*]}{@.metadata.name}{" "}{@..spec..containers[*].image}{" "}{@.status.phase}{" "}{@.status.startTime}{"\n"}{end}'

edited 10/2022 with .. and A suggestions

@Vince-Cercury
Vince-Cercury / gist:43c7afc1a6b0f580b0cb6fb27e650042
Created September 1, 2017 00:12
How to monitor an external secure etcd cluster with Prometheus Operator
# How to monitor a secure external etcd service with Prometheus Operator
This guide will help you monitor an external etcd cluster. When the etcd is not hosted inside Kubernetes.
This is often the case with the Kubernetes setup. This has been tested with kube-aws but same principals will apply to other tools.
# Step 1 - Make the etcd certificates available to Prometheus pod
Prometheus Operator (and Prometheus) allow us to specify a tlsConfig. This is required as most likely your etcd metrics end points is secure.
## a - Create the secrets in the namespace
Prometheus Operator allows us to mount secrets in the pod. By loading the secrets as files, they can be made available inside the Prometheus pod.