Skip to content

Instantly share code, notes, and snippets.

@jemyzhang
jemyzhang / print_macro_define.h
Created March 23, 2018 01:53
[Print The Value of Macro Definitions] #c
#define PRINT_MACRO_HELPER(x) #x
#define PRINT_MACRO(x) #x"="PRINT_MACRO_HELPER(x)
#pragma message(PRINT_MACRO(MULTI_CACHE))
#pragma message(PRINT_MACRO(_CACHE))
@jemyzhang
jemyzhang / get_args.sh
Last active September 19, 2019 01:36
[Get Argument List From cmdline of proc info] Get the argetment list from the cmdline of proc #proc
pid=$(pidof $PROCNAME)
cat /proc/$pid/cmdline | xargs -0 echo
@jemyzhang
jemyzhang / list_module_param.sh
Created March 23, 2018 01:44
[List Parameters of Kernel Module] list the parameters of loaded kernel modules #kernel
cat /proc/modules | cut -f 1 -d " " | while read module; do
echo "Module: $module";
if [ -d "/sys/module/$module/parameters" ]; then
ls /sys/module/$module/parameters/ | while read parameter; do
echo -n "Parameter: $parameter --> ";
cat /sys/module/$module/parameters/$parameter;
done;
fi;
echo;
done
@jemyzhang
jemyzhang / efb_update_chatassoc.sh
Last active March 18, 2018 11:35
Update database of EFB for chat association.
#!/bin/bash
SQLITE3=sqlite3
OLD_CHAT_LIST=$1
NEW_CHAT_LIST=$2
TGDATA_DB=$3
usage() {
echo
echo "Usage:"
@jemyzhang
jemyzhang / log.sh
Created November 2, 2017 08:52
log print for shell
set_force_check() {
export force_check=1
if [ x"$1" = x"0" ]; then
force_check=0
fi
}
print_stack() {
local wholepath=$1
# to avoid noise we start with 2 to skip get_stack caller
@jemyzhang
jemyzhang / common.sh
Created November 2, 2017 08:51
common functional scripts
# strip white spaces and tabs from string
string_trim() {
local str=$1
echo "$str" | sed -E 's/^[ \t]*//' | sed -E 's/[ \t]*$//'
}
# convert string to lower case
string_lower() {
local str=$1
echo "$str" | tr "[:upper:]" "[:lower:]"
@jemyzhang
jemyzhang / kcptun.service
Created September 25, 2017 06:09
service script for kcptun
#!/bin/bash
BIN=/usr/local/bin/kcptun
TUNBASE=1000
CFG_PATH=/etc/kcptun
LOG_PATH=/var/log
do_clean_work() {
for f in $(ls $CFG_PATH/*.enable); do
pid=$(cat $f)
@jemyzhang
jemyzhang / stacktrace.cxx
Created September 7, 2017 08:03 — forked from fmela/stacktrace.cxx
A C++ function that produces a stack backtrace with demangled function & method names.
/*
* Copyright (c) 2009-2017, Farooq Mela
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@jemyzhang
jemyzhang / convert_human.sh
Last active November 2, 2017 08:55
convert bytes to human readble size
#!/bin/bash -e
math_calc() {
local format="$1"
local equation="$2"
echo | awk "{printf \"$format\", $equation}"
}
convert_to_bytes() {
#include <fstream>
#include <iterator>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> example;
example.push_back("This");
example.push_back("is");