Author Archives: Robins

Django. Using f () to solve the competition problem

What are the competition issues:
When multiple users operate on a field at the same time, there is no expected return.
F () function:

from django.db.models import F

def vote(request, choice_id):
    selected_choice = question.choice_set.get(pk=request.POST['choice'])
    selected_choice.votes = F('votes') + 1
    selected_choice.save()

 

Solution in idea java.lang.ClassNotFoundException : org.springframework.web . context.ContextLoaderListener

Reference blog: IDEA development in Java. Lang. ClassNotFoundException: org. Springframework. Web. Context. The ContextLoaderListener error solution


Have a problem
In the process of writing a simple SpringMVC project, I tried to start the project with Tomcat, but found the following errors:

java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener

Simply put, the ContextLoaderListener class cannot be found. The strange thing about
is that the SpringMVC project that I wrote before doesn’t have similar problems. ┍ ┑ ( ̄ Д  ̄)


The solution
After asking baidu, I was told to add Available Elements to the Artifact.
click File - & gt; Project Structure-> Artifacts, right-click the project name in Available Elements, and select Put into Output Root.

Then restart Tomcat, you will be able to access the page correctly! O (≧ ヾ del ≦ *)

Vue refreshes the current page (no flash screen will appear)

Vue refreshes the current page (no flash)
No splash screen appears when vUE refreshes the current page

parent-child component values can also be passed after the parent component completes all operations without having to go to the child component </h6 b> 1. Add the v-if attribute

to app.vue

<router-view v-if="isRouterAlive"></router-view>
2. Add isRouterAlive in the data, of course, this property name can be defined by itself, the default value is true
data () {
      return {
        isRouterAlive: true
      }
  }
3. Methods add a refresh method
methods: {
  reload () {
    this.isRouterAlive = false
    this.$nextTick(function() {
       this.isRouterAlive = true
    })
  }
}

4. Finally, we need to provide this function (the same as data) </h6 b>

provide () {
  return {
    reload: this.reload
  }
}

So, that’s all set up on app.vue,
and then when we need to refresh, we just add this function to the page that we need

5. First inject this function
inject: ['reload'] (same to data)
6. Then refer to it where you need this function
refresh () {
this.reload()
}

This will refresh the page without the white screen

Tkmybatis uses Example.SetOrderByClause Use for sorting and multiple sort fields

How to use it when sorting individual fields

example.setOrderByClause("user_type ASC"); //Output sorted by user type in ascending order

Running SQL looks something like this

SELECT ...
FROM tab_sy_user
order by user_type ASC 

The method of using when sorting multiple fields separated by a comma

The query results are sorted by the order in which the fields are sorted, and if the conditions are the same, continue the conditional sort by the next field until the last field sort is complete.

 //First according to user_type ascending ASC sorting, if there is the same condition, in accordance with the level condition descending DESC sorting
example.setOrderByClause("user_type ASC, level DESC");

Running SQL looks something like this

SELECT ...
FROM tab_sy_user
order by user_type ASC, level DESC

Solution to the problem that listen TCP 0.0.0.0:3306: bind: address already in use port is occupied in Linux centos7

Problem description:
When installing the mysql container running docker in the host environment, the port is occupied

Reason analysis:
The port is occupied and cannot bind the address
Solutions:
netstat -nap look for port 3306 look at the pid that the program is running and find that it is actually occupied, remember the pid
netstat -nap | grep 3306

kill the process, here is kill 1107

Get the startup activity of Android apk

Get the Start Activity for Android APK

adb connect phone open APP

adb -s 192.168.0.11:6688 shell dumpsys window Windows | grep “mCurrent” # gets the package name of the current APP

adb shell dumpsys activity > Act.txt # gets the activity information
# on the act. TXT find android. Intent. The category. The LAUNCHER behind the name of the activity is to start the activity
Adb -s 192.168.0.11:6688 shell am start – n com. Dragon. Read/pages. Splash. SplashActivity #

Python rename renumber

 

# -*- coding: utf-8 -*-
import os
import numpy as np
import cv2

list_path = r"F:\project\cls\yanshen\20201209/"
g = os.walk(list_path)

