Category Archives: How to Fix

Display spaces and tab symbols in vscode

one of the most annoying aspects of python is code alignment, and tabs and Spaces are not the same, so you want to display them for ease of reference. Baidu online a solution, and I am not exactly the same, but still solved.
– extensive chemical and

  • open setting, enter renderControlCharacters in the search box, and select the check box to display TAB.

    2. Enter renderWhitespace in the search box and select all to display the space.
  • baidu to solution: https://www.jianshu.com/p/e9ee1de056b2

    About Java File.separator

    in Windows path separator and Linux path separator is different, when the absolute path is used directly, cross-platform will be exposed “No such file or diretory” exception.

    File
    File file1 = new File (“C:\ TMP \test.txt”);
    File file1 = new File (“C:\ TMP \test.txt”)

    File file2 = new File (“/ TMP /test.txt”);
    File file2 = new File (“/ TMP /test.txt”);

    if cross-platform is considered, it is best to say:
    File myFile = new File(“C:” + file.separator + “TMP” + file.separator, “test.txt”);
    File myFile = new File(“C:” + file.separator + “TMP” + file.separator, “test.txt”);

    The

    File class has several static fields that are similar to separator, which are system related and should be used as far as possible in programming.

    separatorChar

    public static final char separatorChar

    is the default name separator associated with the system. This field is initialized to the first character that contains the system property file.separator value. On UNIX systems, the value of this field is ‘/’; On Microsoft Windows, it is ‘\’.

    separator

    public static final String separator

    is the system-specific default name separator, which is represented as a string for convenience. This string contains only one character, separatorChar.

    pathSeparatorChar

    public static final char pathSeparatorChar

    is the system-dependent path separator. This field is initialized as the first character that contains the system property path.separator value. This character is used to separate filenames in a given file sequence in the form of a path list. On UNIX systems, this field is ‘:’; On Microsoft Windows, it is ‘; ‘.

    pathSeparator

    public static final String pathSeparator

    is the system-dependent path separator, which is represented as a string for convenience. This string contains only one character, pathSeparatorChar.

    ☞ warm prompt: to return to my blog index

    Tensorflow with tf.Session The usage of () as sess

    The

    Session provides the environment for Operation execution and Tensor evaluation. As shown below,

    import tensorflow as tf
    
    # Build a graph.
    a = tf.constant([1.0, 2.0])
    b = tf.constant([3.0, 4.0])
    c = a * b
    
    # Launch the graph in a session.
    sess = tf.Session()
    
    # Evaluate the tensor 'c'.
    print sess.run(c)
    sess.close()
    
    # result: [3., 8.]

    a Session might have some resources, such as Variable or Queue. When the session is no longer needed, these resources need to be released. There are two ways to do it,

    1. calls session.close() method;

    2. USES with tf.session () to create the Context (Context) for execution, which is automatically released when the Context exits.

    import tensorflow as tf
    
    # Build a graph.
    a = tf.constant([1.0, 2.0])
    b = tf.constant([3.0, 4.0])
    c = a * b
    
    with tf.Session() as sess:
        print sess.run(c)


    https://www.cnblogs.com/lienhua34/p/5998853.html


    https://blog.csdn.net/qq_36666115/article/details/80017050


    Python common error: if using all scalar values, you must pass an index (four solutions)

    (author: Chen’s freebies)

    1, error scenario:

    import pandas as pd
    dict = {'a':1,'b':2,'c':3}
    data = pd.DataFrame(dict)

    2, error reason:

    The dictionary

    is passed in directly with the nominal attribute value and index is required, that is, index is set when the DataFrame object is created.

    3, solution:

    Creating DataFrame objects with a

    dictionary is a common requirement, but it can be written differently depending on the object form. Look at the code, the following four methods can correct this error, and produce the same correct results, which method to use according to your own needs.

    import pandas as pd
    
    #方法一:直接在创建DataFrame时设置index即可
    dict = {'a':1,'b':2,'c':3}
    data = pd.DataFrame(dict,index=[0])
    print(data)
    
    #方法二:通过from_dict函数将value为标称变量的字典转换为DataFrame对象
    dict = {'a':1,'b':2,'c':3}
    pd.DataFrame.from_dict(dict,orient='index').T
    print(data)
    
    #方法三:输入字典时不要让Value为标称属性,把Value转换为list对象再传入即可
    dict = {'a':[1],'b':[2],'c':[3]}
    data = pd.DataFrame(dict)
    print(data)
    
    #方法四:直接将key和value取出来,都转换成list对象
    dict = {'a':1,'b':2,'c':3}
    pd.DataFrame(list(dict.items()))
    print(data)

    The difference between sleep() and wait() in Java

    learning just encounter these two methods, look up relevant information, and through the program to achieve, the difference:

    Each object has a lock to control access to the synchronization, and the Synchronized keyword can interact with an object’s lock to implement Synchronized methods or blocks. sleep() sleep() lock lock! ). wait () method is refers to the current thread to temporarily retreat out the synchronous resource lock, so that other threads are waiting for the resource to get the resources, in turn, to run, only calls the notify () method, before calling wait () thread will lift its state of wait, can go to participate in the competition synchronous resource locks, and enforced. ( note: notify role is equivalent to wake the sleeping man, and would not give his assigned task, that is to say notify calling wait before just let the thread has the right to participate in the thread scheduling ).

    2, sleep() can be used anywhere; wait() method can only be used in synchronized methods or synchronized blocks;

    3, sleep() is the method of Thread. The call will suspend the specified time of this Thread, but the monitoring will still be maintained, and the object lock will not be released, and it will automatically recover at the time. wait() is an Object method. The call will give up the Object lock and enter the wait queue. The call notify()/notifyAll() will wake up the specified thread or all threads to enter the lock pool and run until the Object lock is acquired again.


    to procedures:

    public class MultiThread {
    
    	private static class Thread1 implements Runnable{		
    		@Override
    		public void run() {
    			//由于 Thread1和下面Thread2内部run方法要用同一对象作为监视器,如果用this则Thread1和Threa2的this不是同一对象
    			//所以用MultiThread.class这个字节码对象,当前虚拟机里引用这个变量时指向的都是同一个对象
    			synchronized(MultiThread.class){
    				System.out.println("enter thread1 ...");
    				System.out.println("thread1 is waiting");
    				
    				try{
    					//释放锁有两种方式:(1)程序自然离开监视器的范围,即离开synchronized关键字管辖的代码范围
    					//(2)在synchronized关键字管辖的代码内部调用监视器对象的wait()方法。这里使用wait方法
    					MultiThread.class.wait();
    				}catch(InterruptedException e){
    					e.printStackTrace();
    				}
    				
    				System.out.println("thread1 is going on ...");
    				System.out.println("thread1 is being over!");
    			}
    		}
    		
    	}
    	
    	private static class Thread2 implements Runnable{
    		@Override
    		public void run() {	
    			//notify方法并不释放锁,即使thread2调用了下面的sleep方法休息10ms,但thread1仍然不会执行
    			//因为thread2没有释放锁,所以Thread1得不到锁而无法执行
    			synchronized(MultiThread.class){
    				System.out.println("enter thread2 ...");
    				System.out.println("thread2 notify other thread can release wait status ...");
    				MultiThread.class.notify();
    				System.out.println("thread2 is sleeping ten millisecond ...");
    				
    				try{
    					Thread.sleep(10);
    				}catch(InterruptedException e){
    					e.printStackTrace();
    				}
    				
    				System.out.println("thread2 is going on ...");
    				System.out.println("thread2 is being over!");
    			}
    		}		
    	}
    	
    	public static void main(String[] args) {
    		new Thread(new Thread1()).start();
    		try{
    			Thread.sleep(10);
    		}catch(InterruptedException e){
    			e.printStackTrace();
    		}
    
    		new Thread(new Thread2()).start();
    	}
    
    }
    

    program results as shown in the figure below

    [latex] latex adjust row spacing

    we usually use two kinds of units to adjust the line spacing in word, one is single spacing , 1.5 times spacing, 2 times spacing, etc., and the other is USES “pounds” for setting, I generally do not like to use single spacing when writing documents, I think the 22 pound spacing is the most appropriate, looks the most comfortable.

    today when I was editing my paper with latex, I wanted to adjust the line spacing in the LLNCS template, so I summarized both approaches, but before I could use them, I had to introduce the package file: \usepackage{setspace} :

    1) \ renewcommand {\ baselinestretch} {1.0}

    can be understood as what I just used in word, one is to adjust the single spacing, 1.5 times the spacing, 2 times the spacing, etc..

    2) \ setlength {\ baselineskip} {20 pt}
    First of all, we need to know several common unit conversions of LaTeX:

    We often see the units of length used by LaTeX, in, em, and so on.
    LaTeX the length of the support units are:

    • in inches (inch)
    • mm mm (millimeters)
    • cm (centimeters)
    • pt points (approximately 1/72 inch) em-
    • 0 1 ex – 2 Approximately the height of an “x” in the current font

    length can also be negative, such as 1.5 em. notice the number 0 itself is not a length, must show is 0 in or 0 pt, etc.

    and “pounds” is a measure of the size of a print, which is about one seventy-two inches. While 1 inch = 25.4 mm, 1 pound = 25.4/72≈0.353 mm. The pounds agree with LaTeX’s Pt-points (about 1/72 inch).

    so this can be roughly equal to the “pounds” in wor units.


    Python’s importerror: DLL load failed: the specified module was not found and the problem was solved

    environment description

    Window 7, Python 3.6.5

    problem description

    , while importing based on python, reports the following error:

    >> from PIL import Image
    Traceback (most recent call last):
      File "<ipython-input-12-0f6709e38f49>", line 1, in <module>
        from PIL import Image
    
      File "d:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py", line 58, in <module>
        from . import _imaging as core
    
    ImportError: DLL load failed: 找不到指定的模块。

    sometimes, a similar error is reported:

    >> from PIL import Image
    Traceback (most recent call last):
    
      File "<ipython-input-13-0f6709e38f49>", line 1, in <module>
        from PIL import Image
    
    ImportError: cannot import name 'Image'

    problem analysis

    such problems are generally when installing the library, the security is not complete, or the installed library is overwritten or broken, so the corresponding class library cannot be known.

    problem solved

    C:\Users\xxxx\>pip install Pillow
    Requirement already satisfied: Pillow in d:\programdata\anaconda3\lib\site-packages (5.0.0)
    
    
    C:\Users\xxxx>pip show Pillow
    Name: Pillow
    Version: 5.2.0
    Summary: Python Imaging Library (Fork)
    Home-page: http://python-pillow.org
    Author: Alex Clark (Fork Author)
    Author-email: [email protected]
    License: Standard PIL License
    Location: d:\programdata\anaconda3\lib\site-packages
    Requires:
    Required-by:

    as you can see from the instructions above, the class library is already installed. But because it has a problem, it needs to be reinstalled.
    uninstalls

    first

    pip uninstall Pillow

    Uninstalling Pillow-5.0.0:
      Would remove:
        d:\programdata\anaconda3\lib\site-packages\pillow-5.0.0.dist-info\*
    Proceed (y/n)?y
      Successfully uninstalled Pillow-5.0.0

    and then reinstall :

    pip install Pillow

    Collecting Pillow
      Downloading https://files.pythonhosted.org/packages/1b/50/869910cd7110157fbefd0fed3db3656c1951f1bceecdd00e3716aa269609/Pillow-5.2.0-cp36-cp36m-win_amd64.whl (1.6MB)
        100% |████████████████████████████████| 1.6MB 69kB/s
    Installing collected packages: Pillow
    Successfully installed Pillow-5.2.0

    validation

    and then re-import the Image to see that everything is fine.

    summary

    if it has been installed but cannot be found, the high probability is that the installation is damaged and needs to be reinstalled.

    Summary of three methods for pandas to convert dict into dataframe

    enter: my_dict = {‘ I ‘: 1, ‘love’: 2, ‘you’: 3}

    expected output: my_df

          0
    i     1
    love  2
    you   3

    If the key and value in the dictionary are one-to-one, then directly entering my_df = pd.DataFrame(my_dict) will give an error “ValueError: If using all scalar values, you must pass an index”.

    solution:

    1, use DataFrame to specify the dictionary index index

    import pandas as pd
    
    my_dict = {'i': 1, 'love': 2, 'you': 3}
    my_df = pd.DataFrame(my_dict,index=[0]).T
    
    print(my_df)
    

    2. DataFrame

    import pandas as pd
    
    my_dict = {'i': 1, 'love': 2, 'you': 3}
    my_list = [my_dict]
    my_df = pd.DataFrame(my_list).T
    
    print(my_df)
    

    3, DataFrame. From_dict

    specific parameters can refer to the website: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.from_dict.html

    import pandas as pd
    
    my_dict = {'i': 1, 'love': 2, 'you': 3}
    my_df = pd.DataFrame.from_dict(my_dict, orient='index')
    
    print(my_df)

    output

          0
    i     1
    love  2
    you   3

    Java – read all the files and folders in a certain directory and three methods to get the file name from the file path

    1 reads all files and folders in a directory

    public static ArrayList<String> getFiles(String path) {
        ArrayList<String> files = new ArrayList<String>();
        File file = new File(path);
        File[] tempList = file.listFiles();
    
        for (int i = 0; i < tempList.length; i++) {
            if (tempList[i].isFile()) {
    //              System.out.println("文     件:" + tempList[i]);
                files.add(tempList[i].toString());
            }
            if (tempList[i].isDirectory()) {
    //              System.out.println("文件夹:" + tempList[i]);
            }
        }
        return files;
    }

    2 3 ways to get the file name from the file path

    package test;
    
    import java.io.File;
    
    public class FileName {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
    //      举例:
            String fName =" G:\\Java_Source\\navigation_tigra_menu\\demo1\\img\\lev1_arrow.gif ";
    
    //      方法一:
    
            File tempFile =new File( fName.trim());
    
            String fileName = tempFile.getName();
    
            System.out.println("fileName = " + fileName);
    
    //      方法二:
    
            String fName = fName.trim();
    
            String fileName = fName.substring(fName.lastIndexOf("/")+1);
            //或者
            String fileName = fName.substring(fName.lastIndexOf("\\")+1);
    
            System.out.println("fileName = " + fileName);
    
    //      方法三:
    
            String fName = fName.trim();
    
            String temp[] = fName.split("\\\\"); /**split里面必须是正则表达式,"\\"的作用是对字符串转义*/
    
            String fileName = temp[temp.length-1];
            System.out.println("fileName = " + fileName);
        }
    }

    Ubuntu add apt repository command not found solution

    Launchpad PPA Repositories is a useful non-ubuntu personal third-party repository that can be easily installed with third-party software.

    However, when running the Apt-Repository command, it is sometimes suggested that the command does not exist. In this case, apt-get Add-apt-Repository is not possible!

    The solution is to install Software-Properties-common. Input command:

    apt-get install software-properties-common

    MySQL creates tables and sets auto increment of primary keys

    mysql创建表:

    mysql>创建表用户(
    ->userid int(4)主键not null auto_increment,
    ->用户名varchar(16)不为空,
    ->userpassword varchar(32) not null
    -&gt

    创建表log(
    logid int(4) primary key not null auto_increment,
    logtitle varchar(32) not null,
    logcontent varchar(160) not null,
    logtime datetime not null,
    userip varchar(64) not null
    )