0%

Get Start

Install

pip install flask-restplus

Quickstart

from flask import Flask
from flask_restplus import Api, Resource

app = Flask(__name__)
api = Api(app)


@api.route('/hello')
class HelloWorld(Resource):
def get(self):
return {'Hello': 'world'}


if __name__ == '__main__':
app.run(debug=True)
$ python demo01.py 
* Serving Flask app "demo01" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 328-673-670
$ http :5000/hello
HTTP/1.0 200 OK
Content-Length: 25
Content-Type: application/json
Date: Tue, 18 Sep 2018 13:52:20 GMT
Server: Werkzeug/0.14.1 Python/3.6.6

{
"Hello": "world"
}

Installing Xampp and Laravel on Linux (Ubuntu , mint , OpenSuse …)

This tutorial show you how to Install Xampp ,Laravel and Lumen on Linux (Ubuntu , mint , OpenSuse …).If you are involved in building web apps using PHP, MySQL / MariaDB and Apache the Xampp is the ultimate choice for Development .

XAMPP is a completely free, easy to install Apache distribution containing MySQL / MariaDB, PHP, and Perl. The XAMPP open source package has been set up to be incredibly easy to install and to use. Best part is Xampp is cross-platform tool available for Windows , Mac and Linux.

阅读全文 »

参考资料

安装

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install python nginx certbot

配置

生成证书

sudo service nginx stop
sudo certbot certonly --standalone --email your@email.com -d yourdomain.com

配置文件

vim /etc/nginx/sites-available/ssl.conf :

server {

# SSL configuration
#
listen 443 ssl;
listen [::]:443 ssl;

ssl on;

ssl_certificate /etc/letsencrypt/live/harrypotterfans.top/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/harrypotterfans.top/privkey.pem;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
try_files $uri $uri/ =404;
}
}


server {

listen 80 default_server;
listen [::]:80 default_server;

server_name harrypotterfans.top; # www.harrypottefans.top;
rewrite ^(.*) https://$server_name$1 permanent;
}

sudo ln -s /etc/nginx/sites-available/ssl.conf /etc/nginx/sites-enabled/ssl.conf

https://github.com/norvig/paip-lisp/blob/master/docs/chapter3.md

Chapter 03 Overview of Lisp

No doubt about it. Common Lisp is a big language.

-Guy L. Steele, Jr.

Foreword to Koschman 1990

A Guide to Lisp Style

In general, there are six maxims that every programmer should follow:

  1. Be specific.
  2. Use abstractions.
  3. Be concise.
  4. Use the provided tools.
  5. Don’t be obscure.
  6. Be consistent.

Special Forms

definitions conditional variables iteration other
defun and let do declare
defstruct case let* do* function
defvar cond pop dolist progn
defparameter if push dotimes quote
defconstant or setf loop return
defmacro unless incf trace
labels when decf untrace

To be precise, only declare, function, if, labels, let, let*, progn and quote are true special forms. The others are actually defined as macros that expand into calls to more primitive special forms and functions. There is no real difference to the programmer, and Common Lisp implementations are free to implement macros as special forms and vice versa, so for simplicity we will continue to use “special form” as a blanket term for both true special forms and built-in macros.

Special Forms for Definitions

(defun function-name (parameter...) "optional documentation" body...)
(defmacro macro-name (parameter...) "optional documentation" body...)

(defvar variable-name initial-value "optional documentation" )
(defparameter variable-name value "optional documentation")
(defconstant variable-name value "optional documentation")



Special Forms for Conditionals

Special Forms for Dealing with Variables and Places

Functions and Special Forms for Repetition

Repetition through Recursion

Other Special Forms

Macros

Backquote Notation

Functions on Lists

https://github.com/norvig/paip-lisp/blob/master/docs/chapter2.md

Chapter 02 A Simple Lisp Program

Certum quod factum.

(One is certain of only what one builds.)

-Giovanni Battista Vico (1668-1744)

Italian royal historiographer

A Grammar for a Subset of English

The program we will develop in this chapter generates random English sentences. Here is a simple grammar for a tiny portion of English:

Sentence => Noun-Phrase + Verb-Phrase
Noun-Phrase => Article + Noun
Verb-Phrase => Verb + Noun-Phrase
Article => the, a,...
Noun => man, ball, woman, table...
Verb => hit, took, saw, liked...

A Straightforward Solution

We will develop a program that generates random sentences from a phrase-structure grammar. The most straightforward approach is to represent each grammar rule by a separate Lisp function:

