Author Archives: Robins

How to Use the object of ES6 to clear the object value

Use the ES6 Object to clear the Object value
ES6 Object using incidentally paste JS if clearing the Object value method

In front in the process of compiling, Vue, for example, a page is bounced, bounced in assignment objects, so when we close the popup window after the assignment, the object has not been reset or empty, when open again, bounced objects in the content still exists, according to the normal js method, we will put the value of the object a reduction, this is very troublesome, of course, also may be alone to write a function, but the emergence of ES6 makes the process easier.

ES6 Object is used

# Initializing objects
let param = {
	id: '',
	name: '',
	age: 0,
	isManager: false,
	updateTime: new Date()
}
# Assign a value to an object, not shown here (on-page action).
# Use the Object.keys() function to initialize the object to its original state
```javascript
Object.keys(param).forEach(key => (
	switch (typeof param[key]) {
		case 'string':
			param[key] = '';
		case 'boolean':
			param[key] = false;
		case 'date':
			param[key] = new Date();
		case 'number':
			param[key] = 0;			
	}
))
# Use the above method when special types require special handling.
Object.keys(param).forEach(key => param[key] = '')

By the way, paste js if clearing theobject value method

# Assigned Objects
let param = {
	id: '1',
	name: '2',
	age: 3,
	isManager: true,
	updateTime: new Date()
}
# Start Emptying
for (let key in param) {
	param[key] = ''
}
# The logic of the specific initialization type is the same as that of ES6 above, so I won't repeat it.

TypeError: Cannot read property ‘username‘ of undefined

TypeError: Cannot read property ‘username’ of undefined
Recently, onLoad() was used in the uni-App development project of Android app. During the life cycle, the value of Username needed to be changed, but TypeError: TypeError: Cannot read property ‘username’ of undefined was frequently reported



causes this to always point to undefined, which may be because the arrow function is strictly limited to the point of this, or change back later, it is ok;

Could not publish server configuration for Tomcat v8.5 server at localhost

Could not publish Server Configuration for Tomcat V8.5 Server at localhost. The solution
Problem analysis
Possible exception: Multiple duplicate project names are stored in the Context tag in the server.xml file in the Servers file
The solution
Find the Servers file in Eclipse. Find the folder with the name of the server used to start the project in it, and under its directory find the server.xml file
At this time found that the document is very lengthy, small white shows that look dizzy..
Find the Design view at the bottom, click on the Design view to change the view, find the small arrow to the left of Servers, click on the small arrow to see the subdirectory of Servers, and keep looking for the small arrow until you find the Context.

You can clearly see the duplicate item name in the Context, right-click on it and select Remove to remove the redundant Context save (Ctrl+S or click save in the upper left corner, the * on the file label will disappear).
We’re done. Go and restart the project.

An error 1064 is reported when pymysql accesses the image

An error has been reported while accessing images in the mysql database using Pymysql. The code is as follows
Error message: (1064, “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00′ at line 1”)
I found a lot of methods on the Internet, but I couldn’t solve the problem. Later, I tried again and again and finally solved it
Note that the size of the binary BLOB in mysql is smaller than the size of the binary BLOB when designing a table, change the binary data to mediumBLOB
The code is as follows:
import pymysql
from datetime import datetime
To create the database, first connect to the mysql database
Conn = Pymysql.connect (host=’127.0.0.1′, user=’root’, Database =’ smart_apartment_DB ‘,
password=’160507pcsd’, charset=’utf8′)
Create a cursor
cursor = conn.cursor()
The # ExCute () function can execute simple SQL statements
f = open(file=’./img/imageOne.jpg’, mode=’rb’)
dataimg = f.read()
f.close()
nowtime = datetime.now().strftime(“%Y-%m-%d, %H:%M:%S”)
argdata = pymysql.Binary(dataimg)
sqlone = “insert into img_pack(imgtime,imgdata) values(‘%s’,’%s’)” % (
nowtime, argdata)
try:
cursor.execute(sqlone)
conn.commit()
except Exception as e:
conn.rollback()
Print (” Error message: “, e)
Close the cursor first
cursor.close()
Close the database connection again
conn.close()
 
After many attempts, the problem was found
sqlone = “insert into img_pack(imgtime,imgdata) values(‘%s’,’%s’)” % (
Remove the ‘%s’ single quotation mark from nowtime, argdata and change to
sqlone = “insert into img_pack(imgtime,imgdata) values(%s,%s)”
Cursor. Execute (SQlone) changed to CURSOR. Execute (SQlone, (nowtime, argdata))
You can store images in a binary stream like mysql
The correct code is as follows
import pymysql
from datetime import datetime
 
To create the database, first connect to the mysql database
Conn = Pymysql.connect (host=’127.0.0.1′, user=’root’, Database =’ smart_apartment_DB ‘,
password=’160507pcsd’, charset=’utf8′)
Create a cursor
cursor = conn.cursor()
The # ExCute () function can execute simple SQL statements
 
f = open(file=’./img/imageOne.jpg’, mode=’rb’)
dataimg = f.read()
f.close()
nowtime = datetime.now().strftime(“%Y-%m-%d, %H:%M:%S”)
argdata = pymysql.Binary(dataimg)
 
sqlone = “insert into img_pack(imgtime,imgdata) values(%s,%s)”
 
try:
cursor.execute(sqlone, (
nowtime, argdata)
)
conn.commit()
except Exception as e:
conn.rollback()
Print (” Error message: “, e)
 
 
Close the cursor first
cursor.close()
Close the database connection again
conn.close()

Waiting for another pilot command to release the startup lock

During normal development, Android Studio connected to the emulator and did not show it
If Waiting for another flutter Command to release the startup lock..    
Two solutions;

    switch network (the first one is not ok, the second one is not ok) into the SDK directory of flutter, then find bin/cache/lockfile file, delete it, then run the doctor of flutter, and then connect to the simulator.

The mistake will be solved

Windows update failed to update, indicating the solution of 0x80244021

Recently, it was found that one of the company’s windows7 computers could not be automatically updated. When clicking the “check update” button, 0x80244021 error will be prompted. The Windows update.log is as follows:


    2011-11-08  09:51:13:363     972    13d8    AU  Triggering AU detection through DetectNow API  2011-11-08  09:51:13:363     972    13d8    AU  Triggering Online detection (interactive)  2011-11-08  09:51:13:363     972    a10 AU  #############  2011-11-08  09:51:13:363     972    a10 AU  ## START ##  AU: Search for updates  2011-11-08  09:51:13:363     972    a10 AU  #########  2011-11-08  09:51:13:363     972    a10 AU  <<## SUBMITTED ## AU: Search for updates [CallId = {1436F467-82EE-4DED-A72D-5694818E7E49}]  2011-11-08  09:51:13:363     972    2b54    Agent   *************  2011-11-08  09:51:13:363     972    2b54    Agent   ** START **  Agent: Finding updates [CallerId = AutomaticUpdates]  2011-11-08  09:51:13:363     972    2b54    Agent   *********  2011-11-08  09:51:13:363     972    2b54    Agent     * Online = Yes; Ignore download priority = No 2011-11-08  09:51:13:363     972    2b54    Agent     * Criteria = “IsInstalled=0 and DeploymentAction=’Installation’ or IsPresent=1 and DeploymentAction=’Uninstallation’ or IsInstalled=1 and DeploymentAction=’Installation’ and RebootRequired=1 or IsInstalled=0 and DeploymentAction=’Uninstallation’ and RebootRequired=1” 2011-11-08  09:51:13:363     972    2b54    Agent     * ServiceID = {3DA21691 -E39D-4DA6-8A4B-B43877BCB1B7} Managed  2011-11-08  09:51:13:363     972    2b54    Agent     * Search Scope = {Machine}  2011-11-08  09:51:13:363     972    2b54    Setup   Checking for agent SelfUpdate  2011-11-08  09:51:13:363     972    2b54    Setup   Client version: Core: 7.5.7601.17514  Aux: 7.5.7601.17514  2011-11-08  09:51:13:363     972    2b54    Misc    Validating signature for C:\windows\SoftwareDistribution\SelfUpdate\wuident. cab:  2011-11-08  09:51:13:378     972    2b54    Misc     Microsoft signed: Yes  2011-11-08  09:51:13:409     972    2b54    Misc    WARNING: WinHttp: SendRequestToServerForFileInformation failed with 0x801901f6  2011-11-08  09:51:13:409     972    2b54    Misc    WARNING: WinHttp: ShouldFileBeDownloaded failed with 0x801901f6  2011-11-08  09:51:13:409     972    2b54    Misc    WARNING: DownloadFileInternal failed for http://172.16.160.236:8530/selfupdate/wuident. cab: error 0x801901f6  2011-11-08  09:51:13:409     972    2b54    Setup   WARNING: SelfUpdate check failed to download package information, error = 0x80244021  2011-11-08  09:51:13:409     972    2b54    Setup   FATAL: SelfUpdate check failed, err = 0x80244021  2011-11-08  09:51:13:409     972    2b54    Agent     * WARNING: Skipping scan, self-update check returned 0x80244021  2011-11-08  09:51:13:409     972    2b54    Agent     * WARNING: Exit code = 0x80244021  2011-11-08  09:51:13:409     972    2b54    Agent   *********  2011-11-08  09:51:13:409     972    2b54    Agent   **  END  **  Agent: Finding updates [CallerId = AutomaticUpdates]  2011-11-08  09:51:13:409     972    2b54    Agent   *************  2011-11-08  09:51:13:409     972    2b54    Agent   WARNING: WU client failed Searching for update with error 0x80244021  2011-11-08  09:51:13:409     972    2148    AU  >>##  RESUMED  ## AU: Search for updates [CallId = {1436F467-82EE-4DED-A72D-5694818E7E49}]  2011-11-08  09:51:13:409     972    2148    AU    # WARNING: Search callback failed, result = 0x80244021  2011-11-08  09:51:13:409     972    2148    AU    # WARNING: Failed to find updates with error code 80244021  2011-11-08  09:51:13:409     972    2148    AU  #########  2011-11-08  09:51:13:409     972    2148    AU  ##  END  ##  AU: Search for updates [CallId = {1436F467-82EE-4DED-A72D-5694818E7E49}]  2011-11-08  09:51:13:409     972    2148    AU  #############

The company’s environment is such that all client computers use ISA server2006 proxy to access the Internet via an internal WSUS server (172.16.160.236) update patch, and some computers have ISA firewall client software installed.
The windows 7 computer on which the problem was found had the ISA firewall client installed on it.
Solution.
On this problematic windows 7, open a cmd command prompt window and type.

 netsh winhttp set proxy proxy-server=”http=isasvr.xxx.com:8080″ bypass-list=”172.16.160.236″

The effect of the above command is that the communication with the internal WSUS server does not go through the ISA proxy server, i.e., it is updated directly from the WSUS server.

CMake Error at CMakeLists.txt:5 (PROJECT): The CMAKE_C_COMPILER: cl is not a full path

Error info:
– Building for NMake Makefiles
— The C compiler identification is unknown
— The CXX compiler identification is unknown
CMake Error at CMakeLists. txt:5 (PROJECT):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, c make must be run from a shell that can use the compiler cl from the command line.   This environment is unable to invoke the cl compiler.   To fix this problem, run CMake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable “CC” or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.

CMake Error at CMakeLists. txt:5 (PROJECT):
The CMAKE_CXX_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, c make must be run from a shell that can use the compiler cl from the command line.   This environment is unable to invoke the cl compiler.   To fix this problem, run c make from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable “CXX” or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.

— Configuring incomplete, errors occurred!
See also “E:/gc/c_test1/build/CMakeFiles/CMakeOutput.log”.
See also “E:/gc/c_test1/build/CMakeFiles/CMakeError.log”.

How to Fix
1.Don’t use make.. Use  these  commands:

cmake -G "MSYS Makefiles" ..

2. If the first one doesn’t work, set the path:

$ export CC=/c/MinGW/bin/gcc.exe
$ export CXX=/c/MinGW/bin/g++.exe
$ cmake -G "MinGW Makefiles" ..
-- The CXX compiler identification is GNU 4.8.1        
...
$ mingw32-make

The second:

$ cmake -DCMAKE_C_COMPILER=/c/MinGW/bin/gcc.exe -DCMAKE_CXX_COMPILER=/c/MinGW/bin/g++.exe ..

If not, please refer to the following link:
https://www.e-learn.cn/content/wangluowenzhang/22835
https://stackoverflow.com/questions/29746950/cmake-cannot-find-compiler

DataTables warning encountered using DataTables: table id = DataTables_Table_0 – Ajax error. For more information ab

Using DataTables met this error page DataTables warning: table id = DataTables_Table_0 – Ajax error. For more information about this error, please see http://datatables.net/tn/7, record the hope to help everyone.

is the ajax parameter problem, adminid must be the same as the background Controller parameter name, otherwise the interface will not be implemented and error will be reported.

/*  Adding request parameters to data */
	"fnServerParams" : function(data) {
		data.adminid=$("#adminid").val()
		console.log("id为"+$("#adminid").val())
	},

If an error is reported after the Controller is executed, then the return value is usually faulty, null pointer or the data is not converted to JSON data back.

SharePoint site shows ‘Service Unavailable. HTTP Error 503. The service is unavailable’

I haven’t started the SharePoint server for a while, and when I start it up, I find that Central Administration can’t access it, which displaysService Unavailable HTTP Error 503. The service is unavailable,

How to Fix this Issue?

    Go to Start >> All Programs >> Administrative Tools >> Internet Information Services (IIS) Manager. Locate your App Pool account(such as SharePoint Central Administration v4, the third line on the right panel, see below figure) and right-click on it and select ‘Advanced Settings’. Go to process model then Identity Click on the Identity >> Set and then give the user name, password, and confirm password.

The reason may be that the account password has expired and needs to be reset.

https://sharepoint.stackexchange.com/questions/22605/http-503-service-unavailable-error-messages-when-attempting-to-open-sharepoint

C language write() function analysis: write failed bad address

When running the following test program on the ARM development board, “Write Failed Bad address” would appear probabilistic:

/* Write test */
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

int main(int argc,char* argv[]){
 int i = 0;
 int w_rw = 0;
 int fd = -1;
 int bw = -1;
 int nob = 0;
 char* file_name = "testfile";
 char buff[30] = "Testing";

 w_rw = 1;       // 1 - write , 2 - rewrite
 nob = 1024;  // No of bytes to write

 for(i = 0; i < w_rw; i++){
        if((fd = open(file_name,O_CREAT | O_RDWR))< 0){
                perror("Open failed!");
                return -1;
        }

        printf("fd:%d",fd);
        if((bw = write(fd,buff,nob)) < 0){
                perror("Write failed!");
                return -1;
        }
        printf("\n Bytes written : %d \n",bw);
 }

 return 0;
}

write() function man manual. The description of this function is as follows:

Function definition: ssize_t write (int fd, const void * buf, size_t count); 
Function Description: write() writes a count of bytes from the memory specified by buf to the file specified by fd.
Return Value: If write() succeeds, it returns the actual number of bytes written (len). When an error occurs, it returns -1, and the error code is stored in errno.

Here the byte written from the buf file fd file is determined by the count, not the actual allocated memory of the buf file. Thus, there is a case for accessing invalid addresses (Bad address</code b>) : if the value of count is greater than the actual allocated memory size of buf, the write() function may attempt to access invalid addresses beyond the actual memory space of buf.
The problem with the above test code is that buf is small, only 30 bytes, and write() is trying to write 1024 bytes, which will probabilistically access the invalid address. This problem can be solved by simply modifying the following code:

        if((bw = write(fd,buff,sizeof(buf))) < 0){
                perror("Write failed!");
                return -1;
        }

Maven Compilation error jdwp on getting class status, jvmtierror = JVMTI_ERROR_WRONG_PHASE(112)

Today, running the maven compiled project gave errors
JDWP exit error JVMTI_ERROR_WRONG_PHASE(112): on getting class status [../../../src/share/back/util. c:1265]
JDWP exit error JVMTI_ERROR_INVALID_ENVIRONMENT(116): Can’t allocate jvmti memory [../../../src/share/back/util. c:1779]
FATAL ERROR in native method: JDWP on getting class status, jvmtiError=JVMTI_ERROR_WRONG_PHASE(112)
FATAL ERROR in native method: JDWP Can’t allocate jvmti memory, jvmtiError=JVMTI_ERROR_INVALID_ENVIRONMENT(116)

The Internet says to set up maven to use local jdk, specifically open settings.xml and add jdk under the tag.

<profile>  
    <id>jdk17</id>  
    <activation>  
        <activeByDefault>true</activeByDefault>  
        <jdk>1.7</jdk>  
    </activation>  
    <properties>  
        <maven.compiler.source>1.7</maven.compiler.source>  
        <maven.compiler.target>1.7</maven.compiler.target>  
        <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>  
    </properties>   
</profile>  

But it’s strange that I didn’t change the configuration of the project, but I reported this mistake today. It’s amazing.

PM2 user defined Log, PID and other Log File Locations

Method one:


Direct reference pm2 official:
http://pm2.keymetrics.io/docs/usage/log-management/
Log configuration


CLI
Example:

$ pm2 start echo.js --merge-logs --log-date-format="YYYY-MM-DD HH:mm Z"

Options:

--merge-logs                 do not postfix log file with process id
--log-date-format <format>   prefix logs with formated timestamp
-l --log [path]              specify entire log file (error and out are both included)
-o --output <path>           specify out log file
-e --error <path>            specify error log file

JSON way

 {
  "script"          : "echo.js",
  "error_file"      : "err.log",
  "out_file"        : "out.log",
  "merge_logs"      : true,
  "log_date_format" : "YYYY-MM-DD HH:mm Z"
}

Combine out and err logs
To combine all logs into the same file set the same value for error_file, out_file or use an additional log_file.
For example, this keeps out and err separated but adds a combined file:

{
  "log_file": "combined.outerr.log",
  "out_file": "out.log",
  "err_file": "err.log"
}

Or if you want out and err combined without any other file, just use the same log file:

{
  "out_file": "combined.log",
  "err_file": "combined.log"
}

Note that relatives logs paths will usually be written in the PM2_HOME (~/.pm2/logs).
Method 2:


Modify ~/. Pm2 directory conf.js

//conf.js


/**
 * Overidde PM2 configuration
 */

var p    = require('path');

module.exports = function(DEFAULT_HOME) {

  if (!DEFAULT_HOME)
    return false;

  var PM2_HOME = DEFAULT_HOME;

  var pm2_conf = {
    PM2_HOME                 : PM2_HOME,

    PM2_LOG_FILE_PATH        : p.join(PM2_HOME, 'pm2.log'),
    PM2_PID_FILE_PATH        : p.join(PM2_HOME, 'pm2.pid'),

    DEFAULT_PID_PATH         : p.join(PM2_HOME, 'pids'),
    //For example, changing the default location of pm2 logs. 
    DEFAULT_LOG_PATH         : '/data/pm2logs',
    DUMP_FILE_PATH           : p.join(PM2_HOME, 'dump.pm2'),

    DAEMON_RPC_PORT          : p.join(PM2_HOME, 'rpc.sock'),
    DAEMON_PUB_PORT          : p.join(PM2_HOME, 'pub.sock'),
    INTERACTOR_RPC_PORT      : p.join(PM2_HOME, 'interactor.sock'),

    GRACEFUL_TIMEOUT         : parseInt(process.env.PM2_GRACEFUL_TIMEOUT) || 8000,
    GRACEFUL_LISTEN_TIMEOUT  : parseInt(process.env.PM2_GRACEFUL_LISTEN_TIMEOUT) || 3000,

    CONCURRENT_ACTIONS       : parseInt(process.env.PM2_CONCURRENT_ACTIONS) || 1,

    DEBUG                    : process.env.PM2_DEBUG || false,
    WEB_INTERFACE            : parseInt(process.env.PM2_API_PORT)  || 9615,
    MODIFY_REQUIRE           : process.env.PM2_MODIFY_REQUIRE || false,

    PM2_LOG_DATE_FORMAT      : process.env.PM2_LOG_DATE_FORMAT !== undefined ?process.env.PM2_LOG_DATE_FORMAT : 'YYYY-MM-DD HH:mm:ss',

    INTERACTOR_LOG_FILE_PATH : p.join(PM2_HOME, 'agent.log'),
    INTERACTOR_PID_PATH      : p.join(PM2_HOME, 'agent.pid'),
    INTERACTION_CONF         : p.join(PM2_HOME, 'agent.json5')
  };

  return pm2_conf || null;
};

execute pm2 kill to kill the pm2 and then execute pm2 start your configuration to make the change take effect.