test_dataset = ['%s/%s' % (i[0], j) for i in g for j in i[-1]]


for index,filename in enumerate(test_dataset):

    name = f'/{index:04d}.jpg'
    dir_name=os.path.dirname(filename)
    os.rename(filename,dir_name+name)

Filter images:

  g = os.walk(list_path)
        img_files = ['%s\\%s' % (i[0], j) for i in g if i[0].endswith('JPEGImages') for j in i[-1] if
                     j.endswith('jpg')]

 

Homebrew installation strategy of M1 MAC based on ARM architecture

M1 Mac installs Homebrew
Mainly refer to the use of installation process

Main reference

https://sspai.com/post/63935
https://github.com/mikelxc/Workarounds-for-ARM-mac

Main strategy: Install ARM version and X86 version of Homebrew respectively, and in.zshrc through alias name, respectively, to achieve coexistence and specify calls.
The installation process
First install M1 version of BREW, there is no official installation script.

Can focus on website https://brew.sh/
and M1 version homebrew problem summary posted at https://github.com/Homebrew/brew/issues/7857

cd /opt # Switch to the /opt directory
mkdir homebrew # Create the homebrew directory
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew

Then write the environment variable of ZSH (assuming ZSH is used)

vim ~/.zshrc

#Write at the beginning
export PATH="/opt/homebrew/bin:$PATH"

Vim basic operation:

    i——insert:w——write(save):q——quit

Install an x86 version of HomeBrew for later use

#Open a new page of zsh
arch -x86_64 $SHELL

#homebrew official install script
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Write environment variables

vim ~/.zshrc

#Write after
export PATH="/usr/local/bin:$PATH"

Let the two coexist with Alias

vim ~/.zshrc

#Write after
alias abrew='/opt/homebrew/bin/brew' # ARM Homebrew
alias ibrew='arch -x86_64 /usr/local/bin/brew' # X86 Homebrew

usage
In ZSH, input such as “Abrew List” to call ARM BREW under OPT and input “iBREW List” to call X86 BREW under USR /local. The PATH of ARM BREW is in front, so the input of “BREW List” calls ARM BREW by default. When there is a package with the same name in the two BREWS, the default priority is to call ARM BREW under the bin.

Python ProgressBar adds its own dynamic information to the progress bar

Python progressbar adds its own dynamic information to the progressbar (prevent visuals)

import progressbar
import time
widgets = ['Progress:', 
                   progressbar.Percentage(), ' ', 
                   progressbar.Bar('='),' ', 
                   progressbar.Timer(), ' ',
                   progressbar.DynamicMessage("training_batch_acc"),
                  ]
bar=progressbar.ProgressBar(widgets=widgets, max_value=1000)
for i in range(1000):
    time.sleep(1)
    bar.dynamic_messages.training_batch_acc = 10
    bar.update(i)

Dynamic information added by training_batch_ACC in the code, variable is set by Widgets, dynamic_messages.training_batch_ACC modify value, which can be displayed dynamically in real time, concise and clear

Set the cursor of Ubuntu terminal to turn on automatic display

directory
Terminal cursor disappearance causes echo and hide cursor methods boot automatic echo cursor summary

The reason the terminal cursor disappears
When I was using the Ubuntu subsystem terminal, the cursor would often disappear after a single action. Now I suddenly found the reason for the switch between Chinese and English input. When I just entered the terminal, because it was Chinese input, I did not pay attention to typing a few words, so I switched to English with shift casually, and then the cursor disappeared. If you want to retrieve the cursor, press shift to switch the input method to see the cursor.
Echo and hide cursor methods

# Hide the cursor
echo -e "\033[?25l"

# Show cursor
echo -e "\033[?25h"

Power on auto echo cursor
I mainly encountered the following problems in the process of using the Ubuntu subsystem. Although the above command can be normally displayed back to the cursor each time, once the terminal is closed, the cursor is not opened again, so I need to continue typing the above command, but it is very troublesome to go one after another, so I have the following solution ideas.
write shell script, named cursor_show.sh :

#!/bin/bash

echo -e "\033[?25h"

Set automatic startup execution, /etc/init.d/ directory is stored in the program of automatic startup execution:

