Skip to content

Instantly share code, notes, and snippets.

Avatar
🦉
Server Reboot Engineer

Kai Xia(夏恺) xiaket

🦉
Server Reboot Engineer
View GitHub Profile
@xiaket
xiaket / method_as_decorator.py
Last active Apr 1, 2019
Define a class method in Python that can work as a decorator for other methods.
View method_as_decorator.py
#!/usr/bin/env python3
class A:
def dec(func):
def wrapper(self, *args, **kwargs):
print("Pre")
func(self, *args, **kwargs)
print("Post")
return wrapper
@xiaket
xiaket / lifecycle_policy.json
Last active Aug 27, 2020
ECR Lifecycle Policy example with explanations
View lifecycle_policy.json
{
"rules": [
{
"rulePriority": 10,
"description": "For `latest` tag, keep last 5 images",
"selection": {
"tagStatus": "tagged",
"tagPrefixList": ["latest"],
"countType": "imageCountMoreThan",
"countNumber": 5
@xiaket
xiaket / retag.sh
Created Aug 10, 2018
Bash script to add tag to docker images in ECR
View retag.sh
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
REPO_NAME="jenkins-master"
function manifest() {
@xiaket
xiaket / init_django.py
Last active May 21, 2020
Setup Django environment in Pythonista 3 on iOS. Works with Django 2.0+, must have stash installed.
View init_django.py
#!/usr/bin/env python
import io
import os
import tarfile
import requests
import stash
SITE_PACKAGES = os.path.expanduser("~/Documents/site-packages-3")
@xiaket
xiaket / packer_cleanup.py
Created Oct 31, 2017
I frequently ran out of time when I have a packer debug session open and the saml role only grant me one hour of access. So instead of manually removing the keypair and the security group, I come up with this script.
View packer_cleanup.py
#!/usr/bin/env python
# encoding=utf8
"""
This script will cleanup leftover resources(instance, key-pair and security group)
related to an instance specified by its ipaddr or instance-id.
I frequently ran out of time when I have a packer debug session open and
the saml role only grant me one hour of access. So instead of manually
removing the keypair and the security group, I come up with this script.
"""
@xiaket
xiaket / generic_number.py
Created May 29, 2017
generic number class builder
View generic_number.py
# For this codewar question: https://www.codewars.com/kata/54baad292c471514820000a3
import math
def create_number_class(bases):
base = len(bases)
def __init__(self, value):
self.value = value
@xiaket
xiaket / dockerhub-get-image-info.py
Created Mar 20, 2017
Get the list of images and tags for a Docker Hub repo
View dockerhub-get-image-info.py
import json
import sys
import requests
AUTH ={
'username': "xiaket",
'password': "YourPasswordHere",
}
@xiaket
xiaket / postmortem.md
Created Nov 4, 2016 — forked from mlafeldt/postmortem.md
Example Postmortem from SRE book, pp. 487-491
View postmortem.md

Shakespeare Sonnet++ Postmortem (incident #465)

Date

2015-10-21

Authors

  • jennifer
  • martym
@xiaket
xiaket / 2m4b
Last active Mar 20, 2017
create an m4b audiobook file from a movie or an mp3 file.
View 2m4b
#!/usr/bin/env bash
#
# Author: Kai Xia <xiaket@corp.netease.com/xiaket@gmail.com>
# Filename: 2m4b
# Date created: 2014-02-27 16:52
# Last modified: 2014-02-27 16:52
# Modified by: Kai Xia <xiaket@corp.netease.com/xiaket@gmail.com>
#
# Description:
# create an m4b audiobook file from a movie or an mp3 file.
You can’t perform that action at this time.