Ness001

永不放弃的信念和孤注一掷的勇气


  • Home

  • About

  • Tags

  • Archives

GDB debugging introduction

Posted on 2022-05-08

This article introduces the common commands and shortcuts using GDB.
Suppose we have a program named hello.c and complied using gcc -g -o hello hello.c.

commands

Begin gdb session: gdb hello

Set breakpoint: break #lineNumber, eg break 10

Hint: Find line number by using vim hello.c, press escape and input :set nu

Run: run, run with stdin: run < inputfile.txt

Start debugging: start

Show local variables: info locals

Watch a local variable: watch variableName

Continue debugging: continue

Step in: step, executed the next line without stepping in: next

Display a variable at each step: display variableName

shortcuts

In gdb session, press ctrl+x and then press a to show the source code. Press ctrl+x and then press 2 to show the corresponding assembly code.

gdb source code

You could also install cgdb to have better experiences. Use cgdb hello and press escape to scroll the source code and press i to exe command

Press ctrl+x and then press 2 one more time to show the CPU register group.
gdb cpu registry
Use info all-registers to show all registers.
Use tui reg float to show float registry group.

Untitled

Posted on 2021-08-09

Hexo自定

Hexo NexT主题添加点击爱心效果

创建js文件

在/themes/next/source/js/src下新建文件clicklove.js,接着把该链接下的代码拷贝粘贴到clicklove.js文件中。
代码如下:

1
!function(e,t,a){function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o(),r()}function r(){for(var e=0;e<d.length;e++)d[e].alpha<=0?(t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px;top:"+d[e].y+"px;opacity:"+d[e].alpha+";transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg);background:"+d[e].color+";z-index:99999");requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick;e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div");a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style");a.type="text/css";try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s(){return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[];e.requestAnimationFrame=function(){return e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document);

修改_layout.swig

在\themes\next\layout\_layout.swig文件末尾添加:

1
2
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>

添加动态背景

_layout.swig

找到themes\next\layout\_layout.swig文件,添加内容:
在``里添加:

1
2
3
<div class="bg_content">
<canvas id="canvas"></canvas>
</div>

仍是该文件,在末尾添加:

1
<script type="text/javascript" src="/js/src/dynamic_bg.js"></script>

dynamic_bg.js

在themes\next\source\js\src中新建文件dynamic_bg.js,代码链接中可见:dynamic_bg.js

custom.styl

在themes\next\source\css\_custom\custom.styl文件末尾添加内容:

1
2
3
4
5
6
7
.bg_content {
position: fixed;
top: 0;
z-index: -1;
width: 100%;
height: 100%;
}

tag cloud

进入到 hexo 的根目录,在命令行中输入npm install hexo-tag-cloud@^2.0.* --save

在 package.json 中添加依赖: "hexo-tag-cloud": "2.0.*" ,在

在文件 theme/next/layout/_macro/sidebar.swig的</nav>标签之前添加如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
{% if site.tags.length > 1 %}
<script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
<div class="widget-wrap">
<h3 class="widget-title">Tag Cloud</h3>
<div id="myCanvasContainer" class="widget tagcloud">
<canvas width="250" height="250" id="resCanvas" style="width=100%">
{{ list_tags() }}
</canvas>
</div>
</div>
{% endif %}

增加新页面页面

hexo new post tags/about/archive

其中对于tags:

open …/_posts/tags/index.md

title: tags
date: 2020-05-21 18:35:04
layout: “tags”
type: tags

bug

导航栏中点击tags,archive,home,浏览器提示找不到,比如annot GET /tags/%20/

对theme/next/_config.yml文件进行编辑,将中“||”前的空格删掉,上面已经是编辑好的配置,如下所示。

menu:

home: /|| home

about: /about/|| user

tags: /tags/|| tags

#categories: /categories/ || th

archives: /archives/|| archive

#schedule: /schedule/ || calendar

#sitemap: /sitemap.xml || sitemap

# commonweal: /404/|| heartbeat

Untitled

Posted on 2021-08-09

Env

10.3 xcode

macos mojave

Method

  • open /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/IDETextKeyBindingSet.plist
  • Add the following lines into the root dictionary (after first dict occurrence)
