Skip to content

Instantly share code, notes, and snippets.

@ranlix
ranlix / TheBigBen.py
Last active December 17, 2015 09:08
Created by Alex Li; Bell us when it's the whole point
# coding=gbk
import time
from datetime import datetime
LAST_MINUTE = 59 #when it is the last mintue in an hour,the minute is (60-1)
MINUTE_SECONDS = 60#one minute has 60s
def main():
'''This is a main function to print bell when time is the whole point.'''
# coding=utf-8
import time
from datetime import datetime
from douban_client import DoubanClient
LAST_MINUTE = 59 # when it is the last mintue in an hour,the minute is (60-1)
MINUTE_SECONDS = 60 # one minute has 60s
API_KEY = 'your api key'
API_SECRET = 'your api secret'
SCOPE = 'douban_basic_common,shuo_basic_r,shuo_basic_w'
@ranlix
ranlix / gist:5983386
Last active December 19, 2015 16:19
page61
# -*- conding:utf-8 -*-
import math
import calendar
#1.a)
math.abs(-4.3)
#1.b)进一法是嘛?ceil?
math.ceil(math.sin(34.5))
#2.a)
Python补充01 序列的方法
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明。谢谢!
在快速教程中,我们了解了最基本的序列(sequence)。回忆一下,序列包含有定值表(tuple)和表(list)。
此外,字符串(string)是一种特殊的定值表。表的元素可以更改,定值表一旦建立,其元素不可更改。
Python内置函数清单
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明。
Python内置(built-in)函数随着python解释器的运行而创建。在Python的程序中,你可以随时调用这些函数,不需要定义。
最常见的内置函数是:
print("Hello World!")
@ranlix
ranlix / SMTP.py
Last active December 24, 2015 05:19
用smtplib来登录连接邮箱,发送测试邮件到目标邮件
# -*- coding:utf-8 -*-
import smtplib
username = "*******@163.com"
password = "*********"
smtp = smtplib.SMTP() #继承SMTP()的属性
smtp.connect("smtp.163.com","25") #连接服务器和端口
mail_text = """
From: *******@163.com\r\n
# Rock-paper-scissors-lizard-Spock template
import random
# The key idea of this program is to equate the strings
# "rock", "paper", "scissors", "lizard", "Spock" to numbers
# as follows:
#
# 0 - rock
# 1 - Spock
# 2 - paper
@ranlix
ranlix / is_int.py
Last active December 26, 2015 12:38
用于测试手机屏幕在播放某些分辨率的视频的时候的补偿值: 32*x + 2(or 4 or 8 or 16 or 32) = y, 在y输入任意正整数的时候,保证x为有且仅有一个正整数的值
# -*- coding=utf-8 -*-
def is_int():
inputNum = int(input("Please input a number: "))
#生成补偿值的列表
offset_list = range(1,6)
#生成 inputNum-补偿值 列表
new_list = [(inputNum - 2**i)%32 for i in offset_list]
#判断 inputNum-补偿值是不是32的倍数
if new_list.count(0) == 1:
@ranlix
ranlix / Guess_the_number.py
Last active December 27, 2015 18:39
An Introduction to Interactive Programming in Python ——Guess the number!
# template for "Guess the number" mini-project
# input will come from buttons and an input field
# all output for the game will be printed in the console
import simplegui
import random
import math
# initialize global variables used in your code
num_range = 0
num_guess = 0
@ranlix
ranlix / cfg_create.py
Last active December 28, 2015 18:28
工作需要,每个库文件都需要生成单独的cfg文件,并且需要筛选目录下存在的库文件,对比文档里的库文件对应的id,生成内容为“id,4(level)”的cfg文件。 注:这次是在sublime Text2里添加了PEP8的插件,从此开始注重编码规范
# -*-coding:utf-8 -*-
import os
path = r"C:\Users\alex\Desktop\debug"
original_file = open(r"module.txt", "r") # read file
content = original_file.readlines()
def lib_list_without_so(yourdir):
""" Create a list which contains all the libs without '.so'