Author Archives: Robins

[Solved] Ubuntu ccsm Error: Could not connect: Connection refused Traceback (most recent call last): File “/usr/bin/ccsm”, line 99, in

premise

Environment: Windows 10 LTSC Enterprise Edition 2021
had MSDN mirroring before, and the system was upgraded from 2019 to 2021. The purpose is to install WSL2
Microsoft Store after installation, open the store to install Ubuntu, start the system and run the graphical X-server, the result is an error, an error is reported As shown below:

ccsm error

solution:

export DISPLAY=x.x.x.x=:0

The ip address is the local address, enter cat /etc/resolv.conf to view the ip address

X-server can be set at will, the following Display nunber does not need to be set, the default -1, Extra settings need to check the third

Then enter ccsm to enter

uni-app: How to Get the Androoid Device Mac Address

/**
* Get Androoid device mac address
* */
function getMacAddress(){
  var net = plus.android.importClass("java.net.NetworkInterface")
  console.log('mac', net)
  var wl0 = net.getByName('wlan0')
  var macByte = wl0.getHardwareAddress()
  var str = ''
  for (var i = 0; i < macByte.length; i++) {
    var tmp = "";
    var num = macByte[i];
    if (num < 0) {
      tmp =(255+num+1).toString(16);
    } else {
      tmp = num.toString(16);
    }
    if (tmp.length == 1) {
      tmp = "0" + tmp;
    }
    if(i == macByte.length-1){
      str += tmp;
    }else{
      str = str + tmp + "-";
    }
  }
  console.log('mac', str.toUpperCase())
  return str.toUpperCase()
}

epub Book Error: Blocked script execution in ‘http://localhost:8080/’ because the document ‘s frame is sandboxed and the ‘allow-scripts’ permission is not set.

initEpub() {
      const url = 'http://localhost:8081/epub/' +
        this.fileName + '.epub'
      // console.log(url)
      this.book = new Epub(url)
      console.log(this.book)
      this.rendition = this.book.renderTo('read', {
        width: window.innerWidth,
        height: window.innerHeight,
        method: 'default'
      })
      this.rendition.display() 
    }
  },

 

Reason:

This problem is because of the iframe framework, which is used in epub!

 

Your e-book is placed in the iframe!

If you delete:

method : The 'default' 
 e-book can also be rendered, but the error is not resolved!

 

Solution:

My reason: because of the problem of the epub.js package, the version is relatively high! Uninstall this package and start over

Uninstall:

npm uninstall epubjs

Reload the next specified version of the package:

npm install [email protected]

 

Rendering is successful, no error is reported!

Python: How to Batch Read the Form Information in Word and output them to Excel file

1. Read all the files in the folder and filter out the .doc files (because the python dependency package docx can only open .docx files, you need to filter out the .doc files first and convert them to .docx)

import os

def list_files_doc(path):
    files_doc = []
     for i, j, k in os.walk(path):
         for file in k:
            suffix = file.split( ' . ' )
             if suffix[1] == ' doc ' :
                 print (file)
                files_doc.append(os.path.join(path, file))

    print ( ' List of files in doc format: {} ' .format(files_doc))
     return files_doc


if  __name__ == ' __main__ ' :
    list_files_doc( ' E:\\python_myfile\\read_excel ' )

 

2. Convert .doc files to .docx files

from win32com import client as wc   #Import module

def doc2docx(doc_files):
    word = wc.Dispatch( " Word.Application " )   #Open the word application for doc_file in doc_files:
    
        doc = word.Documents.Open(doc_file) #Open   word file 
        doc.SaveAs( " {}x " .format(doc_file), 12) #Save   as a file with the suffix ".docx", where parameter 12 refers to the docx file 
        doc .Close()   #Close the original word file 
    word.Quit()
     print ( "The doc file is converted to docx completed " )

if  __name__ == ' __main__ ' :
    doc2docx([ ' E:\\python_myfile\\read_excel\\user1 information.doc ' ,])

 

 

3. Read table information from .docx file

copy code
from docx import Document
 import os

def get_data_from_docx_files(path):
     print (path)
    data = []
     for i, j, k in os.walk(path):
         for file in k:
            suffix = file.split( ' . ' )
             if suffix[1] == ' docx ' :
                document = Document(file)   #Read in the file 
                tables = document.tables #Get   the table set in the file 

                table = tables[0]
                name = table.cell(0, 1 ).text
                sex = table.cell(0, 3 ).text
                info = { " name " : name, " sex " : sex}
                 print (info)
                data.append(info)
    return data

if  __name__ == ' __main__ ' :
    get_data_from_docx_files( ' E:\\python_myfile\\read_excel ' )

 

4. Export the information to an excel sheet

import xlwt

def output_excel(header, data, result_excel):
     #Read the text file 
    book = xlwt.Workbook(encoding= ' utf-8 ' , style_compression=0) #Create   a Workbook object, which is equivalent to creating an Excel file 
    sheet = book.add_sheet( ' test ' , cell_overwrite_ok=True)   # # where test is the name of the sheet, cell_overwrite_ok, indicating whether the cell can be overwritten, it is actually a parameter of Worksheet instantiation, the default value is False

    #Write header 
    i = 0
     for k in header:
        sheet.write(0, i, k)
        i = i + 1

    # write content
    row = 1
    for val in data:
         print (val)
        sheet.write(row, 0, val[ ' name ' ])   #the second row and the first column 
        sheet.write(row, 1, val[ ' sex ' ])   #the second row and the second column 
        row = row + 1

    book.save(result_excel)

