[Python] Produces a circular image of 001-100

import matplotlib.pyplot as plt
import numpy as np

def draw_circle_with_number(number, filename):
    fig, ax = plt.subplots(figsize=(5, 5))
    ax.set_xlim(0, 1)
    ax.set_ylim(0, 1)

    # draw circular
    circle = plt.Circle((0.5, 0.5), 0.4, color='blue', fill=False, linewidth=4)
    ax.add_artist(circle)

    # add text
    ax.text(0.5, 0.5, f'{number:03}', color='black', fontsize=90,
            ha='center', va='center', weight='bold')

    # hide axis
    ax.set_xticks([])
    ax.set_yticks([])
    ax.set_aspect('equal')

    # save to file
    plt.savefig(filename, bbox_inches='tight', pad_inches=0)
    plt.close()

# ceate 001 ~ 100
for i in range(1, 101):
    draw_circle_with_number(i, f'circle_{i:03}.png')
Posted in Python | Comments Off on [Python] Produces a circular image of 001-100

[Postman] Upload file to s3 in pre-request script

First, select binary in the body settings, and assign a file at will.
Then the real file path will be obtained through the syntax in pre-script.

In some cases, you may need to set the file directory to Postman’s working directory first.

pm.request.body.update({
    mode: "file",
    file: {
        src: pm.environment.get("filePath")
    }
})
Posted in Postman | Comments Off on [Postman] Upload file to s3 in pre-request script

CSS: Center text (horizontally and vertically)





    
    404 Error Page
    



    

404


此活動不存在

Ref.: iThome: 29. CSS 水平置中/ 垂直置中的方法

Posted in CSS, HTML | Comments Off on CSS: Center text (horizontally and vertically)

Mac OS X upgrade cURL with SSL support

┌─Cowman@CLOUD-42:~/Downloads/20160511 └──$ sh curl.sh guList curl: (1) Protocol “‘https” not supported or disabled in libcurl

┌─Cowman@CLOUD-42:~/Downloads/20160511 └──$ brew install curl –with-nghttp2 ==> Installing dependencies for curl: openssl, pkg-config, libev, libevent, jansson, boost, libxml2, spdylay, nghttp2

….

Posted in Mac | Leave a comment

Delete snapshots older than 7 days

To avoid running out of disk space in our test environment, we developed a plan to regularly execute shell scripts to clean up unnecessary snapshots.

#!/bin/bash

week=`date --date='7 days ago' +'%Y%m%d'`
echo "list_snapshots" | /home/webuser/hbase-1.2.9/bin/hbase shell | grep "pattern " | \
while read CMD; do
    filename=($CMD)
#    echo $filename
    date=`echo $filename | awk -F "_" '{print $2}'`
#    echo  "${filename#*_}"
#    echo $date
#    echo ${date:0:8}
    if [ "${date:0:8}" -lt $week ]
    then
        echo "delete_snapshot '$filename'" | /home/webuser/hbase-1.2.9/bin/hbase shell
    fi
done
Posted in HBase, Shell Script | Comments Off on Delete snapshots older than 7 days

Continuously print the file content

Use the command ‘tail’ to print the file contents, starting from the beginning of the file and print new contents continuously.

tail +1f 'file'
Posted in Linux | Comments Off on Continuously print the file content

HBase Client 2.5.5 in JDK 11

Because of the vulnerability scan results of the project, the JDK version must be upgraded from 8 to 11 to complete the repair.

The original HBase Client version 1.2 we used was incompatible with JDK 11, so we had to update the HBase Client version.
After collecting and comparing information on the Internet, I am planning to upgrade the HBase Client version to 2.5.5. The main reason why not choose a newer version (such as version 3) is that the difference between the versions is too big.

However, version 2.5.5 is still incompatible with JDK 11, so some adjustments must be made to make the service work properly.
Referring to the instructions at https://www.cnblogs.com/yjmyzz/p/hbase_client_with_jdk17.html, we must add this setting to the jvm startup parameters.

"--add-opens=java.base/java.lang=ALL-UNNAMED"

Due to the upgrade of HBase Client, “NoSuchColumnFamilyException” errors will occur in existing usage methods (such as using tableExists to confirm whether the table exists).
After referring to the relevant instructions on the Internet, this error is mainly due to the different table management mechanism of version 2.5.5 (https://stackoverflow.com/a/58498721). Therefore, the related usage methods need to be changed and adjusted.

  1. Adjust checkTableExist method

    We first obtain all table information through “listTableDescriptors”, and then use this information to check whether it exists.

  2. Adjust isTableEnabled method (check whether table status is enabled)

    Use try-catch block to catch exceptions, and use the captured exceptions to determine whether the required state is already in place.

    try {
        hbaseAdmin.disableTable(TABLE_NAME);
    } catch (TableNotEnabledException e) {
        LOG.debug("TABLE_NAME is already disable");
    } catch (Exception e) {
        throw e;
    }
    
Posted in HBase, Java | Comments Off on HBase Client 2.5.5 in JDK 11

AES decrypt in postman

sample code:

var CryptoJS = require("crypto-js"); 
let secretKey = 'yourSecretKey'; 

function decrypt(aesStr, key) { 
    return CryptoJS.AES.decrypt( 
        aesStr, 
        CryptoJS.enc.Utf8.parse(padding(key)), 
        { 
            mode: CryptoJS.mode.ECB, 
            padding: CryptoJS.pad.Pkcs7 
        } 
    ).toString(CryptoJS.enc.Utf8) 
} 

function padding(key) { 
    return key.padEnd(32, '\0'); 
} 

//decrypt("encryptedData", secretKey)

Here we choose AES-256 to encrypt / decrypt the secure information. When using AES, the length of the secretKey is important. The length of secretKey in AES-128 is 16 bits, and in AES-256 is 32 bits.

And in our case, the length of secretKey is no enough. So we will use the function padding to fill in the missing length.

source: CSDN: AES解密,key长度不够16处理

Posted in JavaScript, Postman | Comments Off on AES decrypt in postman

[Java] Create CSV files with BOM

public static final String UTF8_BOM = "\uFEFF";

public ByteArrayInputStream createFile(Object object) {
    try {
        CSV csv = (CSV) object;
        StringBuffer sb = new StringBuffer();
        sb.append(UTF8_BOM);

        if (csv.getHeaderList() != null) {
            sb.append(StringUtils.join(csv.getHeaderList().toArray(new String[0]), ",")).append("\n");
        }

        for (List<String> row : csv.getDataList()) {
            sb.append(StringUtils.join(row.toArray(new String[0]), ",")).append("\n");
        }

        return new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
    } catch (Exception e) {
        return null;
    }
}
Posted in Java | Comments Off on [Java] Create CSV files with BOM

[Linux] pkill command

I don’t know what’s going on.

But we can use command “pkill” to delete those abnormal processes.

sudo pkill -f pgrep

Reference: stackoverflow: How to kill all processes with a given partial name?

Posted in Linux | Comments Off on [Linux] pkill command