Skip to content

Instantly share code, notes, and snippets.

View xiaket's full-sized avatar
🦉
SysAdmin

Kai Xia(夏恺) xiaket

🦉
SysAdmin
View GitHub Profile
@xiaket
xiaket / method_as_decorator.py
Last active April 1, 2019 06:02
Define a class method in Python that can work as a decorator for other methods.
#!/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 June 26, 2023 12:24
ECR Lifecycle Policy example with explanations
{
"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 August 10, 2018 01:52
Bash script to add tag to docker images in ECR
#!/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 07:50
Setup Django environment in Pythonista 3 on iOS. Works with Django 2.0+, must have stash installed.
#!/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 October 31, 2017 04:41
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.
#!/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 01:38
generic number class builder
# 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 March 20, 2017 05:28
Get the list of images and tags for a Docker Hub repo
import json
import sys
import requests
AUTH ={
'username': "xiaket",
'password': "YourPasswordHere",
}
@xiaket
xiaket / postmortem.md
Created November 4, 2016 00:20 — forked from mlafeldt/postmortem.md
Example Postmortem from SRE book, pp. 487-491

Shakespeare Sonnet++ Postmortem (incident #465)

Date

2015-10-21

Authors

  • jennifer
  • martym
@xiaket
xiaket / 2m4b
Last active March 20, 2017 05:29
create an m4b audiobook file from a movie or an mp3 file.
#!/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.