if  __name__ == ' __main__ ' :
    output_excel([ ' name ' , ' gender ' ], [{ ' name ' : ' Danny ' , ' sex ' : ' female ' }, { ' name ' : ' Merry ' , ' sex ' : ' male ' }], ' results.xls ' )

[Solved] Version 28 (intended for Android Pie and below) is the last version of the legacy support library

Error:

Version 28 (intended for Android Pie and below) is the last version of the legacy support library

 

Solution:

You need to migrate the principle support library to AndroidX and use implementation to add dependencies.

Step 1: Code Section

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.percentlayout:percentlayout:1.0.0'
    testImplementation 'junit:junit:4.13.2'
}

Step 2: Migrate to AndroidX

image

image

image

Test, Launch succeeded, now the problem is solved.

image

Linux Script Example: iptables-nat.sh

#!/bin/bash
# 2022.2.28 by dewan
# DNAT configuration.

iptables -t nat -F

PUB_IFACE="enp125s0f0"
INT_IFACE="enp125s0f1"

LAN="10.0.0.0/8 172.16.0.0/12 192.168.0.0/16"
SERVER_IP=

for ips in $LAN
do
  iptables -t nat -A POSTROUTING -o $PUB_IFACE -s $ips -j MASQUERADE
done

# 20000 ~ 23999
iptables -t nat -A PREROUTING -p tcp -i $PUB_IFACE --dport 20000:23999 -j DNAT --to-destination $SERVER_IP
iptables -t nat -A PREROUTING -p tcp -i $INT_IFACE -d x.x.x.x --dport 20000:23999 -j DNAT --to-destination $SERVER_IP
iptables -t nat -A PREROUTING -p tcp -i $INT_IFACE -d x.x.x.x --dport 20000:23999 -j DNAT --to-destination $SERVER_IP

# 24000 ~ 32000
# reserved

# 32001 ~ 32768
# sshd

for c in {1..15}
do
        for s in {1..12}
        do
                id=$((c*12-12+s))
                dport=$((32000+id))
                chassis=$((130+c))
                ip="172.168.$chassis.$s"
                echo "$ip:22 --> $dport" >> ip_port.info

                iptables -t nat -A PREROUTING -p tcp -i $PUB_IFACE --dport $dport -j DNAT --to-destination $ip:22
                [ $? -eq 0 ] || echo "$ip failed!"
        done
done

# net.ipv4.ip_local_port_range = 32769  48999

# 48999 ~ 60999
# reserved

# 61000 ~ 64999
# 20 range ports for every hosts

rm -f ip_port.info
for c in {1..15}
do
        for s in {1..12}
        do
                id=$((c*12-12+s))
                dport=$((60980+$id*20)):$((60999+$id*20))
                chassis=$((130+c))
                ip="172.168.$chassis.$s"
                echo "$ip --> $dport" >> ip_port.info

                if [ $c -eq 3 -a $s -eq 4 ] ;then
                        ip="172.168.130.2"
                fi

                iptables -t nat -A PREROUTING -p tcp -i $PUB_IFACE --dport $dport -j DNAT --to-destination $ip
                [ $? -eq 0 ] || echo "$ip failed!"
        done
done

# 65000 ~ 65536
# reserved

How to Replace log4j with shell Script in Bulk

Here is a script example to replace log4j in bulk.

 

How to Replace log4j with shell Script in Bulk

#!/bin/ bash
#

#java 6 log4j file directory
lpath6 =/opt/test/ repl6 #java 7 log4j file directory 
lpath7 =/opt/test/ repl7 
jarname = ' log4j*.jar '
#status value
stat = 0
#The production environment can modify the following line to $(ps -ef |grep java |grep -v grep) |while read pro Extract the current java process.
cat grepfile.txt | while read pro
 do 
propath =$( echo ${pro} | awk -F "  "  ' {print $9} ' | awk -F " = "  ' {print $2} ' | awk -F " tomcat "  ' {print $1} ' )
 if [ -d ${propath} ]; then 
    echo  " ----update path: ${propath} starting------ " 
    echo ${pro} | awk -F " " ' {print $8} ' | grep  1.6 
    if [ $? -eq 0 ]; then 
        echo  " -----jdk 1.6------- " 
        for  file  in $( find ${propath} -name ${ jarname} - print)
         do 
            echo ${ file }
             mv -f ${ file } ${ file }_$( date +%y%m%d%H%M%S) && echo  " ${file} back complete! " 
        done 
        \ cp ${lpath6} /*${propath} && echo "cp ${lpath6}/* /${propath} complete"
        stat=1
    else
        echo "-----Discontent-----"
    fi

    if [ ${stat} -eq 0 ];then
    echo ${pro} |awk -F" " '{print $8}' |grep 1.7
    if [ $? -eq 0 ];then
        echo "-----jdk 1.7-------"
        for file in $(find ${propath} -name ${jarname} -print)
        do
            echo ${file}
            mv -f ${file} ${file}_$(date +%y%m%d%H%M%S) && echo "${file} back complete!"
        done
        \cp ${lpath7}/* ${propath} && echo "cp ${lpath7}/* /${propath} complete"
    else
        echo "-----Discontent-----"
    fi
    else
        stat=0
    fi
else
    echo "----update path: ${propath} no exist------"
fi
done