Skip to content

Commit

Permalink
更新了公开课相关资源
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrued committed Dec 21, 2020
1 parent 3aa9f2f commit e34311d
Show file tree
Hide file tree
Showing 38 changed files with 43,911 additions and 0 deletions.
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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");
}
}
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);
}
}
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));
}
}
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());
}
}
}
}
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());
}
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print('hello, world')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print(sum(range(1, 101)))
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)
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())
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()
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)])
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)}')
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__
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))
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)
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.')
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}')
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)
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)
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)
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
Loading

0 comments on commit e34311d

Please sign in to comment.