Category Archives: How to Fix

pg_ctl: no database directory specified and environment variable PGDATA unset , centos 7 postgreSQL

centos 7 postgreSQL pg_ CTL invalid

In the
section

~/.bash_profile

Next configuration

export PGDATA=/var/lib/pgsql/11.0/data 

But it didn’t work.

However, it can be written like this

Go to

/usr/pgsql/bin

After that, it can be executed

./pg_ctl -D /var/lib/pgsql/11.0/data start

Take notes

Solve the problem of flag error valueerror: View function did not return a response

Today, we use Python to implement the restful interface of Flask, and then call it wrong.

ValueError: View function did not return a response

The code is as follows:

@app.route('/xxxx/yyyy_zzzzz', methods=['POST', 'GET'])

def receive():

      param = request.json

      print(param)

The reason for the error is that the restful interface of flag must have a return value.

Therefore, modify the code to add the return value:

Add: return XXXX

For example:

@app.route('/xxxx/yyyy_zzzzz', methods=['POST', 'GET'])

def receive():

    try:

        if not request.json:

            return jsonify({'code': -1, 'message': 'request is not json'})

        param = request.json

        return jsonify({'code': 0, 'status': 'running'})

    except Exception as e:

        print(e)

        return jsonify({'code': -1, 'error_message':e})

 

Error: transfer of control bypasses initialization of: variable XXX solution

Error: transfer of control bypasses initialization of: variable XXX

The nature of the problem, causes and Solutions

The nature of the problem

The code may skip the initialization of some variables, which makes the program access the uninitialized variables and crash.

Causes

I encountered this problem when porting the code from the vs compiling environment of windows to the G + + of Linux (actually compiling CUDA C + + code with nvcc, but the nvcc background also calls G + + to compile C / C + + part of the code). Later, it was found that in vs environment, it was just a warning, but in G + +, it was an error, so this problem must be solved.

terms of settlement

    whether the variables in the analysis code are initialized, whether the variables are declared after the goto statement in the analysis code, and if so, move the variable declaration to the front of goto .
// error
goto SomeWhere;
int var = 10;
// right
int ver = 10;
goto SomeWhere;
    analyze whether or switch statements appear in the code, because switch statements are essentially implemented with goto , so the above problems may also exist. In addition to reference 2, write the variable declaration before switch, add curly brackets to each branch of switch , or change the switch statement to if / else .
// error
switch (choice)
{
    case 1:
        // do something
        break;
    case 2: 
        // do something
}
// right
switch (choice)
{
    case 1:
    {
        // do something
        break;
    }
    case 2: 
    {
        // do something
    }
}
// or
if(choice == 1)
{
	// do something
}
else if(choice == 2)
{
	// do something
}

[Two Sigma OA] Longest Chain

Title:

http://www.1point3acres.com/bbs/thread-131978-1-1.html

realization:

import java.util.*;

/**
 * Created by Min on 10/2/2017.
 */
public class LongestChain {
    private int getLongestChain(String[] words) {
        Map<Integer, Set<String>> map = new HashMap<Integer, Set<String>>();
        for (String word : words) {
            Set<String> set = map.get(word.length());
            if (set == null) {
                set = new HashSet<String>();
                map.put(word.length(), set);
            }
            set.add(word);
        }
        int ans = 0;
        List<Integer> lengthList = new ArrayList<Integer>(map.keySet());
        Collections.sort(lengthList, Collections.reverseOrder());
        return helper(0, lengthList, map, "");
    }
    private int helper(int start, List<Integer> list, Map<Integer, Set<String>> map, String prev) {
        if (start == list.size()) {
            return 0;
        }
        int ans = 0;
        if (start == 0) {
            for (String word : map.get(list.get(0))) {
                ans = Math.max(ans, helper(start + 1, list, map, word) + 1);
            }
        } else if (prev.length() -1 == list.get(start)) {
            Set<String> wordSet = map.get(list.get(start));
            for (int i = 0; i < prev.length(); i++) {
                String newWord = prev.substring(0, i) + prev.substring(i + 1);
                if (wordSet.contains(newWord)) {
                    wordSet.remove(newWord);
                    ans = Math.max(ans, helper(start + 1, list, map, newWord) + 1);
                }
            }
        }
        return ans;
    }
    public static void main(String[] args) {
        String[] input = {"a","ba","bca","bda","bdca"};
        LongestChain solution = new LongestChain();
        System.out.println(solution.getLongestChain(input));
    }

}

