Author Archives: Robins

The time of the time database displayed by the front end is inconsistent

These days I have encountered a huge pit. The time of data storage is 2 o ‘clock, but the time displayed on the front page is 16 o ‘clock, which is 14 hours short.
Describe the project background, the service is in the US, the project is a Mexican project, the database time and server time have been set to the Mexican time zone, but it is still not correct.
I have asked the project boss in the middle, and the boss gave me the opinion that the time zone was set on the URL of connecting data, but the front-end page was still not displayed correctly.
After several times of locating, the time to find it directly in the dev location will change. This is because the computer’s time zone is the Chinese time zone. But the time log is still on the server, the log time is correct. So guess the front-end is the time zone problem.
Because the last segment passes the timestamp, the timestamp has no time zone. So the front end also needs to change the time zone to correspond

  id : "crete_time",
		            renderer : function(idValue,value,record){
                        return value ?moment(value).tz("America/Guatemala").format("YYYY-MM-DD HH:mm:ss") : "---";
			        }

You can set the time zone using the Moment.tz method

Generate template asp.net Cs1010: newline in constant

compiler error message: CS1010: constants of line breaks
the source error:

Solutions:
Method 1: Open the corresponding template that will prompt “inconsistent line end “, select” Yes “, save → generate
Method 2: When you have written the template, press the formatting code shortcut key Ctrl+K+D

>

ASP.NET How to deal with “unexpected character” when writing code

Compiler error message: CS1056: Handling of unexpected characters

error generated:

An “unexpected character” error occurred in C# code while compiling an ASP. NET 4.0 website using VS2010.

does not use UTF-8 format for display and save, the compiler can not correctly recognize such characters, resulting in compilation error.

:

set the file open mode of VS 2010, make it in view of the error file using utf-8 format to open. The specific operation is as follows:

1) In Solution Explorer, select the file you want to open

2) Right mouse button pops up the menu, select “Open mode”, and use “Charp editor with encoding function” to open it. As shown in the figure below:

Instead, select the following in the code:

then rebuild the solution, error elimination.

Compiler error message: cs1056: unexpected character handling

Error generation:
always returns an error when compiling a pre-existing program code using VS2015. strange In some added to the end of the class file some [] [] [] [], prompt Unexpected character, ‘application error.

A compilation error as shown in the title was caused by a special full-corner character in C# code. > special full-corner characters are not displayed and saved in UTF-8 format, and the compiler cannot correctly recognize such characters, resulting in compilation errors.

solution:
set the file open mode of VS 2015, make it contains a file with the Angle of all special characters use utf-8 format to open.
>
1) In Solution Explorer, select the file that needs special opening. 2) Right-click the mouse button to pop up the menu, select “Open Mode”, and use “Charp Editor with Encoding” to open.

Reproduced in: https://blog.51cto.com/studybao/2048899

Command failed: NPM install — loglevel error — registry= https://registry.npm.taobao.org

Use the vue – cli create project has the following error: the command failed: NPM install – loglevel error – registry=https://registry.npm.taobao.org – disturl=https://npm.taobao.org/dist

the solution has the following kinds:
Make sure that the vue-cli, NPM, node, Versions had better high node must be
1. 8 + NPM install chromedriver – chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver
finished to recreate the project (this approach is not once and for all)
2. NPM cache clean — force Clear the NPM cache (if it doesn’t work, it’s not a cache problem)
3. If the above two steps or not To install the following taobao source
NPM install – g CNPM – registry=https://registry.npm.taobao.org
4. Find your computer C: \ Users \ Administrator found. vuerc the file
initial is true instead of false can

Vue init webpack command error Vue cli / node_ modules/_ [email protected]@rimraf/rimraf.js :313

This is a low-level error in Vue development that can be encountered but is shared here so that it can be resolved if encountered
To explain the development environment in which this problem occurs: native Mac + NVM-managed node uses Node V8.0.0 to install vue-cli globally: NPM install vue-cli-g

Error is as follows

/Users/weiyongqiang/.nvm/versions/node/v9.2.0/lib/node_modules/vue-cli/node_modules/[email protected]@rimraf/rimraf.js:313
        throw er
        ^

Error: EACCES: permission denied, unlink '/Users/weiyongqiang/.vue-templates/webpack/.gitignore'

Error analysis
This problem is actually relatively simple. The intuitive error is that an exception is thrown on line 313 of rimraf.js. Exploring the cause of this problem requires understanding the role of rimraf.js. It uses the rm -rf command of Unix for deep package deletions. RM-RF is required to operate the corresponding permissions.
Error resolution
Run the vue command with sudo

sudo vue init webpack

