forked from jackfrued/Python-100-Days
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
43,911 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
公开课/文档/年薪50W+的Python程序员如何写代码/code/Java/opencourse/opencourse.iml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="module-library"> | ||
<library> | ||
<CLASSES> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/18.0.0/annotations-18.0.0.jar!/" /> | ||
</CLASSES> | ||
<JAVADOC /> | ||
<SOURCES /> | ||
</library> | ||
</orderEntry> | ||
</component> | ||
</module> |
Binary file added
BIN
+16 Bytes
...程序员如何写代码/code/Java/opencourse/out/production/opencourse/META-INF/opencourse.kotlin_module
Binary file not shown.
Binary file added
BIN
+563 Bytes
...on程序员如何写代码/code/Java/opencourse/out/production/opencourse/org/mobiletrain/Example01.class
Binary file not shown.
Binary file added
BIN
+631 Bytes
...on程序员如何写代码/code/Java/opencourse/out/production/opencourse/org/mobiletrain/Example02.class
Binary file not shown.
Binary file added
BIN
+859 Bytes
...on程序员如何写代码/code/Java/opencourse/out/production/opencourse/org/mobiletrain/Example03.class
Binary file not shown.
Binary file added
BIN
+2.32 KB
...on程序员如何写代码/code/Java/opencourse/out/production/opencourse/org/mobiletrain/Example04.class
Binary file not shown.
Binary file added
BIN
+1.26 KB
.../Java/opencourse/out/production/opencourse/org/mobiletrain/Example05$RequestHandler.class
Binary file not shown.
Binary file added
BIN
+996 Bytes
...on程序员如何写代码/code/Java/opencourse/out/production/opencourse/org/mobiletrain/Example05.class
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
公开课/文档/年薪50W+的Python程序员如何写代码/code/Java/opencourse/src/org/mobiletrain/Example01.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.mobiletrain; | ||
|
||
class Example01 { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("hello, world"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
公开课/文档/年薪50W+的Python程序员如何写代码/code/Java/opencourse/src/org/mobiletrain/Example02.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.mobiletrain; | ||
|
||
public class Example02 { | ||
|
||
public static void main(String[] args) { | ||
int total = 0; | ||
for (int i = 1; i <= 100; ++i) { | ||
total += i; | ||
} | ||
System.out.println(total); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
公开课/文档/年薪50W+的Python程序员如何写代码/code/Java/opencourse/src/org/mobiletrain/Example03.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.mobiletrain; | ||
|
||
import java.util.Arrays; | ||
|
||
public class Example03 { | ||
|
||
public static void main(String[] args) { | ||
boolean[] values = new boolean[10]; | ||
Arrays.fill(values, true); | ||
System.out.println(Arrays.toString(values)); | ||
|
||
int[] numbers = new int[10]; | ||
for (int i = 0; i < numbers.length; ++i) { | ||
numbers[i] = i + 1; | ||
} | ||
System.out.println(Arrays.toString(numbers)); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
公开课/文档/年薪50W+的Python程序员如何写代码/code/Java/opencourse/src/org/mobiletrain/Example04.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.mobiletrain; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Scanner; | ||
|
||
class Example04 { | ||
|
||
/** | ||
* 产生[min, max)范围的随机整数 | ||
*/ | ||
public static int randomInt(int min, int max) { | ||
return (int) (Math.random() * (max - min) + min); | ||
} | ||
|
||
/** | ||
* 输出一组双色球号码 | ||
*/ | ||
public static void display(List<Integer> balls) { | ||
for (int i = 0; i < balls.size(); ++i) { | ||
System.out.printf("%02d ", balls.get(i)); | ||
if (i == balls.size() - 2) { | ||
System.out.print("| "); | ||
} | ||
} | ||
System.out.println(); | ||
} | ||
|
||
/** | ||
* 生成一组随机号码 | ||
*/ | ||
public static List<Integer> generate() { | ||
List<Integer> redBalls = new ArrayList<>(); | ||
for (int i = 1; i <= 33; ++i) { | ||
redBalls.add(i); | ||
} | ||
List<Integer> selectedBalls = new ArrayList<>(); | ||
for (int i = 0; i < 6; ++i) { | ||
selectedBalls.add(redBalls.remove(randomInt(0, redBalls.size()))); | ||
} | ||
Collections.sort(selectedBalls); | ||
selectedBalls.add(randomInt(1, 17)); | ||
return selectedBalls; | ||
} | ||
|
||
public static void main(String[] args) { | ||
try (Scanner sc = new Scanner(System.in)) { | ||
System.out.print("机选几注: "); | ||
int num = sc.nextInt(); | ||
for (int i = 0; i < num; ++i) { | ||
display(generate()); | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
公开课/文档/年薪50W+的Python程序员如何写代码/code/Java/opencourse/src/org/mobiletrain/Example05.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.mobiletrain; | ||
|
||
import com.sun.net.httpserver.HttpExchange; | ||
import com.sun.net.httpserver.HttpHandler; | ||
import com.sun.net.httpserver.HttpServer; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.net.InetSocketAddress; | ||
|
||
class Example05 { | ||
|
||
public static void main(String[] arg) throws Exception { | ||
HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0); | ||
server.createContext("/", new RequestHandler()); | ||
server.start(); | ||
} | ||
|
||
static class RequestHandler implements HttpHandler { | ||
@Override | ||
public void handle(HttpExchange exchange) throws IOException { | ||
String response = "<h1>hello, world</h1>"; | ||
exchange.sendResponseHeaders(200, 0); | ||
try (OutputStream os = exchange.getResponseBody()) { | ||
os.write(response.getBytes()); | ||
} | ||
} | ||
} | ||
} |
40,950 changes: 40,950 additions & 0 deletions
40,950
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/USvideos.csv
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example01.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print('hello, world') |
1 change: 1 addition & 0 deletions
1
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example02.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print(sum(range(1, 101))) |
4 changes: 4 additions & 0 deletions
4
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example03.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
values = [True] * 10 | ||
print(values) | ||
numbers = [x for x in range(1, 11)] | ||
print(numbers) |
24 changes: 24 additions & 0 deletions
24
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example04.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from random import randint, sample | ||
|
||
|
||
def generate(): | ||
"""生成一组随机号码""" | ||
red_balls = [x for x in range(1, 34)] | ||
selected_balls = sample(red_balls, 6) | ||
selected_balls.sort() | ||
selected_balls.append(randint(1, 16)) | ||
return selected_balls | ||
|
||
|
||
def display(balls): | ||
"""输出一组双色球号码""" | ||
for index, ball in enumerate(balls): | ||
print(f'{ball:0>2d}', end=' ') | ||
if index == len(balls) - 2: | ||
print('|', end=' ') | ||
print() | ||
|
||
|
||
num = int(input('机选几注: ')) | ||
for _ in range(num): | ||
display(generate()) |
13 changes: 13 additions & 0 deletions
13
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example05.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from http.server import HTTPServer, SimpleHTTPRequestHandler | ||
|
||
|
||
class RequestHandler(SimpleHTTPRequestHandler): | ||
|
||
def do_GET(self): | ||
self.send_response(200) | ||
self.end_headers() | ||
self.wfile.write('<h1>goodbye, world</h1>'.encode()) | ||
|
||
|
||
server = HTTPServer(('', 8000), RequestHandler) | ||
server.serve_forever() |
25 changes: 25 additions & 0 deletions
25
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example06.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# 一行代码实现求阶乘函数 | ||
fac = lambda x: __import__('functools').reduce(int.__mul__, range(1, x + 1), 1) | ||
print(fac(5)) | ||
|
||
# 一行代码实现求最大公约数函数 | ||
gcd = lambda x, y: y % x and gcd(y % x, x) or x | ||
print(gcd(15, 27)) | ||
|
||
# 一行代码实现判断素数的函数 | ||
is_prime = lambda x: x > 1 and not [f for f in range(2, int(x ** 0.5) + 1) if x % f == 0] | ||
for num in range(2, 100): | ||
if is_prime(num): | ||
print(num, end=' ') | ||
print() | ||
|
||
# 一行代码实现快速排序 | ||
quick_sort = lambda items: len(items) and quick_sort([x for x in items[1:] if x < items[0]]) \ | ||
+ [items[0]] + quick_sort([x for x in items[1:] if x > items[0]]) \ | ||
or items | ||
items = [57, 12, 35, 68, 99, 81, 70, 22] | ||
print(quick_sort(items)) | ||
|
||
# 生成FizzBuzz列表 | ||
# 1 2 Fizz 4 Buzz 6 ... 14 ... FizzBuzz 16 ... 100 | ||
print(['Fizz'[x % 3 * 4:] + 'Buzz'[x % 5 * 4:] or x for x in range(1, 101)]) |
12 changes: 12 additions & 0 deletions
12
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example07.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from functools import lru_cache | ||
|
||
|
||
@lru_cache() | ||
def fib(num): | ||
if num in (1, 2): | ||
return 1 | ||
return fib(num - 1) + fib(num - 2) | ||
|
||
|
||
for n in range(1, 121): | ||
print(f'{n}: {fib(n)}') |
23 changes: 23 additions & 0 deletions
23
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example08.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from functools import wraps | ||
from threading import RLock | ||
|
||
|
||
def singleton(cls): | ||
instances = {} | ||
lock = RLock() | ||
|
||
@wraps(cls) | ||
def wrapper(*args, **kwargs): | ||
if cls not in instances: | ||
with lock: | ||
if cls not in instances: | ||
instances[cls] = cls(*args, **kwargs) | ||
return instances[cls] | ||
|
||
|
||
@singleton | ||
class President: | ||
pass | ||
|
||
|
||
President = President.__wrapped__ |
19 changes: 19 additions & 0 deletions
19
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example09.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import copy | ||
|
||
|
||
class PrototypeMeta(type): | ||
|
||
def __init__(cls, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
cls.clone = lambda self, is_deep=True: \ | ||
copy.deepcopy(self) if is_deep else copy.copy(self) | ||
|
||
|
||
class Student(metaclass=PrototypeMeta): | ||
pass | ||
|
||
|
||
stu1 = Student() | ||
stu2 = stu1.clone() | ||
print(stu1 == stu2) | ||
print(id(stu1), id(stu2)) |
15 changes: 15 additions & 0 deletions
15
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example10.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import random | ||
import time | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
for page in range(10): | ||
resp = requests.get( | ||
url=f'https://movie.douban.com/top250?start={25 * page}', | ||
headers={'User-Agent': 'BaiduSpider'} | ||
) | ||
soup = BeautifulSoup(resp.text, "lxml") | ||
for elem in soup.select('a > span.title:nth-child(1)'): | ||
print(elem.text) | ||
time.sleep(random.random() * 5) |
9 changes: 9 additions & 0 deletions
9
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part02/idiom01.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name = 'jackfrued' | ||
fruits = ['apple', 'orange', 'grape'] | ||
owners = {'name': '骆昊', 'age': 40, 'gender': True} | ||
|
||
# if name != '' and len(fruits) > 0 and len(owners.keys()) > 0: | ||
# print('Jackfrued love fruits.') | ||
|
||
if name and fruits and owners: | ||
print('Jackfrued love fruits.') |
8 changes: 8 additions & 0 deletions
8
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part02/idiom02.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
a, b = 5, 10 | ||
|
||
# temp = a | ||
# a = b | ||
# b = a | ||
|
||
a, b = b, a | ||
print(f'a = {a}, b = {b}') |
8 changes: 8 additions & 0 deletions
8
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part02/idiom03.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
chars = ['j', 'a', 'c', 'k', 'f', 'r', 'u', 'e', 'd'] | ||
|
||
# name = '' | ||
# for char in chars: | ||
# name += char | ||
|
||
name = ''.join(chars) | ||
print(name) |
9 changes: 9 additions & 0 deletions
9
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part02/idiom04.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fruits = ['orange', 'grape', 'pitaya', 'blueberry'] | ||
|
||
# index = 0 | ||
# for fruit in fruits: | ||
# print(index, ':', fruit) | ||
# index += 1 | ||
|
||
for index, fruit in enumerate(fruits): | ||
print(index, ':', fruit) |
9 changes: 9 additions & 0 deletions
9
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part02/idiom05.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
data = [7, 20, 3, 15, 11] | ||
|
||
# result = [] | ||
# for i in data: | ||
# if i > 10: | ||
# result.append(i * 3) | ||
|
||
result = [num * 3 for num in data if num > 10] | ||
print(result) |
14 changes: 14 additions & 0 deletions
14
公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part02/idiom06.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
data = {'x': '5'} | ||
|
||
# if 'x' in data and isinstance(data['x'], (str, int, float)) \ | ||
# and data['x'].isdigit(): | ||
# value = int(data['x']) | ||
# print(value) | ||
# else: | ||
# value = None | ||
|
||
try: | ||
value = int(data['x']) | ||
print(value) | ||
except (KeyError, TypeError, ValueError): | ||
value = None |
Oops, something went wrong.