>$ chmod +x cursor_show.sh
>$ sudo mv cursor_show.sh /etc/init.d/cursor_show.sh

conclusion
This is my personal solution to the ubuntu subsystem, but if you have the same problem on other Linux systems, try it.

Memory configuration of BIOS combat

At present, there are two kinds of SMIP and SPD, and now SMIP, soft: BMP, SMIP and SMIP are mainly configured. Relevant document SMIP.c that needs to be modified
BGA: SMT, Dimm: slot, MemoryDown: SMT must be used:

 
ch0 RankEnable–> Ch0 options, these options are configured according to Memory Spec and Gen, where Ch0_RankEnable:only for Memorydown relates to CS and channel
RMT mode runs edge check mode, which is likely to be a circuit problem if there is a problem. This function is opened for hardware Debug. In the macro definition, the value of Set is unchanged, and the value of option is 0 or 1
Additions, deletions and modifications of smip.c :(to be determined)
DQ Mapping for CHO to CH3:
The ch0 and ch2 corresponding to bit0~31 are DQ 8~15,0~7,24~31,16~23
The ch1 and CH3 corresponding to BIT0 ~31 are DQ 0~31
In addition, some basic information about the project.h file is collected in the project.h file. There are many sub-options in the main option in the setup interface, including BIOS vendor, BIOS Version, build time and other relevant information. However, this project.h file is generated after the build.

 
#ifdef CONFIG_ODM_PROJECT_ID
Status = GetMemSkuId (& MemSkuId);
if (EFI_ERROR (Status)) {
MemSkuId = 0x00;
}
DEBUG ((EFI_D_INFO, “=====================================================\n”));
// Bit3 Bit2========Bit1 Bit0
// ID3 ID2========ID1 ID0
//2G 0 0 Hynix—-: 0 0
//4G 1 0 Samsung-: 1 0
//8G 0 1 Micron—: 0 1
// ID4,Bit4 0 DDR3L,1 LP4
MemSkuId & =0x0F; //now only for LP4
#if (CONFIG_ODM_PROJECT_ID == 0)
MemSkuId = 0x10; //DDR3L
#endif
DEBUG ((EFI_D_INFO, “Memory ID: 0x%2X\n”, MemSkuId));
DEBUG ((EFI_D_INFO, “Memory Type: %s %s\n”,MemMfg[MemSkuId&0x03],MemSize[((MemSkuId>>2)&0x03)]));
switch ((MemSkuId> > 4)& 0x01) {
case 0://for LP4
//Bit[4,3]=00 2G(Single Channel), 10 4G(Dual Channel), 01 8G(Dual Channel),11 4G(Single Channel)
switch ((MemSkuId> > 2)& 0x03) {//Memory Size
case 0x00://2G(Single Channel)8Gb
case 0x02://4G(Dual Channel)8Gb
DramConfig = & (DramConfigData-> PlatformDram0); //8Gb Profile
DEBUG ((EFI_D_INFO, “Profile set to 0\n”));
break;
case 0x01://8G(Dual Channel)16Gb
case 0x03://4G(Single Channel)16Gb
DramConfig = & (DramConfigData-> PlatformDram1); //16Gb Profile
DEBUG ((EFI_D_INFO, “Profile set to 1\n”));
break;
}
break;
case 1://For DDR3L
DramConfig = & (DramConfigData-> PlatformDram5);
DEBUG ((EFI_D_INFO, “Profile set to 5, DDR3L\n”));
break;
}
The connections among channel, DIMM,rank, bank, CS and chip in Memory:

 
A channel corresponds to a set of memory controllers

Why namenode can’t be started and its solution

Reasons why the NameNode fails to start and solutions

Problem: After starting Hadoop, I checked with JPS and found no NameNode

The NAMenode Format creates a new NAMenodeld every time, and TMP/DFS /data contains the ID under the last format. The Namenode Format clears the data under the Namenode, but does not clean the data under the Datanode, which causes startup failure.
Solutions:

    stop running hadoop

stop -dfs.sh

    delete the file items mapped by hadoop.tmp.dir in the core-site configuration file, generally hadoop/ TMP folder

sudo rm -r tmp

    performs formatting

./bin/hdfs namenode -format

    restart

start-hdfs.sh