(defun sentence ()    (append (noun-phrase) (verb-phrase)))
(defun noun-phrase () (append (Article) (Noun)))
(defun verb-phrase () (append (Verb) (noun-phrase)))
(defun Article () (one-of '(the a)))
(defun Noun () (one-of '(man ball woman table)))
(defun Verb () (one-of '(hit took saw liked)))

(defun one-of (set)
"Pick one element of set, and make a list of it."
(list (random-elt set)))

(defun random-elt (choices)
"Choose an element from a list at random."
(elt choices (random (length choices))))

Now we can test the program by generating a few random sentences, along with a noun phrase and a verb phrase:


> (sentence) => (THE WOMAN HIT THE BALL)

> (sentence) => (THE WOMAN HIT THE MAN)

> (sentence) =>(THE BALL SAW THE WOMAN)

> (sentence) => (THE BALL SAW THE TABLE)

> (noun-phrase) => (THE MAN)

> (verb-phrase) => (LIKED THE WOMAN)

> (trace sentence noun-phrase verb-phrase article noun verb) =>
(SENTENCE NOUN-PHRASE VERB-PHRASE ARTICLE NOUN VERB)

> (sentence) =>
(1 ENTER SENTENCE)
(1 ENTER NOUN-PHRASE)
(1 ENTER ARTICLE)
(1 EXIT ARTICLE: (THE))
(1 ENTER NOUN)
(1 EXIT NOUN: (MAN))
(1 EXIT NOUN-PHRASE: (THE MAN))
(1 ENTER VERB-PHRASE)
(1 ENTER VERB)
(1 EXIT VERB: (HIT))
(1 ENTER NOUN-PHRASE)
(1 ENTER ARTICLE)
(1 EXIT ARTICLE: (THE))
(1 ENTER NOUN)
(1 EXIT NOUN: (BALL))
(1 EXIT NOUN-PHRASE: (THE BALL))
(1 EXIT VERB-PHRASE: (HIT THE BALL))
(1 EXIT SENTENCE: (THE MAN HIT THE BALL))
(THE MAN HIT THE BALL)

The program works fine, and the trace looks just like the sample derivation above, but the Lisp definitions are a bit harder to read than the original grammar rules. This problem will be compounded as we consider more complex rules. Suppose we wanted to allow noun phrases to be modified by an indefinite number of adjectives and an indefinite number of prepositional phrases. In grammatical notation, we might have the following rules:

Noun-Phrase => Article + Adj* + Noun + PP*
Adj* => 0̸, Adj + Adj*
PP* => 0̸, PP + PP*
PP => Prep + Noun-Phrase
Adj => big, little, blue, green, ...
Prep => to, in, by, with, ...
(defun Adj* ()
(if (= (random 2) 0)
nil
(append (Adj) (Adj*))))
(defun PP* ()
(if (random-elt '(t nil))
(append (PP) (PP*))
nil))
(defun noun-phrase () (append (Article) (Adj*) (Noun) (PP*)))
(defun PP () (append (Prep) (noun-phrase)))
(defun Adj () (one-of '(big little blue green adiabatic)))
(defun Prep () (one-of '(to in by with on)))

I’ve chosen two different implementations for Adj* and PP*; either approach would work in either function. We have to be careful, though; here are two approaches that would not work:

(defun Adj* ()
"Warning - incorrect definition of Adjectives."
(one-of '(nil (append (Adj) (Adj*)))))
(defun Adj* ()
"Warning - incorrect definition of Adjectives."
(one-of (list nil (append (Adj) (Adj*)))))

Rule-Based Solution

An alternative implementation of this program would concentrate on making it easy to write grammar rules and would worry later about how they will be processed. Let’s look again at the original grammar rules:

Sentence => Noun-Phrase + Verb-Phrase
Noun-Phrase => Article + Noun
Verb-Phrase => Verb + Noun-Phrase
Article => the, a, ...
Noun => man, ball, woman, table...
Verb => hit, took, saw, liked...

Two Paths to Follow

Changing the Grammar without Changing the Program

Using the Same Data for Several Programs

☝ Back to Catalog

☜ Introduction to Lisp

☞ Overview of Lisp

https://github.com/norvig/paip-lisp/blob/master/docs/preface.md

Preface

Introduction

paradigm n 1 an example or pattern; esp an outstandingly clear or typical example.

-Longman’s Dictionary of the English Language, 1984

This book is concerned with three related topics:

  • the field of artificial intelligence, or AI;
  • the skill of computer programming;
  • and the programming language Common Lisp.

Why Lisp? Why Common Lisp?

Lisp is one of the oldest programming languages still in widespread use today.

  1. Lisp is the most popular language for AI programming, particularly in the United States. If you’re going to learn a language, it might as well be one with a growing literature, rather than a dead tongue.
  2. Lisp makes it easy to capture relevant generalizations in defining new objects.
  3. Lisp makes it very easy to develop a working program fast. Lisp programs are concise and are uncluttered by low-level detail. Common Lisp offers an unusually large number of useful predefined objects, including over 700 functions.
阅读全文 »