aben20807 / blog-post-issues Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://aben20807.github.io/
License: MIT License
Home Page: https://aben20807.github.io/
License: MIT License
$ gcc -g -ggdb -fno-omit-frame-pointer <target>
$ perf record --call-graph dwarf -g <target>
$ perf script > out.perf
$ ./stackcollapse-perf.pl out.perf > o.folded
$ ./flamegraph.pl o.folded >| o.svg --width 50000
https://stackoverflow.com/a/5373814
static void D() { }
static void Y() { D(); }
static void X() { Y(); }
static void C() { D(); X(); }
static void B() { C(); }
static void S() { D(); }
static void P() { S(); }
static void O() { P(); }
static void N() { O(); }
static void M() { N(); }
static void G() { M(); }
static void A() { B(); G(); }
int main() {
A();
}
$ vim t.cpp
$ clang++ -S -emit-llvm t.cpp -o - | opt -analyze -dot-callgraph
$ cat callgraph.dot |
c++filt |
sed 's,>,\\>,g; s,-\\>,->,g; s,<,\\<,g' |
awk '/external node/{id=$1} $1 != id' |
dot -Tpng -ocallgraph.png
$ eog callgraph.png
#include "adder.h"
int add(int a, int b)
{
return a + b;
}
extern "C" {
int add(int a, int b);
}
$ g++ -o libadder.so -shared -fPIC adder.cc
from ctypes import cdll
adder_lib = cdll.LoadLibrary("libadder.so")
add = adder_lib.add
print(add(1, 3))
$ sudo sh -c 'echo 1 > /proc/sys/vm/drop_caches'
$ sudo sh -c 'echo 2 > /proc/sys/vm/drop_caches'
$ sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'
java formatter: https://github.com/coveo/fmt-maven-plugin
https://bogdancornianu.com/change-swap-size-in-ubuntu/
$ sudo swapoff -a
$ sudo dd if=/dev/zero of=/swapfile bs=1G count=8
8+0 records in
8+0 records out
8589934592 bytes (8.6 GB, 8.0 GiB) copied, 214.629 s, 40.0 MB/s
$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 8 GiB (8589930496 bytes)
no label, UUID=984c57f8-ef1e-46a3-ba35-6bc23bd896af
$ sudo swapon /swapfile
W: GPG error: file:/var/cuda-repo-10-0-local-10.0.130-410.48 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY F60F4B3D7FA2AF80
Ref: NVIDIA/nvidia-docker#571 (comment)
$ sudo vim /etc/apt/sources.list.d/cuda.list
deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /
$ wget -qO - https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub | sudo apt-key add -
(require 'smooth-scrolling)
(smooth-scrolling-mode 1)
(setq smooth-scroll-margin 5)
open source video editor
https://shotcut.org/
https://github.com/mltframework/shotcut
download "64-bit Linux portable tar" from official website
$ tar xf shotcut-linux-x86_64-181223
$ ~/.Program/Shotcut
$ ./Shotcut.app/shotcut
$ sudo apt install valgrind
http://www.valgrind.org/docs/manual/quick-start.html#quick-start.mcrun
$ valgrind --leak-check=yes ./cache testcase/6_bits/cache.txt testcase/6_bits/ReferenceList.txt
https://github.com/aben20807/computer_architecture/tree/master/proj
https://the.exa.website/
https://github.com/ogham/exa
alias ls='exa -F --classify'
alias ll='ls -alF'
alias lls='ls --sort=size -l'
$ cargo build --release
$ ln -s /home/ben/.Program/exa/exa/target/release/exa /home/ben/.local/bin/exa
https://handyfloss.wordpress.com/2008/02/15/python-speed-vs-memory-tradeoff-reading-files/
https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects
f = open(filename,'r')
for line in f.readlines():
if condition:
do something
f.close()
faster:
f = open(filename,'r')
for line in f:
if condition:
do something
f.close()
dict.iteritems()
dict.items()
"\e[A": history-search-backward
"\e[B": history-search-forward
http://vimcdoc.sourceforge.net/doc/syntax.html#:syn-arguments
https://github.com/vim/vim/tree/master/runtime/syntax
after/syntax/lcc.vim
syn match lccIntType "int[0-9]*\(\s\|\[\)"me=e-1
syn match lccFloatType "float[0-9]*\(\s\|\[\)"me=e-1
syn keyword lccSecure public secure
syn keyword lccPackage package
syn keyword lccConditional if else
syn keyword lccRepeat while for bwhile bfor
syn match lccUserFunction "\<\h\w*\>\(\s\|\n\)*("me=e-1
hi def link lccIntType Type
hi def link lccFloatType Type
hi def link lccSecure StorageClass
hi def link lccPackage Include
hi def link lccRepeat Repeat
hi def link lccConditional Conditional
hi def link lccUserFunction Function
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"
$ mcd .oh-my-bash/themes/ouo
$ vim ouo.theme.sh
# ouo theme
# Author: Huang Po Hsuan
# inspired by theme "pure" "cupcake"
# scm theming
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY=" ${bold_red}✗${normal}"
SCM_THEME_PROMPT_CLEAN=" ${green}✓${normal}"
SCM_GIT_CHAR="${green}±${normal}"
SCM_GIT_BEHIND_CHAR="${bold_blue}↓${normal}"
SCM_GIT_AHEAD_CHAR="${bold_blue}↑${normal}"
SCM_GIT_UNTRACKED_CHAR="${bold_blue}⌀${normal}"
SCM_GIT_UNSTAGED_CHAR="${bold_yellow}•${normal}"
SCM_GIT_STAGED_CHAR="${bold_green}+${normal}"
CLOCK_THEME_PROMPT_PREFIX=''
CLOCK_THEME_PROMPT_SUFFIX=' '
THEME_SHOW_CLOCK=true
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$green"}
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"[%H:%M]"}
scm_prompt() {
CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ]
then
return
else
echo "[$(scm_prompt_info)]"
fi
}
rightprompt() {
printf "%*s" $COLUMNS "$1"
}
ouo_prompt() {
# ps_host="${bold_blue}\h${normal}";
# ps_user="${green}\u${normal}";
# ps_root="${red}\u${red}";
# ouo="${green}ouo${normal}";
if [ $? -ne 0 ]
then
ps_user_mark="${red}$ ${normal}";
else
ps_user_mark="${green}$ ${normal}";
fi
ps_root_mark="${green}# ${normal}"
ps_path="${yellow}\w${normal}"
# make it work
# PS1="\n$(clock_prompt)$ps_path $(scm_prompt)"
PS1L="$ps_path $(scm_prompt)"
PS1R="$(clock_prompt)"
# Ref: https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Right-justified_text
PS1=$(printf "\n$(tput sc; rightprompt $PS1R; tput rc)%s" "$PS1L")
# case "$HAS_GOTO" in
# 1) PS1="${PS1}\n${GOTO_PROMPT}"
# printf "OuO"
# ;;
# esac
case $(id -u) in
# 0) PS1="$ps_root@$ps_host$(scm_prompt):$ps_path\n$ps_root_mark"
0) PS1="${PS1}\n$ps_root_mark"
;;
# *) PS1="$ps_user@$ps_host$(scm_prompt):$ps_path\n$ps_user_mark"
*) PS1="${PS1}\n$ps_user_mark"
;;
esac
}
safe_append_prompt_command ouo_prompt
$ vim ~/.bashrc
OSH_THEME="ouo"
Sticky bit wiki
So what is the sticky bit?
https://www.thegeekstuff.com/2011/02/sticky-bit-on-directory-file/
$ ls -ld /tmp
drwxrwxrwt - root 12 七 9:44 /tmp/
How to get group name of highlighting under cursor in vim?
:echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
bash: /tmp/bashmarks.gnc3m4: cannot overwrite existing file
$ vim ~/.oh-my-bash/plugins/bashmarks/bashmarks.plugin.sh
# purge line
- sed "/$2/d" "$1" > "$t"
+ sed "/$2/d" "$1" >| "$t"
/bin/mv "$t" "$1"
http://blog.linux.org.tw/~jserv/archives/001870.html
use dladdr to show function name
https://unix.stackexchange.com/a/386903
print indent
https://www.dennisthink.com/?p=63
Makefile:
all:
g++ -c tracer.c -g
g++ tracer.o main.cpp -fPIC -ldl -finstrument-functions -export-dynamic -g
clean:
rm *.out *.o
tracer.c:
#ifdef __cplusplus
extern "C"
{
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dlfcn.h>
void __cyg_profile_func_enter (void *, void *)
__attribute__((no_instrument_function));
void __cyg_profile_func_exit (void *, void *)
__attribute__((no_instrument_function));
// extern int trace_on;
// int trace_on = 1;
}
#endif
#define TRACE_FD 3
static FILE *fp_trace=NULL;
static int nDepth = 0;
void __attribute__((constructor)) traceBegin(void) {
fp_trace = fopen("func_trace.out", "w");
}
void __attribute__((destructor)) traceEnd(void) {
if (fp_trace != NULL) {
fclose(fp_trace);
fp_trace = NULL;
}
}
void __cyg_profile_func_enter (void *func, void *caller)
{
// if (!trace_on) {
// return;
// }
nDepth++;
for(int i = 0 ; i < nDepth ; i++) {
if(fp_trace) {
fprintf(fp_trace,"\t");
}
}
Dl_info info;
if (fp_trace == NULL) {
fp_trace = fdopen(TRACE_FD, "w");
if (fp_trace == NULL) abort();
setbuf(fp_trace, NULL);
}
if (dladdr(func, &info)) {
// fprintf (fp_trace, "in %p [%s] %s\n",
// func,
// info.dli_fname ? info.dli_fname : "?",
// info.dli_sname ? info.dli_sname : "?");
fprintf (fp_trace, "in [%s] %s\n",
info.dli_fname ? info.dli_fname : "?",
info.dli_sname ? info.dli_sname : "?");
}
}
void __cyg_profile_func_exit(void *func, void *caller)
{
// if (!trace_on) {
// return;
// }
for(int i = 0 ; i < nDepth ; i++) {
if(fp_trace) {
fprintf(fp_trace,"\t");
}
}
nDepth--;
Dl_info info;
if (fp_trace == NULL) {
fp_trace = fdopen(TRACE_FD, "w");
if (fp_trace == NULL) abort();
setbuf(fp_trace, NULL);
}
if (dladdr(func, &info)) {
// fprintf (fp_trace, "out %p [%s] %s\n",
// func,
// info.dli_fname ? info.dli_fname : "?",
// info.dli_sname ? info.dli_sname : "?");
fprintf (fp_trace, "out [%s] %s\n",
info.dli_fname ? info.dli_fname : "?",
info.dli_sname ? info.dli_sname : "?");
}
}
main.cpp:
#include <iostream>
#include <cstdio>
#include <cstdlib>
extern int traceon;
// int trace_on = 1;
using namespace std;
int bar(float f) {
printf("%f\n", f);
}
void foo(int a) {
printf("%d\n", a);
bar(4.4);
}
int main()
{
puts("c++");
foo (3);
puts("gg");
return 0;
}
func_trace.out:
in [./a.out] ?
in [./a.out] ?
out [./a.out] ?
out [./a.out] ?
in [./a.out] main
in [./a.out] _Z3fooi
in [./a.out] _Z3barf
out [./a.out] _Z3barf
out [./a.out] _Z3fooi
out [./a.out] main
$ head -n 2 file.txt | tail -n 1
https://github.com/universal-ctags/ctags
$ sudo apt install autoconf automake libtool
$ sudo apt install pkg-config
$ git clone https://github.com/universal-ctags/ctags.git
$ cd ctags
$ ./autogen.sh
$ ./configure --program-prefix=uni
$ make
$ sudo make install
Plug 'majutsushi/tagbar', {'do': 'unictags -R -h \".h .c .hpp .cpp .java .python .y .l\"'}
let g:tagbar_ctags_bin = '/usr/local/bin/unictags'
plugin: https://github.com/rlue/vim-barbaric
ime:
$ sudo apt-get install fcitx fcitx-chewing
$ fcitx-config-gtk3 # 新增 chewing 輸入法
https://gist.github.com/tanyuan/c0d4ee15cf0c9c93da28cc1cf0ff87b3
https://askubuntu.com/a/1074135
$ pip install pre-commit
# ref: https://github.com/junegunn/fzf/issues/542#issuecomment-210463399
$ vim $(fzf)
Ref: https://askubuntu.com/a/55960
tar -xvf jdk-7*
sudo mkdir /usr/lib/jvm
sudo mv ./jdk1.7* /usr/lib/jvm/jdk1.7.0
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
$ sudo apt install fcitx-bin fcitx-chewing
$ im-config
$ ll params/ --sort=size -l
Scenario:
Find a bug in dev-branch
branch.
Create a fix-branch
from master, fix it and create PR.
Merge the fix to dev-branch
after merging PR to upstream/master.
$ git add .
$ git commit -m "STASH"
$ git checkout master
$ git checkout -b fix-branch
# fix code
$ git add
$ git commit
$ git push origin fix-branch
# Create PR to upstream repo's master
# Wait the merge by reviewer
$ git checkout master
$ git fetch upstream
$ git merge upstream/master
$ git checkout dev-branch
$ git rebase master
$ git push -f origin/dev-branch
detecting plagiarism
http://theory.stanford.edu/~aiken/moss/
./moss -d extracted/Compiler_*/*.y extracted/Compiler_*/*.y
$ sudo apt install dconf-editor
https://itsfoss.com/click-to-minimize-ubuntu/
org/gnome/shell/extensions/dash-to-dock/click-action
minimize-or-overview
Sensible Horizontal Scroll in Vim
https://ddrscott.github.io/blog/2016/sidescroll/
$ sudo apt install tmux
https://5xruby.tw/posts/tmux/
https://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/
.tmux.conf
: https://gist.github.com/gutoyr/4192af1aced7a1b555df06bd3781a722# `echo $TERM` in bash
set -g default-terminal "xterm-256color"
shift
magic script: temp_throttle.sh
http://seperohacker.blogspot.com/2012/10/linux-keep-your-cpu-cool-with-frequency.html
https://github.com/Sepero/temp-throttle
https://askubuntu.com/a/395666
$ chmod +x temp_throttle.sh
$ sudo ./temp_throttle.sh 80
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.