Author Archives: Robins

Gulp Error: Cannot find module ‘jshint/src/cli’;

In the book “Automatic Construction of Web Front End”, according to the second chapter “Introduction to Gulp”, in order to use JSHint to conduct code style check, after installing Gulp-Jshint, I wrote the following example code:

const jshint = require('gulp-jshint');

gulp.task('test', () => {
    return gulp.src('./app/**/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'))
        .pipe(jshint.reporter('fail'))
});

When running gulp test, the following error occurs:

module.js:442
    throw err;
    ^

Error: Cannot find module 'jshint/src/cli'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (E:\Nodejs\mywebpackDemo\node_modules\gulp-jshint\src\extract.js:1:79)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)

Analysis of the
The console reports an error and cannot find Jshint. The easiest way to resolve this error is to install the package that cannot be found.
The solution

NPM install --save-dev jshint
When using JSHint for code style checking, JSHint and gulp-jshint can be installed directly once.
namely:
NPM install --save-dev jshint gulp-jshint
Reference articles:
https://stackoverflow.com/questions/33984558/gulp-error-cannot-find-module-jshint-src-cli

Solution to stray’\357′ in program when gcc is compiled

Link: http://blog.chinaunix.net/uid-23089249-id-61541.html

I got a few header files from my colleagues. It’s ok to compile with GCC, but a whole bunch of them came up when I compiled with ARM-Linux-gcc!

SerialPort.h:1: error: stray ‘\357’ in program

SerialPort.h:1: error: stray ‘\273’ in program

SerialPort.h:1: error: stray ‘\277’ in program

Look at these errors confused, after looking up the Internet, found that some characters in the file compiler does not support. If you look for these characters one by one, you’ll probably be looking for a long time! The simplest solution:
Put the files into The Windows system, use “Notepad” to open these files, and then “save as”, choose the code ASNI, and then under Linux to re-compile with the compiler, generally can pass!

Experience:

The first time: unknown;

Second time: when compiling QT program, prompt this error; According to the above method solved.

Error resolving version for plugin ‘org.apache.maven.plugins:maven-compiler-plugin’ from the repo…