1
2
3
4
5
6
7
8
9
<key>Sublime Commands</key>
<dict>
<key>Cut Current Line</key>
<string>selectLine:, cut:</string>
<key>Copy Current Line</key>
<string>selectLine:, copy:</string>
<key>Duplicate Current Line</key>
<string>selectLine:, copy:, moveToBeginningOfLine:, paste:, moveToEndOfLine:</string>
</dict>
  • restart xcode
  • cmd + , go to key bindings, go to Text, go to Sublime Commands
    • add your own shortcut

nvidia-ubuntu-env

Posted on 2020-11-01

tested for two times.

prepare

  • download os from aliyun: http://mirrors.aliyun.com/ubuntu-releases/2
    • choose amd64 desktop version
  • download qv2ray and v2ray core from github
  • download ultraiso
  • download cuda.run for your ubuntu version
    • https://developer.nvidia.com/cuda-toolkit-archive

use a portable disk to save all the files in case next time you need them

install ubuntu

  1. prepare a blank usb flash disk
  2. open the os iso in ultraios, and write it to your usb flash disk
  3. compress a blank partition in other disks, compress a 200m partition in your windows-disk
  4. reboot, in bois, select the usb flash disk, reboot
  5. edit install config(press e), add nomodeset after quite splash ( or it will 花屏)
  6. f10 to reboot
  7. begin install
    1. choose the last option for install
    2. add ubuntu disk partitions on your blank partition
      1. /, main partition
      2. home, logistic partition
      3. add efi on 200m partition
      4. add swap if your ram is small
  8. after installation reboot
  9. in grub, edit again, use e, add nomodeset after quite splash

install cuda and graphic card driver

tutorials on Chinese websites are not good enough. they always said you need to install the driver first, but actually the cuda will recommend you to install the driver while you are installing cuda

  1. copy the cuda.run from your external disk to your local disk

  2. change directory to where your cuda is

  3. sudo chmod x+a cuda.run

  4. sudo ./cuda.run

  5. after installation, edit environment variables

sudo gedit /etc/profile, append contents like in the bottom

refer to https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#post-installation-actions for more

1
2
3
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

source /etc/profile to make it activated

check

  1. use nvidia-smi and nvcc -V to check whether it works.

  2. now you would be able to reboot the system without the need to add nomodeset

  3. run cuda examples

    • cd ~/nvidia_cuda-11.1-examples

    • make

    • devicequery, it is under utilities/devicequery

install docker

https://docs.docker.com/engine/install/ubuntu/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

check

sudo docker run hello-world

add permission

1
2
3
sudo gpasswd -a current_user_name docker
Sudo service docker restart
reboot

install others, just follow the document

  • ngc
  • nvidia docker

use vm to boost local docker pull

  1. cd to vm_for_docker_pull ( it is from my private repo)
  2. in bash, ssh -i nessvm-asia_key.pem ness@52.175.13.200
  3. pull the containers from NGC
  4. docker tag image_from_ngc registry.cn-hangzhou.aliyuncs.com/ness001/image_name
  5. on your local computer, docker pull registry.cn-hangzhou.aliyuncs.com/ness001/image_name

current pushed images

registry.cn-hangzhou.aliyuncs.com/ness001/ +aliyun image name

original name tag aliyun image name usage
nvcr.io/nvidia/tlt-streamanalytics v2.0_py3 nv-tlt transfer learning toolkit
nvidia/cuda 11.0-base cuda11 test for nvidia-docker2

prepare ml env

Posted on 2020-10-02

I built my new pc last month and walked through the tedious installation process for future machine learning usage.

Here are some reusable snippets just in case I forgot.

My wares

hardware

  • Intel 10900k
  • RTX 2070s Colorful Adoc
  • ASUS Z490 edge wifi version
  • 3600mhz 32G RAM

software

  • win10 professional version
  • efficiency tools
    • listary
    • chrome
      • toby

conda

  • download anaconda
  • invoke anaconda prompt
  • create env
    • conda create --name wow
    • conda create --name wow python=3.7.3
  • list env
    • conda env list
  • activate env
    • conda activate wow
  • list env packages
    • conda list
  • clone an env
    • conda create --name copy --clone wow
  • remove an env
    • conda env remove --name copy

