Skip to content

Instantly share code, notes, and snippets.

@jemyzhang
jemyzhang / get_current_rss.c
Last active April 1, 2024 11:38
common functions
/**
* Returns the current resident set size (physical memory use) measured
* in bytes, or zero if the value cannot be determined on this OS.
*/
size_t getCurrentRSS( )
{
long rss = 0L;
FILE* fp = NULL;
if ( (fp = fopen( "/proc/self/statm", "r" )) == NULL )
return (size_t)0L; /* Can't open? */
@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 / install_makemkv.sh
Last active February 12, 2019 01:26 — forked from knugie/install_makemkv.sh
Ubuntu - Install MakeMKV 1.10.2
sudo apt-get install build-essential pkg-config libc6-dev libssl-dev libexpat1-dev libavcodec-dev libgl1-mesa-dev qt5-default
wget http://www.makemkv.com/download/makemkv-oss-1.10.2.tar.gz
wget http://www.makemkv.com/download/makemkv-bin-1.10.2.tar.gz
tar -xvf makemkv-oss-1.10.2.tar.gz
tar -xvf makemkv-bin-1.10.2.tar.gz
cd makemkv-oss-1.10.2/
./configure
make
sudo make install
@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 / spacemacs.mirror
Last active March 23, 2018 01:45
[Mirror of emacs in China] mirror site of china to install spacemacs #emacs
(defun dotspacemacs/init ()
(setq configuration-layer--elpa-archives
'(("gnu" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("melpa" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
("melpa-stable" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/melpa-stable/")
("org" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/org/")
("marmalade" . "https://mirrors.tuna.tsinghua.edu.cn/elpa/marmalade/")))
@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 / 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() {
@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:]"