Error resolving version for the plugin ‘. Org, apache maven plugins: maven — the compiler plugin ‘from the repositories [local (E: \ apache maven – 3.5.3 \ repository). Nexus
(http://localhost:8080/nexus-2.14.5-02/content/groups/public)]] : plugins not found in any Plugin repository
The above error occurred at the beginning of the parent project to create the Maven aggregation project. You can see that the maven-Complier-plugin version of org.apache.maven.plugin resolves the error. The wrong configuration is as follows:

Solution: Declare a version for the plug-in:
Add & lt; version> Tags:

  <build>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>2.5.1</version>
              <configuration>
                  <source>1.7</source>
                  <target>1.7</target>
                  <encoding>UTF-8</encoding>
              </configuration>
          </plugin>
      </plugins>
  </build>

In R language, for loop or array truncation, the following error occurs only 0’s may be mixed with negative subscripts

Only 0’s May be mixed with negative subscripts when writing loop statements in R language or truncating arrays

This error is usually caused by writing arrays like x[i-10: I + J-10], and is corrected by enclosing i-10 and I + J-10 in parentheses, such as x[(i-10): I + J-10)].

This will solve the problem, the R beginners must pay attention to these details, otherwise they will be tormented by this small problem

Encryption unsuccessful, need to factory reset or crash after android restarts several times

This reality has been seen in previous projects that did not have batteries, but the one that did not have a battery power outage and had data being written to EMMC, whereas reboot was supposed to shut down or pause all threads to make sure that no EMMC operation was written. Depressing.
There is no way to appear, it appears, take a look at what Android Reboot does, baidu, there are a lot of, post the process out:

framework 
./base/core/java/com/android/internal/app/ShutdownThread.java
/**
     * Do not call this directly. Use {@link #reboot(Context, String, boolean)}
     * or {@link #shutdown(Context, boolean)} instead.
     *
     * @param reboot true to reboot or false to shutdown
     * @param reason reason for reboot
     */
    public static void rebootOrShutdown(boolean reboot, String reason) {
        if (reboot) {
            Log.i(TAG, "Rebooting, reason: " + reason);
            try {
                Power.reboot(reason);
            } catch (Exception e) {
                Log.e(TAG, "Reboot failed, will attempt shutdown instead", e);
            }
        } else if (SHUTDOWN_VIBRATE_MS > 0) {
            // vibrate before shutting down
            Vibrator vibrator = new Vibrator();
            try {
                vibrator.vibrate(SHUTDOWN_VIBRATE_MS);
            } catch (Exception e) {
                // Failure to vibrate shouldn't interrupt shutdown.  Just log it.
                Log.w(TAG, "Failed to vibrate during shutdown.", e);
            }

            // vibrator is asynchronous so we need to wait to avoid shutting down too soon.
            try {
                Thread.sleep(SHUTDOWN_VIBRATE_MS);
            } catch (InterruptedException unused) {
            }
        }

        // Shutdown power
        Log.i(TAG, "Performing low-level shutdown...");
        Power.shutdown();
    }




./base/core/jni/android_os_Power.cpp 
static void android_os_Power_shutdown(JNIEnv *env, jobject clazz)
{
    android_reboot(ANDROID_RB_POWEROFF, 0, 0);
}

extern int go_recovery(void);

static void android_os_Power_reboot(JNIEnv *env, jobject clazz, jstring reason)
{
    if (reason == NULL) {
        android_reboot(ANDROID_RB_RESTART, 0, 0);
    } else {
        const char *chars = env->GetStringUTFChars(reason, NULL);
        //android_reboot(ANDROID_RB_RESTART2, 0, (char *) chars);
        go_recovery();
        android_reboot(ANDROID_RB_RESTART, 0, 0);
        env->ReleaseStringUTFChars(reason, chars);  // In case it fails.
    }
    jniThrowIOException(env, errno);
}

ANDOID_ROOT\system\core\libcutils\android_reboot.c
int android_reboot(int cmd, int flags, char *arg)
{
    int ret;

    if (!(flags & ANDROID_RB_FLAG_NO_SYNC))
        sync();

    if (!(flags & ANDROID_RB_FLAG_NO_REMOUNT_RO))
        remount_ro();

    switch (cmd) {
        case ANDROID_RB_RESTART:
            ret = reboot(RB_AUTOBOOT);
            break;

        case ANDROID_RB_POWEROFF:
            ret = reboot(RB_POWER_OFF);
            break;

        case ANDROID_RB_RESTART2:
            ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
                           LINUX_REBOOT_CMD_RESTART2, arg);
            break;

        default:
            ret = -1;
    }

    return ret;
}

android4.0/frameworks/base/core/jni/misc_rw.cpp
/* force the next boot to recovery */
int go_recovery(void){
	
	LOGE("go_recovery  =================\n");
	struct bootloader_message boot, temp;

	memset(&boot, 0, sizeof(boot));
	strcpy(boot.command, "boot-recovery");
	if (set_bootloader_message_block(&boot, MISC_DEVICE) )
		return -1;

	//read for compare
	memset(&temp, 0, sizeof(temp));
	if (get_bootloader_message_block(&temp, MISC_DEVICE))
		return -1;

	if( memcmp(&boot, &temp, sizeof(boot)) )
		return -1;
	LOGE("go_recovery  ++++++++++++++++++++++\n");
	return 0;

}

as you can see from above, the system is mount readonly before reboot:

  remount_ro();

So why is there a problem?The problem seems to be remount_ro(); The inside. Look at the code inside

static void remount_ro(void)
{
    int fd, cnt = 0;

    /* Trigger the remount of the filesystems as read-only,
     * which also marks them clean.
     */
    fd = open("/proc/sysrq-trigger", O_WRONLY);
    if (fd < 0) {
        return;
    }
    write(fd, "u", 1);
    close(fd);


    /* Now poll /proc/mounts till it's done */
    while (!remount_ro_done() && (cnt < 50)) {
        usleep(100000);
        cnt++;
    }

    return;
}

 

/proc/sysrq-trigger

This is a read-only node that can restart the system, remount, and so on, but it’s asynchronous, so there’s a check and wait, it’s probably not long enough to wait (5S), let’s try it out for a minute.

How to launch powershell script in C#

If you want to start a powershell script in a CSharp application, you don’t have to construct a cmd command line to start the script.

You can use the following example to make your life easier:

