2020-04-03 工作日志

14:00 《java设计模式及实践》

开闭原则,里氏替换原则,单一职责原则,接口隔离原则?,依赖倒置原则?
UML

14:30 《lightwieght django》

Why Stateless?

HTTP itself is a stateless protocol, meaning each request that comes to the server is
independent of the previous request. If a particular state is needed, it has to be added
at the application layer. Frameworks like Django use cookies and other mechanisms to
tie together requests made by the same client.
Along with a persistent session store on the server, the application can then handle tasks,
such as holding user authentication across requests. With that comes a number of chal‐
lenges, as this consistent state reads, and potentially writes, on every request in a dis‐
tributed server architecture.

通过正则匹配限定url

we’ll want to make sure to enforce them by the
URL. Since URL patterns in Django use regular expressions to match the incoming
URL, we’ll be able to easily pass in those parameters.

细节:r''

'r'是防止字符转义的 如果路径中出现'\t'的话 不加r的话\t就会被转义 而加了'r'之后'\t'就能保留原有的样子

python正则:

指数号(^)-匹配以指定字符开头的字符串
示例:^start—匹配以start开头的字符串

点号(.)-匹配除换行符\n外的任意单个字符
示例:a.o—匹配字母a和o且二者中间为任意单字符的字符串,如axoa!o

加号+用于表示最左边字符的一个或多个实例。

星号*用于表示最左边字符的0个或多个实例。

转换和验证从url中传入的参数

Though the regular expression will
ensure that the height and width consist of digits, they will be passed to the view as
strings. The view will need to convert them and may also want to validate that they are(注意传入的参数到后端都是String类型)
a manageable size. We can easily do this by validating user input with Django forms.
Typically forms are used to validate POST and GET content, but they can also be used
to validate particular values from the URL, or those stored in cookies

添加caching

One way to avoid this repetition is to use caching. There are two options to think about
when you’re determining how to utilize caching for this service: server-side and client-side. For server-side caching, you can easily use Django’s cache utilities. This will trade
memory usage to store the cached values while saving the CPU cycles required to gen‐
erate the images, as shown in this excerpt from placeholder.py

服务器端的缓存

from django.core.cache import cache
key = '{}.{}.{}'.format(width, height, image_format) 
content = cache.get(key) 
if content is None:
      pass
      cache.set(key, content, 60 * 60)
return content

Django defaults to using a process-local, in-memory cache, but you could use a different
backend—such as Memcached or the file system—by configuring the CACHES setting.

客户端缓存 304Not Modified(即请求的服务器资源未变 缓存再客户端)

A complementary approach is to focus on the client-side behavior and make use of the
browser’s built-in caching. Django includes an etag decorator for generating and using
the ETag headers for the view. The decorator takes a single argument, which is a functionto generate the ETag header from the request and view arguments.

import hashlib 
import os
...
from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.http import etag 
...
def generate_etag(request, width, height): 
 content = 'Placeholder: {0} x {1}'.format(width, height)
 return hashlib.sha1(content.encode('utf-8')).hexdigest()
@etag(generate_etag) 
def placeholder(request, width, height):
...

generate_etag is a new function that takes the same arguments as the
placeholder view. It uses hashlib to return an opaque ETag value, which will
vary based on the width and height values.The generate_etag function will be passed to the etag decorator on theplaceholder view.
With this decorator in place, the server will need to generate the image the first time
the browser requests it. On subsequent requests, if the browser makes a request with the matching ETag, the browser will receive a 304 Not Modified response for the image.The browser will use the image from the cache and save bandwidth and time to regen‐erate the HttpResponse.

20:50 matlab 返回多个值的函数

定义:

function [result1,...] = function_name(arg1,...)
...
...
end

调用:
[resut1,...] = functio_name(arg1,...);
注意用[]将返回值包裹起来

21:00 django

快速原型

“Death to Wireframes, Long Live Rapid Prototyping”

Bermon Painter statedthat there are five steps to the rapid prototyping process:

  1. Observe and analyze. This is the part of the process where you figure out your end�user goals. It is all about brainstorming with your teammates about what you want
    to build (e.g., Who are your users? What will each user want from your product?).
  2. Build. Using HTML, CSS, and JavaScript, the team now works together to create a
    minimum viable product (MVP) using only gray box samples and simple layouts.
  3. Ship. Create a seamless way for every single person who touches the code on your
    team to deploy and ship code for viewing and/or testing purposes.
  4. Adopt and educate. Teach your users how to use the new features or design of your
    project, and listen to their feedback.
  5. Iterate and maintain. Take your users’ feedback and iterate back through the rapid
    prototyping process. This helps refine your end product to create an even more
    successful result. Also, maintain the code you are working on by staying up to date
    with any new package releases.

21:30 《flutter in action》

Everything is widgets inside widgets inside widgets inside widgets...

组合多于继承

Flutter favors composition over class inheritance, which allows you to make your own
unique widgets. A majority of widgets are combinations of smaller widgets.

stateful widget

Flutter widgets are reactive. They respond to new information from an outside source
(or setState), and Flutter rebuilds what it needs to. This is the high-level process:
1 A user taps a button.
2 Your app calls setState in the Button.onPressed callback.
3 Flutter knows that it needs to rebuild, because the Button state is marked
dirty.
4 The new widget replaces the old one in the tree.
5 Flutter renders the new tree.

flutter,or,React

flutter小心点那个bug再不好 我就要投入React的怀抱了!!!

23:00

使用https://github.com/react-native-community/react-native-webview
来封装蛋蛋影视构建一个简易的app

你可能感兴趣的:(2020-04-03 工作日志)