There are three important concepts:
There are three layouts in Web:
Web是一个客户端-服务器系统。客户端向服务器发起请求:它会创建一个TCP/IP连接, 通过HTTP发送URL和其他信息并接收一个响应。响应的格式也由HTTP定义。其中包括请求的状态以及(如果请求成功)响应的数据和格式。
最著名的Web客户端是Web浏览器。它可以用很多种方式来发起HTTP请求。你可以在 地址栏中输入URL或者点击网页上的链接来手动发起请求。通常来说,请求所返回的数 据会被当作网页展示——HTML文档、JavaScript文件、CSS文件和图片——但也可以是 其他类型的数据,它们并不会被用于展示。
HTTP的一个重要概念是无状态。你发起的每个HTTP请求都和其他请求互相独立。可以使用cookie来解决无状态带来的问题。服务器可以在cookie中加入一些特殊的信息.
telnet www.google.com 80
如果google.com的80端口有一个Web服务器程序(我觉得这是肯定的),telnet会打印出一些确认信息并显示一个空白行供你输入信息:
Trying 172.217.10.228...
Connected to www.google.com.
Escape character is '^]'.
使用标准库来获取网站的内容。例子中的URL会返回一段随机文本
import urllib.request as ur
url = 'https://stemgene.github.io/2018/01/Markdown-Syntax/'
conn = ur.urlopen(url)
print(conn)
read()方法会获取网页的数据
data = conn.read()
print(data)
使用第三方模块request可以更短并且更易读
import requests
url = 'https://stemgene.github.io/2018/01/Markdown-Syntax/'
resp = requests.get(url)
resp
print(resp.text)
Web has turned out to be a powerful way to glue applications and data in many more formats than HTML
The webbrowser makes your browser do all the work
import webbrowser
url = 'http://www.python.org'
webbrowser.open(url)
Instead of publishing web pages, you can provide data through a web application programming interface(API). Clients access your service by making requests to URLs and getting back responses containing status and data. Instead of HTML pages, the data is in formats that are easier for programs to consume, such as JSON or XML.
JavaScript Object Notation(JSON,http://www.json.org)是源于JavaScript的当今很流行的 数据交换格式,它是JavaScript语言的一个子集,也是Python合法可支持的语法。
用dumps将数据编码成JSON字符串,然后再反过来用loads把JSON字符串解析成python的数据结构: 首先给出一组数据menu
import json
menu_json = json.dumps(menu)
menu_json
menu2 = json.loads(menu_json)
menu2
The information is available only in HTML pages. It’s much more satisfying to automate some or all of these steps. An automated web fetcher is called a crawler or spider.
If you already have the HTML data from a website and just want to extract data from it, BeautifulSoup is a good choice.
$ pip install beautifulsoup4
Let’s use it to get all the links from a web page. The HTML a element represnts a link, HTML的a元素表示一个链接,and herf is its attribute representing the link destination.
def get_links(url):
import requests
from bs4 import BeautifulSoup as soup
result = requests.get(url)
page = result.text
doc = soup(page)
links = [element.get('href') for element in doc.find_all('a')]
return links
if __name__ == '__main__':
import sys
for url in sys.argv[1:]:
print('Links in', url)
for num, link in enumerate(get_links(url), start = 1):
print(num , link)
print()
I saved this program as get_links.py and then ran this command:
$ python get_links.py http://stemgene.github.io
Besides these, there are several syntaxs below:
`Highlight`
Highlight
换行
直接回车不能换行,可以在上一行文本后面补两个空格,这样下一行的文本就换行了。或者就是在两行文本直接加一个空行。也能实现换行效果,不过这个行间距有点大。
锚点
Back to…
But you must notice that URL does not distinguish upper-case
and space
. For example, if you want to return to the top of this page, you should use '\[Back to Top](#mastering-markdown)
GitHub Pages 可以为你或者你的项目提供介绍网页,它是由 GitHub 官方托管和发布的。你可以使用 GitHub 提供的页面自动生成器。也可以做个人博客,是个轻量级的博客系统,没有麻烦的配置。使用标记语言如Markdown,不需自己搭建服务器,还可以绑定自己的域名。
Github Pages - 官方配置指南
Github Pages - 自定义页面指南
极客学院翻译 - 中文版本指南
本站借鉴了两篇文章:
用Jekyll搭建的Github Pages个人博客
利用 GitHub Pages 快速搭建个人博客
怎样将ipynb文件转为md文件:
Including Jupyter Notebooks in Jekyll blog posts
Using IPython Notebook to Write Jekyll Blog Posts
Each new prime is an extension of the bounds of human mathematical knowledge
Yesterday I read a news about scientists found out the largest prime number known
. It starts with a 4, ‘continues on for’ 23 million digits, then ends with a 1.
A prime number can only be divided evenly by
itself and by the number 1. The number 2 is prime because it can only be divided by 1 or 2 to give a whole number. Other example of prime numbers are 3,5,7,11,13,17 and 19.
Prime numbers are essential to modern life. They are used in everything from securely encrypting banking information to the random number generators used for visual effects in the latest movies.
About 2300 years ago, the Greek mathematician Euclid wrote a book called “The Elements”. He showed that prime numbers did not just stop at a certain value, there are infinitely many of them.
About 100 years later, another Greek mathematician Eratosthenes came up with a way of finding prime number. His method was called the Sieve of Eratosthenes. A sieve is a tool that drains water. Eratosthenes’ mathematical drains away non-prime numbers from prime numbers.
Here is how it works:
Write down all the numbers from 1 to 100.
Cross out 1, since it’s not a prime number. A prime number can be divided by exactly two numbers. The number 1 can only be divided by 1.
Circle 2, the smallest prime number, then cross out every multiple of
two. These are the numbers 4,6,8 etc. In other words
, cross out every second number
.
Circle 3, the next prime number. Then cross out all the multiple of 3, which are 6,9,12,15 etc. Some have already been crossed out.
Circle the next number not circled or crossed out, which is 5, then cross out the multiples of 5, which are 10,15,20,25 etc. Some have already been crossed out.
Continue doing this until all the numbers have been circled or crossed out. The circled numbers are the prime numbers from 1 to 100.
Christian Goldbach was a historian and mathematician. He made another discovery about prime numbers in the 1600s. He said that
every even number could be weitten by adding two prime numbers together.
For example, 20 can be written as 17+3.
Even today, we are still not sure if Goldbach’s idea is true. But scientists do know that it’s true for every even number between 2 and 400,000,000,000,000.
Cicadas are plant-eating insects. They spend almost all their lives underground before coming out as adults. For some kinds of cicada, this happens after 13 or 17 years.
Note that 13 and 17 are prime numbers. Scientists who have studied these cicadas think there’s a reason for this. Both predators and prey have certain life cycles, which determine how long it takes for those animals to reach a peak in their numbers. The reserchers found the best times for the cicadas to emerge from the ground were in life cycles that were prime numbers, like 13 and 17 years, so a predator’s life cycle also has to be 1, 13 or 17 years. The odds of being prey happening are much lower.
The newest prime number is generated by multiplying 2 by itself 77,232,917 times, then subtracting 1. The way this is calculated makes it a Mersenne Prime. Named after
the French theologian and mathematician Marin Mersenne, these types of primes are always calculated as a power of 2 minus 1. The number - which can be written in shorthand as M77232917 - is nearly 1 million digits longer than the last confirmed prime discovered in 2016.
When M77232917 is written out
as all 23,249,425 digits, the number contains every digit from zero through 9 roughly 2.3 million times each
. Like all prime numbers, it appears to be random. Some researchers suggest, however, that faint patterns shape the distribution of prime numbers. These faint patterns are enough to help narrow the search for new prime numbers. This helps researchers predict how many primes will exist within a range of numbers.
Determining if a number is a prime is simple in theory, all you need to do is divide it by all primes smaller than itself. If no other primes can divide it evenly, it must be a new prime number. In practice, however, this approach is time-consuming for a extremely large numbers, even with modern computers capable of precise and quick calculations. Instead, algorithms take advantage of a number theory trick called the Lucas-Lehmer test that only works for Mersenne primes to speed up the process.
Welcome to the list of primes, M77232917, and enjoy your time as the largest prime number while you can. One thing is certain: One day, a new largest prime number will be discovered.
关于写倒计时大家可能都都比较熟悉,使用 setTimeout 或 setInterval 就可以搞定。几秒钟或者几分钟的倒计时这样写没有问题,但是如果是长时间的倒计时,这样写就会不准确。如果用户修改了他的设备时间,这样的倒计时就没有意义了。今天就说说写一个精确的倒计时的方法。
本文将介绍如何使用 JavaScript 创建文件,并自动/手动将文件下载。这在导出原始数据时会比较方便。
/**
* 创建并下载文件
* @param {String} fileName 文件名
* @param {String} content 文件内容
*/
function createAndDownloadFile(fileName, content) {
var aTag = document.createElement('a');
var blob = new Blob([content]);
aTag.download = fileName;
aTag.href = URL.createObjectURL(blob);
aTag.click();
URL.revokeObjectURL(blob);
}
很简单对吧,直接调用这个方法,传入文件名和文件内容,程序新建 a 标签,新建 Blob 对象,将文件名赋给 a 标签,同时将 Blob 对象作为 Url 也赋给 a 标签,模拟点击事件,自动下载成功,最后再回收内存。下面我们来看看具体是怎么操作的。