Skip to content

Commit e34311d

Browse files
committed
更新了公开课相关资源
1 parent 3aa9f2f commit e34311d

38 files changed

+43911
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library>
12+
<CLASSES>
13+
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/18.0.0/annotations-18.0.0.jar!/" />
14+
</CLASSES>
15+
<JAVADOC />
16+
<SOURCES />
17+
</library>
18+
</orderEntry>
19+
</component>
20+
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.mobiletrain;
2+
3+
class Example01 {
4+
5+
public static void main(String[] args) {
6+
System.out.println("hello, world");
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.mobiletrain;
2+
3+
public class Example02 {
4+
5+
public static void main(String[] args) {
6+
int total = 0;
7+
for (int i = 1; i <= 100; ++i) {
8+
total += i;
9+
}
10+
System.out.println(total);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.mobiletrain;
2+
3+
import java.util.Arrays;
4+
5+
public class Example03 {
6+
7+
public static void main(String[] args) {
8+
boolean[] values = new boolean[10];
9+
Arrays.fill(values, true);
10+
System.out.println(Arrays.toString(values));
11+
12+
int[] numbers = new int[10];
13+
for (int i = 0; i < numbers.length; ++i) {
14+
numbers[i] = i + 1;
15+
}
16+
System.out.println(Arrays.toString(numbers));
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.mobiletrain;
2+
3+
import java.util.List;
4+
import java.util.ArrayList;
5+
import java.util.Collections;
6+
import java.util.Scanner;
7+
8+
class Example04 {
9+
10+
/**
11+
* 产生[min, max)范围的随机整数
12+
*/
13+
public static int randomInt(int min, int max) {
14+
return (int) (Math.random() * (max - min) + min);
15+
}
16+
17+
/**
18+
* 输出一组双色球号码
19+
*/
20+
public static void display(List<Integer> balls) {
21+
for (int i = 0; i < balls.size(); ++i) {
22+
System.out.printf("%02d ", balls.get(i));
23+
if (i == balls.size() - 2) {
24+
System.out.print("| ");
25+
}
26+
}
27+
System.out.println();
28+
}
29+
30+
/**
31+
* 生成一组随机号码
32+
*/
33+
public static List<Integer> generate() {
34+
List<Integer> redBalls = new ArrayList<>();
35+
for (int i = 1; i <= 33; ++i) {
36+
redBalls.add(i);
37+
}
38+
List<Integer> selectedBalls = new ArrayList<>();
39+
for (int i = 0; i < 6; ++i) {
40+
selectedBalls.add(redBalls.remove(randomInt(0, redBalls.size())));
41+
}
42+
Collections.sort(selectedBalls);
43+
selectedBalls.add(randomInt(1, 17));
44+
return selectedBalls;
45+
}
46+
47+
public static void main(String[] args) {
48+
try (Scanner sc = new Scanner(System.in)) {
49+
System.out.print("机选几注: ");
50+
int num = sc.nextInt();
51+
for (int i = 0; i < num; ++i) {
52+
display(generate());
53+
}
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.mobiletrain;
2+
3+
import com.sun.net.httpserver.HttpExchange;
4+
import com.sun.net.httpserver.HttpHandler;
5+
import com.sun.net.httpserver.HttpServer;
6+
7+
import java.io.IOException;
8+
import java.io.OutputStream;
9+
import java.net.InetSocketAddress;
10+
11+
class Example05 {
12+
13+
public static void main(String[] arg) throws Exception {
14+
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
15+
server.createContext("/", new RequestHandler());
16+
server.start();
17+
}
18+
19+
static class RequestHandler implements HttpHandler {
20+
@Override
21+
public void handle(HttpExchange exchange) throws IOException {
22+
String response = "<h1>hello, world</h1>";
23+
exchange.sendResponseHeaders(200, 0);
24+
try (OutputStream os = exchange.getResponseBody()) {
25+
os.write(response.getBytes());
26+
}
27+
}
28+
}
29+
}

公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/USvideos.csv

Lines changed: 40950 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print('hello, world')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print(sum(range(1, 101)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
values = [True] * 10
2+
print(values)
3+
numbers = [x for x in range(1, 11)]
4+
print(numbers)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from random import randint, sample
2+
3+
4+
def generate():
5+
"""生成一组随机号码"""
6+
red_balls = [x for x in range(1, 34)]
7+
selected_balls = sample(red_balls, 6)
8+
selected_balls.sort()
9+
selected_balls.append(randint(1, 16))
10+
return selected_balls
11+
12+
13+
def display(balls):
14+
"""输出一组双色球号码"""
15+
for index, ball in enumerate(balls):
16+
print(f'{ball:0>2d}', end=' ')
17+
if index == len(balls) - 2:
18+
print('|', end=' ')
19+
print()
20+
21+
22+
num = int(input('机选几注: '))
23+
for _ in range(num):
24+
display(generate())
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from http.server import HTTPServer, SimpleHTTPRequestHandler
2+
3+
4+
class RequestHandler(SimpleHTTPRequestHandler):
5+
6+
def do_GET(self):
7+
self.send_response(200)
8+
self.end_headers()
9+
self.wfile.write('<h1>goodbye, world</h1>'.encode())
10+
11+
12+
server = HTTPServer(('', 8000), RequestHandler)
13+
server.serve_forever()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 一行代码实现求阶乘函数
2+
fac = lambda x: __import__('functools').reduce(int.__mul__, range(1, x + 1), 1)
3+
print(fac(5))
4+
5+
# 一行代码实现求最大公约数函数
6+
gcd = lambda x, y: y % x and gcd(y % x, x) or x
7+
print(gcd(15, 27))
8+
9+
# 一行代码实现判断素数的函数
10+
is_prime = lambda x: x > 1 and not [f for f in range(2, int(x ** 0.5) + 1) if x % f == 0]
11+
for num in range(2, 100):
12+
if is_prime(num):
13+
print(num, end=' ')
14+
print()
15+
16+
# 一行代码实现快速排序
17+
quick_sort = lambda items: len(items) and quick_sort([x for x in items[1:] if x < items[0]]) \
18+
+ [items[0]] + quick_sort([x for x in items[1:] if x > items[0]]) \
19+
or items
20+
items = [57, 12, 35, 68, 99, 81, 70, 22]
21+
print(quick_sort(items))
22+
23+
# 生成FizzBuzz列表
24+
# 1 2 Fizz 4 Buzz 6 ... 14 ... FizzBuzz 16 ... 100
25+
print(['Fizz'[x % 3 * 4:] + 'Buzz'[x % 5 * 4:] or x for x in range(1, 101)])
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from functools import lru_cache
2+
3+
4+
@lru_cache()
5+
def fib(num):
6+
if num in (1, 2):
7+
return 1
8+
return fib(num - 1) + fib(num - 2)
9+
10+
11+
for n in range(1, 121):
12+
print(f'{n}: {fib(n)}')
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from functools import wraps
2+
from threading import RLock
3+
4+
5+
def singleton(cls):
6+
instances = {}
7+
lock = RLock()
8+
9+
@wraps(cls)
10+
def wrapper(*args, **kwargs):
11+
if cls not in instances:
12+
with lock:
13+
if cls not in instances:
14+
instances[cls] = cls(*args, **kwargs)
15+
return instances[cls]
16+
17+
18+
@singleton
19+
class President:
20+
pass
21+
22+
23+
President = President.__wrapped__
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import copy
2+
3+
4+
class PrototypeMeta(type):
5+
6+
def __init__(cls, *args, **kwargs):
7+
super().__init__(*args, **kwargs)
8+
cls.clone = lambda self, is_deep=True: \
9+
copy.deepcopy(self) if is_deep else copy.copy(self)
10+
11+
12+
class Student(metaclass=PrototypeMeta):
13+
pass
14+
15+
16+
stu1 = Student()
17+
stu2 = stu1.clone()
18+
print(stu1 == stu2)
19+
print(id(stu1), id(stu2))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import random
2+
import time
3+
4+
import requests
5+
from bs4 import BeautifulSoup
6+
7+
for page in range(10):
8+
resp = requests.get(
9+
url=f'https://movie.douban.com/top250?start={25 * page}',
10+
headers={'User-Agent': 'BaiduSpider'}
11+
)
12+
soup = BeautifulSoup(resp.text, "lxml")
13+
for elem in soup.select('a > span.title:nth-child(1)'):
14+
print(elem.text)
15+
time.sleep(random.random() * 5)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = 'jackfrued'
2+
fruits = ['apple', 'orange', 'grape']
3+
owners = {'name': '骆昊', 'age': 40, 'gender': True}
4+
5+
# if name != '' and len(fruits) > 0 and len(owners.keys()) > 0:
6+
# print('Jackfrued love fruits.')
7+
8+
if name and fruits and owners:
9+
print('Jackfrued love fruits.')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a, b = 5, 10
2+
3+
# temp = a
4+
# a = b
5+
# b = a
6+
7+
a, b = b, a
8+
print(f'a = {a}, b = {b}')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
chars = ['j', 'a', 'c', 'k', 'f', 'r', 'u', 'e', 'd']
2+
3+
# name = ''
4+
# for char in chars:
5+
# name += char
6+
7+
name = ''.join(chars)
8+
print(name)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fruits = ['orange', 'grape', 'pitaya', 'blueberry']
2+
3+
# index = 0
4+
# for fruit in fruits:
5+
# print(index, ':', fruit)
6+
# index += 1
7+
8+
for index, fruit in enumerate(fruits):
9+
print(index, ':', fruit)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
data = [7, 20, 3, 15, 11]
2+
3+
# result = []
4+
# for i in data:
5+
# if i > 10:
6+
# result.append(i * 3)
7+
8+
result = [num * 3 for num in data if num > 10]
9+
print(result)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
data = {'x': '5'}
2+
3+
# if 'x' in data and isinstance(data['x'], (str, int, float)) \
4+
# and data['x'].isdigit():
5+
# value = int(data['x'])
6+
# print(value)
7+
# else:
8+
# value = None
9+
10+
try:
11+
value = int(data['x'])
12+
print(value)
13+
except (KeyError, TypeError, ValueError):
14+
value = None

0 commit comments

Comments
 (0)