[UNK]

import java.util.*;

/**
 * Created by Min on 10/2/2017.
 */
public class LongestChain2 {
    public int getLongestChain(String[] words) {
        Set<String> set = new HashSet<String>();
        for (String word : words) {
            set.add(word);
        }
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        int ans = 0;
        for (String word : words) {
            Integer length =map.get(word);
            if (length == null) {
                length = dfs(word, map, set);
            }
            ans = Math.max(ans, length);
        }
        return ans;
    }

    private int dfs(String word, Map<String, Integer> map, Set<String> set) {
        Integer ans = map.get(word);
        if (ans != null) {
            return ans.intValue();
        }
        ans = 0;
        for (int i = 0; i < word.length(); i++) {
            String newWord = word.substring(0, i) + word.substring(i + 1);
            ans = Math.max(ans, dfs(newWord, map, set) + 1);
        }
        map.put(word, ans);
        return ans.intValue();
    }
    public static void main(String[] args) {
        String[] input = {"a","ba","bca","bda","bdca"};
        LongestChain2 solution = new LongestChain2();
        System.out.println(solution.getLongestChain(input));
    }
}

 

Reproduced in: https://www.cnblogs.com/Gryffin/p/7623249.html

Kafka prompts no brokers found when trying to rebalance

Kafka prompts when executing the following command:

bin/kafka-console-consumer.sh --zookeeper localhost102:2181 --topic test

WARN [console-consumer-87796_ localhost002-1592779486563-9b43649b], no brokers found when trying to rebalance.( kafka.consumer.ZookeeperConsumerConnector )

The reason is that the Kafka process is not started or there is no Kafka cluster information on zookeeper

[root@localhost002 ~]# jps
3667 DataNode
3365 ResourceManager
21446 QuorumPeerMain
23386 Jps
3230 NodeManager

Solve the problem after starting Kafka

String operation to delete the character at the specified position

Using iterator and erase

Here, we use a function erase (iterator) of string to delete the characters at the specified position. The iterator iterator can string.begin () get the first iterator of the string, and then add different values to delete it.

	string s = "abcdefg";
	int i = 3;
	string::iterator itr = s.begin();
	itr+=i;
	s.erase(itr);
	s.erase(itr);
	cout<<s;

Here we want to delete “de”. Because we get the first iterator and add the value, we delete “d”. If we want to delete “e”, we don’t need to add any value, because the position of “e” is just “d”, so we just need to erase () again.

main.cpp : (. Text + 0xd06): undefined reference to XX method | simple record

This blog post is just a record of C + + compilation and installation problems – it doesn’t give the correct solution

main.cpp:(.text+0xd06): undefined reference to `uni_text::UniText::UniText(std::string const&, int)'
main.cpp:(.text+0xe73): undefined reference to `uni_text::UniText::PutText(cv::Mat&, std::string const&, cv::Point_<int> const&, cv::Scalar_<double> const&, bool)'

Analysis:
encounter this problem: run some C + + projects that contain special so dynamic library or static library;
the compiled versions of GCC and G + + used by the native environment are not completely consistent with the libraries (dynamic library or static library) compiled by the author, resulting in these errors

1: There is no corresponding dependency (static library or dynamic library). 2: the compiled versions of some static libraries or dynamic libraries in the project are inconsistent

Solutions:

In the final analysis, it’s an environmental issue: GCC, G + + version matching or the supplement of third-party dependency


The node rimraf module recursively deletes the contents of the folder

When using the webpack build file project, a dist directory is generated every time. Sometimes, all the old files in the dist directory need to be deleted,

In addition to the RM – RF / dist / command, you can also use the rimraf / dist / command

The function of rimraf is to package the RM - RF command in the form of package to delete files and folders, regardless of whether the folder is empty or not

Local installation: NPM install rimraf — save dev

Global installation: NPM install rimraf – G

Use: rimraf & lt; path & gt; [& lt; path & gt;…]

api:rimraf(f, [opts], callback)

Nginx reverse proxy report 400 error solution!

upstream tomcat_ server { 
        server localhost:8090;
    }

server {
     listen 80;
     server_ name localhost;
    charset utf-8;
    access_ log logs/ host.access.log main;

location / {
    proxy_ pass http://tomcat_ server
    proxy_ set_ header Host $http_ Host; / / to add a host header here, return the header information to the server
}