Posts

Showing posts from 2018

How to use gitbook right in local

1. Set up `node.js` env     ```     sudo apt-get install nodejs npm     ``` 2. Install Gitbook     ```     sudo npm install -g gitbook-cli     export PATH=$PATH:/opt/node/bin     ``` 3. Clone your `Gitbook` project from `Github`     ```     git clone your_github_project_address     cd your_github_project_address     ``` 4. Install necessary gitbook plugins     ```     gitbook install ./     ``` 5. `Build and View` or `Output as pdf`     ```     gitbook build .     gitbook serve .     gitbook pdf .     ``` 6. Write in local     https://github.com/GitbookIO/editor-legacy#how-to-install-it-on-linux ___ > create a new book: gitbook init

How to create an chrome extension

1. See the useless official document     https://developer.chrome.com/extensions/getstarted 2. See my codes     https://github.com/yingshaoxo/No_More_Chinese/tree/example-of-chrome-extension 3. Core question     + [Content scripts](https://developer.chrome.com/extensions/content_scripts) have only limited access to Chrome APIs. This access does not include the API you are trying to use (e.g. `chrome.tabs`). If you need to use that API, you will have to do so in a [background script](https://developer.chrome.com/extensions/background_pages).

Make a always running service in android based on kotlin

### 0. What is `service`? You could see `service` as a always running program But by default, a service runs in the same process as the main thread of the application Therefore, you need to use asynchronous processing in the service to perform resource intensive tasks in the background ___ ### 1. Basic idea or resources Official but you can't understand: [Google Developer Guide](https://developer.android.com/training/run-background-service/create-service.html) Unofficial but reachable: [tutorials_point](https://www.tutorialspoint.com/android/android_services.htm) ___ ### 2. Getting started + Create a kotlin file which names `MyService.kt`, and put the following codes in: ``` class MyService : Service() {     @Nullable     override fun onBind(intent: Intent): IBinder? {         return null     }     override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {         // Let it continue running until it is stopped.         Toast.makeText(this

Running Jupyter on server

#### 1. install ``` sudo -H pip install jupyter ``` #### 2. create config ``` jupyter notebook --generate-config ``` #### 3. set password ``` jupyter notebook password ``` #### 4. set ip ``` vim ~/.jupyter/jupyter_notebook_config.json ``` ``` {   "NotebookApp": {     "ip": "0.0.0.0",   } } ``` #### 5. run it ``` jupyter notebook ```

Master FFmpeg

#### I just want to see my beautiful face ``` ffplay -window_title "yingshaoxo" -vf hflip /dev/video0 ``` ___ #### Maybe record my screen with my voice ``` ffmpeg -y -f alsa -i hw:0 -f x11grab -framerate 30 -video_size 1920x1080 -i :0.0+0,0 -c:v libx264 -pix_fmt yuv420p -qp 0 -preset ultrafast ~/Videos/$(date +%F_%A_at_%H:%M:%S).mp4 ``` ___ #### You got it, I couldn't record without my beautiful face ``` ffmpeg -hide_banner -loglevel info -thread_queue_size 512 -y -f alsa -i hw:0 -thread_queue_size 512 -f x11grab -video_size 1920x1080 -i ":0.0" -thread_queue_size 512 -f v4l2 -video_size 320x240 -i "/dev/video0" -c:v libx264 -crf 30 -preset ultrafast -filter_complex 'overlay=main_w-overlay_w-10:main_h-overlay_h-10' -threads 0 ~/Videos/$(date +%F_%A_at_%H:%M:%S).mp4 ``` ___ #### Maybe do something to my face (camera) ``` ffmpeg -hide_banner -loglevel info -thread_queue_size 512 -y -f alsa -i hw:0 -itsoffset -1.266 -thread_queu

Best way to fix grub problem

Try the following ``` grub rescue > ls grub rescue > ls (hd0,msdos2) # let's assume this is the linux partition grub rescue > set root=(hd0,msdos2) grub rescue > set prefix=(hd0,msdos2)/boot/grub # or wherever grub is installed grub rescue > insmod normal # if this produced an error, reset root and prefix to something else .. grub rescue > normal ``` Run the following after you successfully boot ``` sudo update-grub sudo grub-install /dev/sdX # where /dev/sdX is your boot drive. ``` If you have to copy a whole linux system, you could use `Clonezilla` If you want to install multi-system at your machine, you have to make sure you are using grub boot. (There has two signal that shows you are in grub boot mode: 1. The quality of the boot GUI is very bad. 2. It has auto counting.)

