## An introduce to xlsxwriter :)

xlsxwriter is an xlsx auto generate with charts in python

Today i will show how to generate the xlsx and send to reporter!

I am a maintainer and the server status must be reported to my boss every weekend . They prefer xlsx file and charts in the file.

So , i have to generate the xlsx with chart includ the summary of server status data .

finally , i will send it via my yandex mail to my boss.:)

xlsxwriter

## An interesting problem for Spiral matrix!

few days ago . my friend go to have an interview.he saw this meaningful algorithm . like leetcode spiral matrix.

here is my code,in my code,i predefine the matrix is 17*17 ðŸ™‚

``````    int arr[17][17];
int m=17;
int n=17;
int i = 0;
int j = 0;
int count = 1;
int the_max = 0;
int max = m*n;
// initial to 0
for (int j = 0; j < n; j++)
{
for (int i = 0; i < m; i++)
{
arr[i][j] = 0;
}
}
// construct the matrix
for (; count <= max; )
{
i = the_max;
j = the_max;
// top row
for(;i<m-the_max-1;i++){
arr[i][j] = count++;
}
// right column
for(;j<n-the_max-1;j++){
arr[i][j] = count++;
}
// bottom row
for(;i>the_max;i--){
arr[i][j] = count++;
}
// left column
for(;j>the_max;j--){
arr[i][j] = count++;
}
the_max++;
}``````

something detail must to be caucion .the odd parameter should have a special process.
since the last row,the first 12 rows cannot print the last row.for example 17*17 , 656,666 wil not show instead of 0.
so i hope i will fix it will the code in the future ðŸ™‚

i think this problem also have other more powerful solutions!

## Mysql add user and grant privilege

``````\$ CREATE USER 'new_user_name'@'%' IDENTIFIED BY 'the_password';
\$ GRANT ALL PRIVILEGES ON *.* TO 'new_user_name'@'%';
# the first * is database`s name, the second * is table`s name
\$ FLUSH PRIVILEGES;``````
learn from digitalocean ðŸ™‚

## Python raw tcp data convert to int

Today i will talk about the python built-in function ord() .

For example, I receive raw data from serial or tcp device,the data always be the array of binary.When you print it to console,it shows like b’\x01\xe5′ and so on.

To convert this data to int like below.

``````raw_data = b'\x01\xe5'
print(int(ord(raw_data)),16)``````

Thats it! very simple!OK thanks for reading see you soon!

## Compile gost with mipsel support

I have a ASUS AC1200GU router,And I use gost to proxy my web trafic.But i have a startup script in my win7.When i boot the system,the system will run the script and start an gost instance to proxy my web trafic to server.

The question is , in my computer , i have many OS (win7,win10,ubuntu etc.) and in my home i have many mobile phone,pads and laptop.I never though i want setup a startup script in my mobile phone , laptop. ðŸ™‚

The best solution is run the gost client in low power consumtion device such as Raspberry pi , routers and so on.So i must compile gost in ARM or mipsle architecture.In my case ,my router is mipsel-linux-gnu-gcc-8 -march=1004Kc

``````\$ git clone https://github.com/ginuerzh/gost
\$ cd gost/cmd/gost
\$ GOOS=linux GOARCH=mipsle go build

# and the bin gost will place in gost/cmd/gost folder
# in other country the golang package manager network connection may unstable
# you can use the command below to accelerate

\$ export GOPROXY=https://mirrors.aliyun.com/goproxy/``````

## How to analyze Apache access.log with AWStats?

When i use VirtualSever in WanWang.com which provide the awstats report for administrator to help analyze the webserver`s visit status.In my case , I want a single static html file , easily to share ðŸ™‚

First of all .you must change you awstats.model.conf correctly!

In my case , i change this.

``````LogFormat=1
# i change to 4 default is 1

LogFile="/var/log/httpd/mylog.log"
# change the path to you access.log file full path!``````

Then you can run the command below to generate the html report file!

``````\$ cd awstats-7.7\wwwroot\cgi-bin
\$ perl awstats.pl -config=model -output -staticlink >> youserver.html``````

When you access.log file include long duration of year.you can use sed command to extract the line you want to analyze!

``\$ sed -n '[start line number],[end line number]p' access.log >> access_sed.log``

Conclusion:

Some images in the static html can`t show , so i will figure it out later.

for more detail pls visit

https://www.awstats.org/

## How to limit cpu usage with Nodejs?

I want to introduce the node-cpulimit in this post.When i use puppeteer ,some page cost a long time in page loading. At the same time , the cpu limit will increase instantly.So i want to find some tools to help limit the cpu usage.

A very simple example to use cpulimit and childprocess

``````const limiter = require('cpulimit');

// Run command
const { spawn } = require('child_process');
const node = spawn('node', ['/root/puppeteer.js']);

// Run cpulimit
const options = {
limit: 50, // or any other value
includeChildren: true,
pid: node.pid
};

limiter.createProcessFamily(options, (err, processFamily) => {
if (err) {
console.error('Error:', err.message);
return;
}

limiter.limit(processFamily, options, (err) => {
if (err) {
console.error('Error:', err.message);
} else {
console.log('Done.');
}
});
});``````

for more detail pls visit

https://github.com/vangelov/node-cpulimit

## Get player data and match via PUBG API

The programmer who do not know data analyze is not a good player in PUBG. ðŸ™‚

I will show some tool method below

``````# this function get the player data by PUBG player name and return the json data

def get_player_data(name):
"Authorization": "Bearer {}".format(PUBG_API_TOKEN),
"Accept": "application/vnd.api+json",
}

return result.json()``````
``````# this function get the match data by match id and return the match data json
def get_matches_by_id(id):
"Accept": "application/vnd.api+json",
}

return result.json()``````

This post just show the tool function . The next post will show how to use it and extract data!

## download GoProxy via vultr vps startup and open a socks proxy

As we know , Goproxy just release the latest version on github and delete the old releases. And more , the goproxy will check update at the proxy program startup.

Try to image , you vps reboot , you have to download the latest goproxy and run a socks proxy, And you must use shell script on vps bootup!

Here is the shell script . The script visit the goproxy github repository and get the latest linux version download link.Then download the goproxy ,extract it and run it.

``````#!/bin/sh