Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"log"
"net/http"
"github.com/prometheus/procfs"
)
"""
python tailf.py thefile
equals linux shell order : tail -f thefile
"""
import time
def trackline(thefile):
thefile.seek(0, 2)
while True:
line = thefile.readline()
@xiaotangyuan
xiaotangyuan / namekoservice.py
Last active January 9, 2019 09:26
use nameko
import os
from nameko.rpc import rpc
from nameko.cli import run
rabbit_config = {
'AMQP_URI': os.environ['AMQP_URI'],
'rpc_exchange': 'smstaskrpc',
'max_workers': 20,
'parent_calls_tracked': 10,
# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import requests
STATION_TRAIN_CODE = 'G1952'
TRAIN_DATE = '2017-01-17'
subject = u'火车票余票提醒'
@xiaotangyuan
xiaotangyuan / gist:35b2c2a5835b12920da0ab8e67a7f0a0
Created December 30, 2016 03:48
download walking dead comic
# encoding=utf8
import commands
import time
base_url = "http://www.omgbeaupeep.com/comics/mangas/The%20Walking%20Dead/001%20-%20The%20Walking%20Dead%20001/The-Walking-Dead-Comic-00{pic}.jpg"
for i in range(9,53):
image_url = base_url.replace('{pic}',str(i))
order = 'wget %s ' % image_url
print order
res = commands.getstatusoutput(order)
# print res
@xiaotangyuan
xiaotangyuan / sendemail.py
Last active October 25, 2016 07:38
smtp发送邮件附件
import os
import smtplib
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
def send_mail(send_from, send_to, subject, text, files,
smtpserver, sender_username, sender_password):
assert isinstance(send_to, list)
@xiaotangyuan
xiaotangyuan / gist:124238f03eaa0cfe40d3f9f2c34b1014
Created August 4, 2016 07:42
windows csv file code error
import csv
f = codecs.open('dfdf.csv' , 'w', 'utf_8_sig')
writer = csv.writer(f)
writer.writerow(['fdfd'])
def exchange(a_index,b_index,thelist):
temp = thelist[a_index]
thelist[a_index] = thelist[b_index]
thelist[b_index] = temp
print 'exchanged:',thelist[a_index],thelist[b_index]
return thelist
def insertorder(thelist):
for index,num in enumerate(thelist):
if index == 0:
def selectorder(thelist):
for index,num in enumerate(thelist):
minnum = num
minnum_index = index
for index2,num2 in enumerate(thelist[index+1:]):
if num2 < minnum:
minnum = num2
minnum_index = index + index2 + 1
thelist[index] = minnum
class Solution(object):
def findMedianSortedArrays(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: float
"""
nums = nums1 + nums2
nums = sorted(nums)
total = len(nums)