The variable “script” is the full path to the powershell script.
The variable “parameters” is an instance of an IDictionary type, which contains a set of parameter keys/values.

            using (var powerShellInstance = PowerShell.Create())
            {
                //Prepare powershell execution
                powerShellInstance.AddCommand(script);
                powerShellInstance.AddParameters(parameters);

                //Execute powershell command and get the results
                var results = powerShellInstance.Invoke();

                var errors = powerShellInstance.Streams.Error;
                var sb = new StringBuilder();

                if (errors.Count > 0)
                {
                    foreach (var error in errors)
                    {
                        sb.Append(error);
                    }
                    errorResult = sb.ToString();
                }
                else
                {
                    foreach (var result in results)
                    {
                        sb.AppendLine(result.ToString());
                    }
                    executionResult = sb.ToString();
                }

                return errors.Count == 0;
            }

Update:2015-07-01
I’m having a problem executing a powershell script in the logon server.
Actually, the application uses a system account to execute the powershell script.
But the account does not have enough privileges to run the script.

The exception is:PSSecurityException
Here are the details of the error:

Message: AuthorizationManager check failed.
InnerException stack trace:    
at System.Management.Automation.AuthorizationManager.ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host)
InnerException: A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. Do you want to run xxx.ps1?

I searched the internet for information. It is so important to repeat the same mistakes! First, I copied the service account into the integrated environment by removing it from the “Administrators” group.
You can go to the “Local Users and Groups”, then “Groups”, then “Administrators” group. Select the service account and delete it from the group. Well, I found that the problem is related to the enforcement policy on the server. I’ve tested it with the enforcement policy.
You can use open powershell.exe on the server.
Execute the command:

Get-ExecutionPolicy

You can even verify that a particular user is enforcing the policy.
You will need to open powershell.exe from your service account to run it.
Then execute the command:

Get-ExecutionPolicy -Scope:CurrentUser

 

In my server, the enforcement policy is set to unlimited in the LocalMachine range.

There are 7 enforcement policies in total.
Default:This is equal to Restricted
Restricted: Do not load configuration files or run scripts. This is the default.
AllSigned: Requires all scripts and configuration files to be signed by a trusted publisher, including scripts written on your local machine.
remotesizable: Requires all scripts and configuration files downloaded from the Internet to be signed by a trusted publisher.
unrestricted:Load all configuration files and run all scripts. If you run an unsigned script downloaded from the internet, you will be prompted for permission before running the script.
Bypass: No blocking, warnings or prompts.
Undefined:Deletes the currently assigned enforcement policy from the current scope. This parameter does not delete enforcement policies set within the Group Policy range.

0 has 5 ranges:
Process
CurrentUser
LocalMachine
UserPolicy
MachinePolicy

0 is actually the enforcement policy preventing the service account from running the script correctly. So I need to change the enforcement policy. In the end, the bypass method meets my needs. But I don’t apply this enforcement policy to all types of users within the local machine. So I only apply the bypass enforcement policy to the service account.

The commands used are:

Set-ExecutionPolicy -Scope:CurrentUser -ExecutionPolicy:Bypass

cv2.imread() error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow’

error: (-215:Assertion failed) size.width> 0 & & size.height> 0 in function ‘CV ::imshow’

Solution:
change the name and path of the picture to English or number

window name should also be set to English or number, otherwise it will show the code
from the code of https://www.zhihu.com/question/67157462/answer/251754530
Chinese path can be read normal, but still have window name Chinese garbled.

update: fix window name mess
change system Settings, check the system default code under the CMD window to enter CHCP. If the system encoding is UTF-8, output 65001, modify the language setting to UTF-8, and operate as follows:

red envelope + discount, ali cloud on cloud gift package!
https://promotion.aliyun.com/ntms/yunparter/invite.html?UserCode = 5 wzgtzow
“universal cloud computing” cloud host as low as 4
https://promotion.aliyun.com/ntms/act/qwbk.html?UserCode = 5 wzgtzow
cloud communication exclusive ali cloud new users 】 【 8 fold the
https://www.aliyun.com/acts/alicomcloud/new-discount?UserCode =5wzgtzow
[trademark registration service] as low as 680
https://tm.aliyun.com/?userCode=5wzgtzow