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
import itertools | |
import requests | |
def check_password(password): | |
data = {'username': '0501234567', 'password': password} | |
res = requests.post('http://localhost:8080/login', json=data) | |
if res.status_code == 200: | |
return True | |
return False |
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
import hashlib | |
from bottle import run, post, request, HTTPResponse | |
def check_password(username, password): | |
hashed_password = hashlib.md5(password.encode('utf-8')).hexdigest() | |
return username == "0501234567" and hashed_password == '24fdf987d78b1f6d7c6008e7ecffeefb': # md5 of 01011980 | |
@post('/login') | |
def login(): | |
if check_password(request.json['username'], request.json['password']): |
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
class Reporter(models.Model): | |
id = models.AutoField(primary_key=True, null=False) | |
name = models.TextField | |
class Article(models.Model): | |
id = models.AutoField(primary_key=True, null=False) | |
content = models.TextField(null=True) | |
reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE) | |
ids = [a.reporter.id for a in Article.objects.filter(content__contains="camelCase")] # 1 |
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
select * from table where a=b and b=c | |
select * from table where a=b and b=c and a=c |
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
>>> 0.1 + 0.2 | |
0.30000000000000004 |
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
>>> round(0.1 + 0.2, 10) == 0.3 | |
True |
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
>>> from fractions import Fraction | |
>>> a = Fraction(1, 10) | |
>>> b = Fraction(2, 10) | |
>>> float(a + b) | |
0.3 | |
>>> a + b == Fraction(3, 10) | |
True |
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
>>> 0.1 + 0.2 == 0.3 | |
False | |
>>> def compare(a, b, epsilon=0.00001): | |
... return abs(a - b) < epsilon | |
... | |
>>> compare(0.1 + 0.2, 0.3) | |
True |
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
>>> class Reporter(models.Model): | |
... id = models.AutoField(primary_key=True, null=False) | |
... name = models.TextField | |
... | |
>>> qs = Reporter.objects.filter(name=None) # 1 | |
>>> print(qs.query) | |
SELECT * | |
FROM reporter | |
WHERE name = NULL |
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
from sqlalchemy import Column, Integer, String, create_engine | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import sessionmaker | |
engine = create_engine('sqlite:///:memory:') | |
Session = sessionmaker(bind=engine) | |
session = Session() | |
Base = declarative_base() |
OlderNewer