写出明确的指引的策略

在查询中包含详细信息以获得更相关的答案

(Include details in your query to get more relevant answers****)****

为了获得高度相关的回答,请确保请求提供任何重要的细节或背景信息。否则,你就让模型去猜你的意思了。

Worse Better
How do I add numbers in Excel? How do I add up a row of dollar amounts in Excel? I want to do this automatically for a whole sheet of rows with all the totals ending up on the right in a column called “Total”.
Who’s president? Who was the president of Mexico in 2021, and how frequently are elections held?
Write code to calculate the Fibonacci sequence. Write a TypeScript function to efficiently calculate the Fibonacci sequence. Comment the code liberally to explain what each piece does and why it’s written that way.
Summarize the meeting notes. Summarize the meeting notes in a single paragraph. Then write a markdown list of the speakers and each of their key points. Finally, list the next steps or action items suggested by the speakers, if any.

要求模型采用特定的人设

(Ask the model to adopt a persona)
系统消息可以用来指定模型在回复中所使用的人设。

Role Prompt
SYSTEM When I ask for help to write something, you will reply with a document that contains at least one joke or playful comment in every paragraph.
USER Write a thank you note to my steel bolt vendor for getting the delivery in on time and in short notice. This made it possible for us to deliver an important order.
More...

GPT 官方推荐使用方法

背景

GPT官方推出了一个使用方法介绍:网址,挺有意思,搬运过来,并做一些归纳。
有6种方法可以得到更好的结果:

一、写出明确的指引(Clear Instructions)

GPT无法读取您的思维。如果它们的输出太长,请要求简洁回答。如果它们的输出过于简单,请要求专家级的写作。如果您不喜欢格式,请展示您想要看到的格式。GPT越少猜测您的需求,您得到的结果就更有可能符合您的期望。

策略:

More...

Django 的类视图

背景

练习Django的时候发现它的类视图很神奇,很少的代码就能实现功能,研究了一下,发现这个教程,写得比较详细,转载一下,加深印象。

类视图与函数视图

Django的视图可以分为:

  • 函数视图FBV:def index(request):
  • 类视图CBV:class AboutView(TemplateView):

早期,人们在视图开发中发现了一些常见的习语和句式,也就是重复性代码和工作。于是引入了基于函数的视图来抽象这些模式,便于一般情况下的视图开发。

基于函数的视图的问题在于,尽管它们覆盖了简单的情况,但是除了一些简单的配置选项之外,没有办法扩展或定制它们,限制了它们在许多现实应用中的实用性。

基于类的通用视图与基于函数的视图的目标相同,都是想让视图开发更容易。但由于类视图可以使用MIXIN等一些面向对象的方法和工具包,使得基于类的视图比基于函数的视图更具扩展性和灵活性。

基于类的视图:

  • 通过HTTP请求方法的不同,将代码分隔在不同的类方法中,比如GET和POST,而不是类函数中的条件判断。
  • 可以使用面向对象的技巧,比如混入。
  • 类具有封装和继承的特性,方便代码复用、分发和重构。

两种视图可以实现同样的功能,本质上是一个东西,没有谁好谁坏之分,只是适用场景不同而已:

  • 简单逻辑、快速处理,请用FBV
  • 代码复用、功能封装,请用CBV

用法

Django 提供了很多适用于各种应用场景的基本视图类,我们一般不从头自己写起,这些类视图都继承django.views.generic.base.View类。比如RedirectView 用于 HTTP 重定向,TemplateView 用于渲染模板。

类视图有很多简单的用法,甚至不需要去views.py中编写代码,比如下面的例子:

1
2
3
4
5
6
from django.urls import path
from django.views.generic import TemplateView

urlpatterns = [
path('about/', TemplateView.as_view(template_name="about.html")),
]

重点关注:

  • TemplateView类视图
  • as_view()方法
  • template_name参数

更通用的使用方法是继承Django提供的各种视图类,所以上面的例子的一般性写法如下:

1
2
3
4
5
# some_app/views.py
from django.views.generic import TemplateView

class AboutView(TemplateView):
template_name = "about.html"