add conda to path

  • in cmd, where conda
  • add three paths to system environment variable PATH
    • 1
    • 2
    • 3

change mirror

find .condarc file under your user folder, replace the content with

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

If you need to restore to the default settings, just delete all the lines after show_channel_urls line or you can use conda config --remove-key channels

pip

  • conda install pip

  • change mirror

    • (1)阿里云 http://mirrors.aliyun.com/pypi/simple/
      (2)豆瓣http://pypi.douban.com/simple/
      (3)清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
      (4)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
      (5)华中科技大学http://pypi.hustunique.com/
    1
    2
    pip install pip -U
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
  • search for a package

    • pip search keras

prepare ml+dl env

install packages

1
2
3
pip install pandas scikit-learn seaborn tqdm
pip install jupyter notebook
pip install jupyter_contrib_nbextensions

the latest tf2 supports both gpu and cpu.

https://pytorch.org

https://www.tensorflow.org/install

install cuda

You should check the pytorch page for cuda version or it can’t detect your gpu properly.

Till now, the latest cuda version you could use is CUDA10.02.

You can find all cuda versions here.

  • https://developer.nvidia.com/cuda-toolkit-archive

The difference between CUDA and cuDNN:

  • https://blog.csdn.net/u014380165/article/details/77340765

which cnDNN should you install

just use pip install cudnn and it will automatically choose the right version of cudnn for your cuda version.

pandas strange row number mismatch

Posted on 2020-05-30

前情提要

一个30兆不到的csv文件,70多万条数据。

使用read csv加low memory选项读入。

始终显示:

class ‘pandas.core.frame.DataFrame’>
Int64Index: 80350 entries, 0 to 722963
Data columns (total 5 columns):
user_id 80350 non-null float64
item_id_pred 80350 non-null float64
score 80350 non-null float64
rank 80350 non-null float64
item_id_true 80350 non-null float64
dtypes: float64(5)
memory usage: 3.7 MB

debug途中有一瞬间存在过30m全部读入的情况,可是再难复现。

可能的原因

  • 文件被其他程序使用着 - 排除,我没有打开

  • 文件编码原因 - 未知

  • read_csv选项里还要加东西quoting=csv.QUOTE_NONE, error_bad_lines=Fals -实验后,无用

使用pyinstaller将pyqt5打包为MacOS App

Posted on 2020-05-20

官方文档

https://pyinstaller.readthedocs.io/en/stable/usage.html

TL;DR

1
2
3
4
cd yourprogram
sudo pyi-makespec --onefile --windowed yourscript.py
#如果你修改了py文件,也不用再运行一遍👆的代码
sudo pyinstaller --clean --noconfirm yourscript.spec

出现no permission问题,用sudo就对了。

我的环境:

163 INFO: PyInstaller: 3.6
164 INFO: Python: 3.7.4
187 INFO: Platform: Darwin-19.2.0-x86_64-i386-64bit
219 INFO: UPX is available.

代码

基本格式:

pyinstaller options.. myscript.py

pyinstaller --windowed --onefile --clean --noconfirm testqt.py

这样生成的文件夹dist中是pkg文件,往往打开就出错,不知为何

通过上面的代码,根目录下还会生成一个spec文件,spec文件是告诉pyinstaller如何打包你的程序的配置文件,对spec文件做相同的操作,就可以获得app文件。

pyinstaller options.. myscript.spec

pyinstaller --clean --noconfirm testqt.spec

怎么直接获得spec文件呢?

pyi-makespec options *name*.py

spec文件打开后应该能看到类似这样的字样

1
2
3
4
app = BUNDLE(exe,
name='myscript.app',
icon=None,
bundle_identifier=None)

options

注意短横-后是缩写,–后是全称。

https://pyinstaller.readthedocs.io/en/stable/usage.html

