Skip to content

Instantly share code, notes, and snippets.

View Everfighting's full-sized avatar
😁
I may be slow to respond.

蔡大锅 Everfighting

😁
I may be slow to respond.
View GitHub Profile
@Everfighting
Everfighting / asyncpg_demo.py
Last active May 4, 2017 05:06
asyncpg:高效的基于 Python/asyncio 的 PostgreSQL 客户端库
import asyncio
import asyncpg
async def run():
conn = await asyncpg.connect(user='user', password='password',
database='database', host='127.0.0.1')
values = await conn.fetch('''SELECT * FROM mytable''')
await conn.close()
loop = asyncio.get_event_loop()
@Everfighting
Everfighting / enu_start_demo.py
Last active May 4, 2017 05:07
enumerate起始位置参数
list1 = ["这", "是", "一个", "测试"]
for index, item in enumerate(list1, 1):
print index, item
#results
#1 这
#2 是
#3 一个
#4 测试
#修改了默认的起始位置
@Everfighting
Everfighting / pymysql_demo.py
Last active May 4, 2017 05:07
python操作mysql数据库
# -*- coding: utf-8 -*-
import pymysql
conn= pymysql.connect(host="localhost",user="root",passwd="admin",db="local_db",charset="utf8")
cursor = conn.cursor()
n = cursor.execute("select * from course")
for row in cursor.fetchall():
for r in row:
print (r)
print(n)
@Everfighting
Everfighting / itertools_demo.py
Created May 4, 2017 05:35
itertools.chain的用法
import itertools
for i in itertools.chain([1, 2, 3], ['a', 'b', 'c']):
print(i,end=" ")
# 1 2 3 a b c
@Everfighting
Everfighting / readme
Last active May 4, 2017 10:15
pip安装方法
pip install -i http://pypi.douban.com/simple/ packagename
pip install -i http://pypi.tuna.tsinghua.edu.cn/simple packagename
@Everfighting
Everfighting / opertation.cs
Last active May 6, 2017 09:22
大话设计模式:简单工厂模式(C#版)
public class Operation
{
private double _numberA = 0;
private double _numberB = 0;
public double NumberA
{
get { return _numberA; }
set { _numberA = value; }
}
@Everfighting
Everfighting / opertation.py
Last active May 7, 2017 08:49
大话设计模式:简单工厂模式(python版)
class Operation:
def GetResult(self):
pass
class OperationAdd(Operation):
def GetResult(self):
return self.op1+self.op2
class OperationSub(Operation):
@Everfighting
Everfighting / smtplib_demo.py
Created May 8, 2017 06:26
python邮件模块smtplib的使用
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication
#设置登录及服务器信息
mail_host = 'smtp.163.com'
mail_user = '' #账号
mail_pass = '' #密码(smtp服务器的密码)
@Everfighting
Everfighting / smtplib_demo_v2.py
Created May 8, 2017 07:23
python邮件模块stmp优化版
#!/usr/bin/env python3
"""
email负责构造邮件
smtplib负责发送邮件
"""
from email.header import Header
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.utils import formatdate
import smtplib
@Everfighting
Everfighting / json_conn.py
Created May 11, 2017 03:44
读取配置文件转成json连接数据库
import psycopg2
import json
def load_db_config():
with open('../conf/db0.conf', "r") as f:
config_json = json.loads(f.read())
return config_json
config_json = load_db_config()