但是,由于类不是函数,所以需要在URLconf中使用as_view()这个类方法将一个基于类的视图转换成函数形式的接口。

1
2
3
4
5
6
7
# urls.py
from django.urls import path
from some_app.views import AboutView

urlpatterns = [
path('about/', AboutView.as_view()),
]
More...

解决Django无法访问远程服务器

背景

我在运上搭建了Django的服务器环境,这样就不能用 http://127.0.0.1:8000 来访问Django的服务了,那如何解决呢?

解决方案

在启动服务的时候,加一些参数:

1
python3 [manage.py](http://manage.py/) runserver 0.0.0.0:8000

同时,修改 setting.py,将远端的服务器ip加到ALLOWED_HOSTS参数里:

1
ALLOWED_HOSTS = ['xxx.xxx.xxx.xxx']

注:其中’xxx.xxx.xxx.xxx’是你远程服务器的外网ip

这样,就可以用 http://xxx.xxx.xxx.xxx:8000 访问Django的服务了。

SSH客户端会话超时的解决方案

背景

通常默认公有云上的ECS远程连接,很容易断开,当你有什么事情被打断或者去操作别的机器同步做点其他事情,你会发现你SSH客户端登录窗口经常会断开掉,非常烦人,经常要重新登录。
如果用一些Windows下客户端软件比如XShell or CRT都会有超时时间和心跳检测次数设置,但是默认Mac下的终端 Or Linux下直接远程命令客户端是没有这个设置窗口的。
SSH Client会从以下途径获取配置参数:

  1. SSH命令行参数;
  2. 用户配置文件 (~/.ssh/config);
  3. 系统配置文件 (/etc/ssh/ssh_config)。

方法1

1
ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=30 root@10.0.1.25 -p22

方法2

1
2
3
4
$ vim ~/.ssh/config #添加如下内容
Host *
ServerAliveInterval 60
ServerAliveCountMax 30

方法3

1
2
3
4
5
6
$ vim /etc/ssh/ssh_config # 在Host *下面添加:

Host *
SendEnv LANG LC_*
ServerAliveInterval 60
ServerAliveCountMax 30

如果三个都设置了,读取顺序是 方法1 —> 方法2 —> 方法3

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(10)

比特币:一个点对点的电子货币系统

11 结论

11 Conclusion
We have proposed a system for electronic transactions without relying on trust. We started with the usual framework of coins made from digital signatures, which provides strong control of ownership, but is incomplete without a way to prevent double-spending. To solve this, we proposed a peer-to-peer network using proof-of-work to record a public history of transactions that quickly becomes computationally impractical for an attacker to change if honest nodes control a majority of CPU power. The network is robust in its unstructured simplicity. Nodes work all at once with little coordination. They do not need to be identified, since messages are not routed to any particular place and only need to be delivered on a best effort basis. Nodes can leave and rejoin the network at will, accepting the proof-of-work chain as proof of what happened while they were gone. They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.

我们已经提出了一种不依赖信任的电子交易系统。我们从通用的数字签名货币体系开始,这体系提供了强有力的所有权控制,但由于缺乏防止双重支付的方法而不完善。为解决这个问题,我们提出一种使用工作量证明来记录公共交易历史的点对点网络,只要诚实节点控制了多数的 CPU 算力,对于攻击者,交易历史将很快变得在计算上不可更改。网络因其结构简洁性而强大。节点只需很少的协调就能同时工作。它们不需要被认证,因为信息不会被发送到某个特殊的位置,只需被尽力传播。节点可以随时离开和重新加入网络,只需接受工作量证明链作为它们离开时发生事件的证据。节点使用 CPU 算力来投票,通过致力于延长有效区块来表达对其接受,通过拒绝在无效区块上工作来表达对其抵制。任何需要的规则和激励都可通过这个共识机制来加强。

【关注点】:

  • rules and incentives, 都会有哪些规则和激励?

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(9)

比特币:一个点对点的电子货币系统

11 计算

We consider the scenario of an attacker trying to generate an alternate chain faster than the honest chain. Even if this is accomplished, it does not throw the system open to arbitrary changes, such as creating value out of thin air or taking money that never belonged to the attacker. Nodes are not going to accept an invalid transaction as payment, and honest nodes will never accept a block containing them. An attacker can only try to change one of his own transactions to take back money he recently spent.
The race between the honest chain and an attacker chain can be characterized as a Binomial Random Walk. The success event is the honest chain being extended by one block, increasing its lead by +1, and the failure event is the attacker’s chain being extended by one block, reducing the gap by -1. The probability of an attacker catching up from a given deficit is analogous to a Gambler’s Ruin problem. Suppose a gambler with unlimited credit starts at a deficit and plays potentially an infinite number of trials to try to reach breakeven. We can calculate the probability he ever reaches breakeven, or that an attacker ever catches up with the honest chain, as follows [8]:
p = probability an honest node finds the next block
q = probability the attacker finds the next block
qz = probability the attacker will ever catch up from z blocks behind

More...

Difference between" npm run serve" and "npm run dev" in VUE

npm run serve basically is just saying “npm please run the command I defined under the name serve in package.json” the same happens with npm run dev.

Given this the commands can do the exact same thing, similar things, or very different things. Usually they are a shorthand for running a dev server on localhost, but it’s not a rule, only a convention.

So you’ll need to check in your package.json file and look for

1
2
3
4
"scripts": {
"serve": "[list of commands here]",
"dev": "[list of commands here]"
},

VUE练习4 - 使用Ant Design

1 安装

1
npm i --save ant-design-vue@3.2.16

不要装最新版,变化比较大。

2 注册

**全局完整注册:**修改 main.js:

1
2
3
4
5
6
7
8
9
10
11
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
import settings from '@/settings';

const app = createApp(App)
app.use(store).use(router).use(Antd).mount('#app')
app.config.globalProperties.$settings = settings

3 测试

修改 ShowCenterView.vue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<template>
<div class="showcenter">
<h1>show center | 展示中心</h1>
<a-row>
<a-col :span="8" :offset="8">
<a-input-search
v-model:value="value"
placeholder="input text"
enter-button="Search"
size="large"
@search="onSearch"
/>
</a-col>
</a-row>
</div>
</template>

效果:

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(8)

比特币:一个点对点的电子货币系统

10 隐私

10 Privacy
The traditional banking model achieves a level of privacy by limiting access to information to the parties involved and the trusted third party. The necessity to announce all transactions publicly precludes this method, but privacy can still be maintained by breaking the flow of information in another place: by keeping public keys anonymous. The public can see that someone is sending an amount to someone else, but without information linking the transaction to anyone. This is similar to the level of information released by stock exchanges, where the time and size of individual trades, the “tape”, is made public, but without telling who the parties were.

As an additional firewall, a new key pair should be used for each transaction to keep them from being linked to a common owner. Some linking is still unavoidable with multi-input transactions, which necessarily reveal that their inputs were owned by the same owner. The risk is that if the owner of a key is revealed, linking could reveal other transactions that belonged to the same owner.

传统的银行模型通过限制参与方和可信任第三方对信息的访问来达到一定级别的隐私保护。交易必须要公开发布就不能使用这个方法,但隐私仍可在其他地方通过阻断信息流的方式来保护:那就是保持公钥匿名。公众能看到有人正在发送一定量货币给其他人,但是不能将交易关联到某个人。这和证券交易所发布的信息级别类似,每笔交易的时间和交易量,即行情是公开的,但是不会显示交易双方是谁。

作为额外的防火墙,对每笔交易使用新密钥对可以防止他们被关联到一个共同的拥有者。由于多输入值交易存在,有些关联仍不可避免,因为多输入值交易必然暴露其多个输入是属于同一个拥有者的。风险就在于如果一个密钥的拥有者被暴露,关联性将暴露属于同一个拥有者的其他交易。

【关注点】:

  • keeping public keys anonymous, 如何做到呢?
  • 证券交易所发布的信息级别类似,这个类比比较有趣。

请我喝杯咖啡吧~

支付宝
微信