Master docker for developing

#### 0. Read This ``` FROM ubuntu:17.10 ENV LANG C.UTF-8 RUN apt-get update RUN apt-get install -y python3 RUN apt-get install -y python3-pip RUN apt-get install -y python3.6-dev COPY ./requirements.txt /usr/src/Local_Show/requirements.txt RUN pip3 install --no-cache-dir -r /usr/src/Local_Show/requirements.txt COPY . /usr/src/Local_Show/ RUN chmod +x /usr/src/Local_Show/tool.sh RUN mkdir -p /usr/src/Local_Show/files EXPOSE 2018 CMD ["bash", "/usr/src/Local_Show/tool.sh", "docker_run"] ``` #### 1. Basic Things `FROM` indicates what image you are based on. `ENV LANG C.UTF-8` sets what encoding your system will use, something will wrong in Chinese Showing without it `RUN` represents every stage you are going, docker will store that stage every time after that line is executed `COPY` is like `cp` The important thing is: **`CMD` is always the final line of your docker file, that command should be running forever as long as dock

Sanic could take the place of Flask

#### Why Sanic? 1. Faster and More stable 2. `async` request handler 3. `WebSockets` support #### For static files servering ``` app.static('/static', './static') ``` #### For jinja2 template rendering ``` from jinja2 import Template from sanic import Sanic from sanic.response import text template = Template('Hello {{ name }}!') app = Sanic() @app.route("/") async def test(request):         data = request.json         return text(template.render(name=data["name"])) app.run(host="0.0.0.0", port=8000) ``` ``` from jinja2 import Template import os from sanic import Sanic from sanic.response import html def render_template(html_name, **args):     with open(os.path.join(os.path.dirname(__file__), 'templates', html_name), 'r') as f:         html_text = f.read()     template = Template(html_text)     return html(template.render(args)) app = Sanic() @app.route("/") async d

一个小目标

音频算法工程师 1. 克服学历障碍,拥有自信人生; 2. 熟悉数字音频信号处理,熟悉模式识别和深度学习开源框架; 3. 音效算法开发或移动、音频内容分析、听歌识曲和哼唱识别实际项目经验者优先; 4. 编程基础扎实,熟悉算法和数据结构,熟练运用c\c++、python等开发语言; 5. 喜欢音乐,对音乐和音频技术的结合感兴趣者优先。 —————— 一年后评价: 这个真是有点难,1、2、5好做,4只有python比较熟

Use Apache to set a file server

``` <VirtualHost>         ServerName file.yingshaoxo.xyz         DocumentRoot "/var/www/html"                                                                   <Directory "/var/www">                                                                            Options Indexes FollowSymLinks MultiViews                                                    AllowOverride None                                                                          Order allow,deny                                                                            allow from all                                                                          </Directory> </VirtualHost> ``` ``` systemctl restart apache2 ``` When you finished doing this, you could remove `/var/www/html/index.html`, then add some folder or file into `/var/www/html/` In the end, you will find your file right in `file.yingshaoxo.xyz`

Apache virtualhost setting for web-sockets

##### Environment 1. A records in DNS manager | Type | Name | Value | | A | blog | your_server_ip | | A | math | your_server_ip | 2. Set up apache2 with this https://certbot.eff.org/ 3. Add necessary module ``` a2enmod proxy proxy_http proxy_wstunnel proxy_balancer lbmethod_byrequests systemctl restart apache2 ``` ##### HTML Codes ```         var ws_link = 'ws://' + location.hostname + "/ws/";         if (window.location.protocol === 'https:') {             ws_link = 'wss://' + location.hostname + "/wss/";         }         var ws = new WebSocket(ws_link); ``` ##### Apache Codes (at /etc/apache2/sites-available/000-default.conf) ``` <VirtualHost *:80>         ServerName blog.yingshaoxo.xyz         ProxyRequests Off         ProxyPreserveHost On         ProxyPass        "/" "http://127.0.0.1:2018/"         ProxyPassReverse "/" "http://127.0.0.1:2018/" </VirtualHost

Can't import or play gnome recorded video in Windows System?

