Skip to content

Instantly share code, notes, and snippets.

View andyxning's full-sized avatar
:octocat:
I may be slow to respond.

Ning Xie andyxning

:octocat:
I may be slow to respond.
  • Beijing, China
View GitHub Profile
@andyxning
andyxning / add_linux_man_page_docset_to_Dash.sh
Created June 9, 2020 10:17
Add linux man page docset to Dash
#!/bin/bash
# Under instructions in: https://blog.kapeli.com/linux-man-pages-in-dash
set -x
set -e
man_path_dest_dir="/usr/local/share/man"
man_pages_version="5.06"
linux_man_pages_download_link="https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/man-pages-${man_pages_version}.tar.xz"
@andyxning
andyxning / npd_kernel_monitor.json
Created December 22, 2016 12:59
npd_kernel_monitor
{
"logPath": "/var/log/kern.log",
"lookback": "10m",
"startPattern": "Initializing cgroup subsys cpuset",
"bufferSize": 10,
"source": "npd",
"conditions": [
{
"type": "KernelDeadlock",
"reason": "KernelHasNoDeadlock",
@andyxning
andyxning / k8s_insufficient_cpu_message.md
Created December 16, 2016 10:53
k8s_insufficient_cpu_message
pod (vv10dece4d-9avwu) failed to fit in any node fit failure on node (192.168.0.1): Insufficient CPU fit failure on node (192.168.0.2): Insufficient Memory fit failure on node (192.168.0.3): Insufficient Memory fit failure on node (192.168.0.4): Insufficient CPU fit failure on node (192.168.0.5): Insufficient CPU fit failure on node (192.168.0.6): Insufficient CPU fit failure on node (192.168.0.7): Insufficient CPU fit failure on node (192.168.0.8): Insufficient CPU fit failure on node (192.168.0.9): Insufficient CPU fit failure on node (192.168.0.10): Insufficient CPU fit failure on node (192.168.0.11): Insufficient CPU fit failure on node (192.168.0.12): Insufficient CPU fit failure on node (192.168.0.13): Insufficient CPU fit failure on node (192.168.0.14): Insufficient CPU fit failure on node (192.168.0.15): Insufficient Memory fit failure on node (192.168.0.16): Insufficient Memory fit failure on node (192.168.0.17): Insufficient CPU fit failure on node (192.168.0.18): Insufficient CPU fit failure on
@andyxning
andyxning / necessary_git_skills.md
Created August 9, 2016 03:57
Necessary Git Skills

Tags

  • update tags
  • git fetch 'refs/tags/*:refs/tags/*'
@andyxning
andyxning / NaN_Inf_Near_zero_MarshalJSON.go
Created December 15, 2015 08:55
NaN, Inf and Near zero value MarshalJSON
type JsonSpecial float64
func (value JsonSpecial) MarshalJSON() ([]byte, error) {
// Handle NaN, Inf and near-zero values marshalling
if math.IsNaN(float64(value)) || math.IsInf(fload64(value), 0) {
return json.Marshal(nil)
} else if math.Exp(float64(value)) == 1 {
return json.Marshal(0)
}
@andyxning
andyxning / check_whether_an_ip_is_loopback.go
Created December 9, 2015 08:48
check whether an ip is loopback
package main
import "fmt"
import "net"
func main() {
IPv4Loopback := net.ParseIP("127.0.0.1")
IPv6Loopback := net.ParseIP("::1")
NonIPv6LoopbackOne := net.ParseIP("2001:db8::1")
NonIPv6LoopbackTwo := net.ParseIP("fe80::1%lo0")
@andyxning
andyxning / sort_a_dict_in_python.py
Last active November 11, 2015 08:55
Sort a Dict in Python
#/usr/bin/env python
# -*- coding: utf-8 -*-
a = {3:4, 1:2, 5:6}
# Demo1
#
# get a list of tuples consisting the dict,
# sort the list with tuple items
print sorted(a.items())
@andyxning
andyxning / get_current_function_name_in_python.py
Last active May 6, 2022 07:36
get current function name in Python
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Note: This may only work in CPython. For more info please see python doc about sys._getframe
import sys
# This will also show that function name(co_name) in python is bounded to function code(f_code).
# i.e., function assignment will not change the attribute of "co_name", function name
@andyxning
andyxning / element_not_in_an_array_test_in_awk.txt
Created August 19, 2015 12:44
element not in an array test in awk
# [reference 1](http://www.unix.com/302702781-post2.html)
# awesome in using Ternary Operator
awk '
BEGIN {
a["1"]="a";
a["2"]="b";
a["3"]="c";
}
{ print !( $1 in a) ? "x" : a[$1]; }
'
@andyxning
andyxning / single_quote_usage_in_awk.txt
Last active August 29, 2015 14:27
single quote usage in awk
single quote using in awk
###### Using Single QUote in awk script
function ltrim_single_quote(s) { return sub(/^\047+/, "", s); return s}
function rtrim_single_quote(s) { return sub(/'\047+$/, "", s); return s}
function trim_single_quote(s) { return ltrim_single_quote(rtrim_single_quote(s)) }
* [reference 1](http://www.gnu.org/software/gawk/manual/html_node/Quoting.html)