对py的pyinstaller 和pyi-makespec命令(只列出常用)

  • –clean
    • Clean PyInstaller cache and remove temporary files before building.
  • –noconfirm -y
    • Replace output directory (default: SPECPATH/dist/SPECNAME) without asking for confirmation
  • –windowed -w
    • Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. On Windows this option will be set if the first script is a ‘.pyw’ file. This option is ignored in *NIX systems.
  • –onefile -F
    • Create a one-file bundled executable.
  • onedir -D
    • Create a one-folder bundle containing an executable (default)
  • –osx-bundle-identifier BUNDLE_IDENTIFIER
    • Mac OS X .app bundle identifier is used as the default unique program name for code signing purposes. The usual form is a hierarchical name in reverse DNS notation. For example: com.mycompany.department.appname (default: first script’s basename)

官方说对于对py的pyinstaller选项库和pyi-makespec的选项库是一样的。

You create a spec file using this command:

pyi-makespec options *name*.py [other scripts …]

The options are the same options documented above for the pyinstaller command. This command creates the *name*.spec file but does not go on to build the executable.

然而其实不是的,如果你加入 –clean的选项,则会出现pyi-makespec: error: unrecognized arguments: --clean,经过测试–noconfirm也是不能用的。

对spec的pyinstaller

对于spec文件操作,只有这些命令是起作用的。

  • --upx-dir=
  • --distpath=
  • --workpath=
  • --noconfirm
  • --ascii
  • --clean

高分辨率app

当你好不容易打包好一个app后问题又来了,你发现你的app的ui异常模糊,分辨率很低。你只需要在spec文件中加上info_plist就能解决问题。

1
2
3
4
5
6
7
8
app = BUNDLE(exe,
name='myscript.app',
icon=None,
bundle_identifier=None
info_plist={
'NSHighResolutionCapable': 'True' #<------这一句
},
)

减小app体积

写python程序的过程中尽量不要使用import,而是用from…import…来减少调用。

第一步:安装upx

  • 使用brew install upx

第二部:使用pipenv的干净环境进行打包操作。

  • 以下是一个本人的通用流程。依次在bash中运行。
1
2
3
4
5
6
7
8
pip install pipenv
pip install pipreqs
pipreqs #generate clean requirements.txt
pipenv install
pipenv shell
pip install -r requirements.txt
pyi-makespec --onefile --windowed myscript.py
pyinstaller --noconfirm --clean myscript.spec

不知道问题出在哪里怎么办?

运行dist文件夹下的同名unix进程,该进程会在terminal中打开,如果有错误会在terminal中表现出来。

比如我的app一开始只要双击就会闪退,于是我使用这个方法,控制台中出现了如下错误。经过搜索了解到是setuptools最新的几个版本和pyqt5有点冲突。使用pip install setuptools==44.0.0安装44版本后就没问题了。

File “site-packages/pkg_resources/init.py”, line 86, in

ModuleNotFoundError: No module named ‘pkg_resources.py2_warn’

remove an executable file to \usr\bin

Posted on 2020-03-30

It very silly setting of the MacOs
When you want to remove an executable file to \usr\bin, you will find it impossible, because It is protect by SIP (System integrity Protection). If you want to disable it, you have to go to the safety mode, which is restarting your mac with CMD+R holding. Then, in the safety tool -terminal, you can run a command to disable it.

Actually, you don’t need to do all these. You can just paste your exe file into …\usr\local\bin. It is equally effective as you put it in …\usr\bin.

switch提升网速的dns测试

Posted on 2020-02-18

测试背景

电信光纤200m,上海

腾达千兆5g路由器

测试结果

香港:

218.102.23.228

203.80.96.10

label encoder和ordinal encoder的区别

Posted on 2019-12-15

中文圈的资料大多都是错的或者语焉不详。在此阐述清楚,为后来人开路。

一句话

两者功能一样。但label适用于目标变量,而ordinal适用于多个特征变量。

原因

查询sklearn官方文档,可以看到label encoder的fit方法,输入的数据是 y array-like of shape (n_samples,)

,而ordinal encoder输入的数据是X array-like, shape [n_samples, n_features。

12>

13 posts
9 tags

Tag Cloud

  • MacOS1
  • apple1
  • cs61c tools1
  • ml1011
  • nvidia1
  • python2
  • sklearn1
  • switch1
  • ubuntu1
RSS
© 2022 Liang Li
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4