Skip to content

Instantly share code, notes, and snippets.

View AntiKnot's full-sized avatar
🎯
Focusing

Yan.xxx AntiKnot

🎯
Focusing
View GitHub Profile
@AntiKnot
AntiKnot / BubbleSort.py
Created October 12, 2018 06:11
InfatuatedStaidFraction created by siyuYan - https://repl.it/@siyuYan/InfatuatedStaidFraction
def bubble_sort(numbers:list)->list:
length = len(numbers)
for i in range(length):
for j in range(0,length-i-1):
if numbers[j]>numbers[j+1]:
numbers[j],numbers[j+1] = numbers[j+1],numbers[j]
return numbers
@AntiKnot
AntiKnot / LargerDemo.java
Created October 12, 2018 06:29
FloweryPleasedPlanes created by SailerNote - https://repl.it/@SailerNote/FloweryPleasedPlanes
public class LargerDemo {
public static int larger(int x, int y) {
if (x > y) {
return x;
}
return y;
}
public static void main(String[] args) {
System.out.println(larger(-5,10));
@AntiKnot
AntiKnot / README-Template.md
Created January 24, 2019 05:37 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@AntiKnot
AntiKnot / heapq-topk&btmk.py
Last active May 29, 2019 07:11
python heapq TopK & BtmK
import heapq
class TopK(object):
def __init__(self, k):
self.k = k
self.heap = []
def push(self, elem):
if len(self.heap) < self.k:
@AntiKnot
AntiKnot / python_read_csv.py
Last active June 10, 2019 07:26
python read xlsx or csv by row
import os
import numpy as np
import pandas as pd
if __name__ == '__main__':
csv_data = pd.read_csv('../resources/areadata/data.csv')
dict_data = csv_data.to_dict(orient='row')
for elem in dict_data:
do_something(elem)
print(dict_data[3])
@AntiKnot
AntiKnot / django-annotate.py
Created June 18, 2019 10:56
django annotate
# django annoate
#single field
SomeModel.objects.values('gender').annotate(Sum('hotdog_number'))
#mutiple fields
SomeModel.objects.values('gender','age').annotate(Sum('hotdog_number'))
"""odrder_by is needed
without order_by
[
@AntiKnot
AntiKnot / nested2flat.py
Created July 10, 2019 14:24
convert nested data to flat data
data = [
{
'id': '1',
'parent': '',
'children': [
{
'id': '2',
'parent': '1',
'children': [
{
@AntiKnot
AntiKnot / flat2nested.py
Created July 10, 2019 14:36
convert flat data to nested data
items = [
{"id": "1", "parent": ""},
{"id": "2", "parent": "1"},
{"id": "3", "parent": "1"},
{"id": "4", "parent": ""},
{"id": "5", "parent": "4"},
{"id": "6", "parent": "4"},
{"id": "7", "parent": "4"},
{"id": "8", "parent": "2"},
{"id": "9", "parent": "8"},
@AntiKnot
AntiKnot / demo_bcrypt.py
Created September 5, 2019 09:37
demo with bcrypt, simple deal crypt password.
import bcrypt
def get_hashed_password(plain_text_password):
return bcrypt.hashpw(plain_text_password, bcrypt.gensalt())
def check_password(plain_text_password, hashed_password):
return bcrypt.checkpw(plain_text_password, hashed_password)
@AntiKnot
AntiKnot / decimal_performance_test.py
Created October 14, 2019 09:38
测试decimal的性能消耗
import decimal
import time
from functools import reduce
import matplotlib.pyplot as plt
import random
# generate scale number
def scale_random_number(scale):