Although the solution to this problem is very simple but I believe that many people will encounter, the use of Windows system, of course, will not appear the problem of authority.

Error: ~ /. Vuerc may be updated. Please delete it and re run vuercli in manual mode

Recently ready to develop an H5 sharing service, found the new version of Vue CLI4.0 is a lot of pit
First: My local @vue CLI version is 4.5.11:

 
Later, due to the tight schedule of the project, I directly reduced the local CLI version to 3.0, but because of my mistake, I made a mistake when creating the Vue project, but don’t worry:

Just find the local user directory C disk to find a.vuerc file deleted on the OK

Image proxy settings Flash + JavaScript

The article directories
Problem description idea specific implementation front end back end

Problem description
If is request http://www.example.com/image1.png picture originally, now ask for pictures, https://www.petal.social/image/www.example.com/image1.png you will need to do an image proxy
(request pictures to our own when the server request, then our HTTP server request images, the result of the HTTP in the way back to the web site of the HTTPS)
Train of thought
First, add an API locally for the front-end request that returns the modified image URL
The specific implementation
The front end
Original version:

showImage(url) {
    if (url.startsWith('http://')) {
        if (url.includes('qpic.cn') || url.includes('gtimg.cn')) {
            return url.replace('http://', 'https://')
        } else {
            return return 'https://demo.cloudimg.io/v7/' + url
        }
    } else {
        return url
    }
}

Image URL contains /, so in Flask is mistaken for routing calls, so you need to for the original URL with Base64 encryption
modify after:

import {Base64} from 'js-base64'
const BASE_URL = 'http://localhost:5000'
// const BASE_URL = 'https://www.petal.social'
showImage(url) {
    if (url.startsWith('http://')) {
        if (url.includes('qpic.cn') || url.includes('gtimg.cn')) {
            return url.replace('http://', 'https://')
        } else {
            return BASE_URL + '/api/v1/image/' + Base64.encode(url)
        }
    } else {
        return url
    }
}

The back-end

from flask_restplus import Namespace, Resource
from flask import request, make_response
from maintenance import check_maintenance, not_under_maintenance
import requests
from flask import Response, stream_with_context
import base64
image_api = Namespace('image', description='image related public interface')

@image_api.route('/<image_url>')
@image_api.param('image_url', 'The original image url')
class Image(Resource):
    @image_api.doc('get_image_url')
    @not_under_maintenance
    def get(self, image_url):
        check_maintenance()
        image_url = base64.b64decode(image_url)
        res = requests.get(image_url, stream = True)
        return Response(stream_with_context(res.iter_content(2048)), content_type = res.headers['content-type']) 

How to Fix “the data of store is lost after Vue refreshes the page”

When the page is refreshed, the VUE instance is reloaded, and the store will be reset. The store can be stored in the local localStorage, sessionStorage and cookie before the definition is refreshed. The localStorage is permanent storage, and the page data that was opened last time will be read when the page is reopened. According to my needs, the most appropriate is sessionStorage.
before upload fires when the page is refreshed. You can listen to this method to store the page to sessionStorage before the page is refreshed. Even when page refresh
of course, read the sessionStorage data into the store, read and stored, are written in the app. Vue.

export default {
  name: 'app',
  created () {
    // Read sessionStorage on page load
    if (sessionStorage.getItem('store')) {
      this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store'))))
    }
    // Save the store to sessionStorage when the page is refreshed
    window.addEventListener('beforeunload', () => {
      sessionStorage.setItem('store', JSON.stringify(this.$store.state))
    })
  }
}

Python custom convolution kernel weight parameters

Pytorch build convolution layer generally use nn. Conv2d method, in some cases we need custom convolution kernels weight weight, and nn. Conv2d custom is not allowed in the convolution parameters, can use the torch at this time. The nn. Functional. Conv2d referred to as “f. onv2d

torch.nn.functional.conv2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1)

F.onv2d can and must be required to input the convolution weight and bias bias. Therefore, build the desired convolution kernel parameters, and then input F.conv2d. Here is an example of using f.conv2d to build the convolution layer, where a class is needed for the network model:

class CNN(nn.Module):
    def __init__(self):
        super(CNN, self).__init__()
        self.weight = nn.Parameter(torch.randn(16, 1, 5, 5))  # Customized weights
        self.bias = nn.Parameter(torch.randn(16))    # Customized bias

    def forward(self, x):
        x = x.view(x.size(0), -1)
        out = F.conv2d(x, self.weight, self.bias, stride=1, padding=0)
        return out

It is worth noting that the data type of weights to be trained for each layer in the PyTorch is set to nn.parameter rather than Tensor or Variable. Parameter’s require_grad defaults to true, and Varaible defaults to False.