`ffmpeg -i in.mp4 -crf 18 -pix_fmt yuv420p -c:a copy out.mp4`

How to gain permission and delay for user clicking in Kotlin

1. 绑定一个按钮事件: `button.setOnClickListener({ view -> doSomething() })` 2. 申请一个权限并 delay waiting for user ``` // get permission // import android.Manifest if (ContextCompat.checkSelfPermission(this,                 Manifest.permission.WRITE_EXTERNAL_STORAGE)         != PackageManager.PERMISSION_GRANTED) {     ActivityCompat.requestPermissions(this,             arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 999)     Thread.sleep(7 * 1000) } ```

How to set global variable in Kotlin

1. put this on top: ``` object GlobalVariable {     var mp = MediaPlayer() } ``` 2. use it everywhere `GlobalVariable.mp` 3. so you won't have to worry about open too many MediaPlayer at the same time

Review in 2017 and Plans for 2018

Have Done in 2017:  At least solve 100 algorithm problems on leetcode during this year Insist learning on Khan Academy Learn JavaScript for web app design Maintain GitHub project with Vim Solving at least 1 math question per few days Learning New Concept English 4th book Know how to break through the school net Master Linux System like Kali, Ubuntu Master System Installation, including Android, Linux, Windows Plan to do: Use Javascript Use Python3 Use Kotlin Use Golang or C Keep interests in Programming, be happy, don’t mind other’s judgment. ​

Fail to run emulator in Android Studio and Kali System(rolling) with hardware graphics?

``` cd Android/Sdk/emulator/lib64/libstdc++ mv libstdc++.so.6 libstdc++.so.6.bak ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 ```

How to install and use jedi-vim in Kali System

##### 1. Remove old Vim first `apt purge vim*` #### 2. Install essential python relyings `apt install python3 python3-dev` #### 3. Pull jedi-vim to local ``` mkdir ~/.vim cd ~/.vim rm * -fr git clone https://github.com/davidhalter/jedi-vim.git . ``` #### 4. Install a new Vim version for python support `apt install vim-nox`

Master System Installation

##### 修复多系统如 win10 的引导: 0. 主板设置为启动全基于 `BIOS` 1. PE 用 `DISM++` 恢复某个盘的 win10 引导 2. 去那个 win10 玩玩`EasyBCD`也可以 3. 去你安装好的另一个盘的linux,用 `update-grub` ___ #### kali 才是人用的系统 ###### 修复显卡太高级灰屏的问题(如 NVIDIA) 1. `Ctrl+Alt+F1` to terminal 2. `apt-get install lightdm` (choice lightdm) 3. `reboot` ###### 修复  `shutdown now` or `reboot` 卡机的问题 `apt-get update && apt-get dist-upgrade` https://thehacktoday.com/installing-nvidia-driver-and-fix-boot-loading-and-freezing-issue-in-kali-linux/

Keep python script running by systemd service

#### 0. write a python script `vim time_logger.py` ``` import os import logging import time current_dir = os.path.abspath(os.path.dirname(__file__)) logging.basicConfig(filename=os.path.join(current_dir, 'whatsup.log'), level=logging.INFO) now = time.strftime("%H:%M:%S") logging.info(now + '\n') time.sleep(3) ``` #### 1. create a service file `vim  /lib/systemd/system/my_python@your_user_name.service` ``` [Unit] Description=My first python service After=multi-user.target [Service] Type=idle ExecStart=/usr/bin/python /root/Codes/Python/time_logger.py Restart=always #RestartSec=1 [Install] WantedBy=multi-user.target ``` #### 2. reload deamon and enable our service `systemctl daemon-reload` `systemctl enable my_python@your_user_name.service` #### 3. reboot and check `reboot` go to the python script folder and run `cat whatsup.log` constantly, you will see current time logging. #### 4. links may help: https://

Use Chrome on Kali System

## Forget about those tutorials, just follow me. #### 1. download chrome deb file from whatever place #### 2. install chrome `dpkg -i google-chrome-stable_current_amd64.deb` `apt install -f` `dpkg -i google-chrome-stable_current_amd64.deb` #### 3. allow root user to run chrome `vim /opt/google/chrome/google-chrome` change the last line to `exec -a "$0" "$HERE/chrome" "$@" --no-sandbox --user-data-dir` #### 4. just click chrome icon, then enjoy it.