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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,417评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,921评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,850评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,945评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,069评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,188评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,239评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,994评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,409评论 1 304
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,735评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,898评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,578评论 4 336
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,205评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,916评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,156评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,722评论 2 363
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,781评论 2 351

推荐阅读更多精彩内容