Skip to content

Instantly share code, notes, and snippets.

@wangyiyang
wangyiyang / juhewethar.py
Last active March 30, 2016 08:13
聚合数据——天气接口 python3 版本
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import urllib
from urllib.parse import urlencode
import urllib.request as ur
#----------------------------------
# 天气预报调用示例代码 - 聚合数据
# webservice.py
from suds import WebFault
from suds.client import Client
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
# url="http://ipatest.shenzhenair.com/sasis/services/PassengerInfoService?wsdl"
url = 'http://ipatest.shenzhenair.com/sasis/services/FlightStatusInfoService?wsdl'
@wangyiyang
wangyiyang / Python面试.md
Last active June 14, 2018 01:45
Python 面试题

#Python 面试题

Python 装饰器

def log(func):
	def wrapper(*args, **kw):
    	print('call %s():' % func.__name__)
    	return func(*args, **kw)

return wrapper

@wangyiyang
wangyiyang / Singleton_Pattern.py
Last active December 23, 2019 03:17
单例模式的Python实现 #Algorithm #Python
#-*- encoding=utf-8 -*-
print '----------------------方法1--------------------------'
#方法1,实现__new__方法
#并在将一个类的实例绑定到类变量_instance上,
#如果cls._instance为None说明该类还没有实例化过,实例化该类,并返回
#如果cls._instance不为None,直接返回cls._instance
class Singleton(object):
def __new__(cls, *args, **kw):
if not hasattr(cls, '_instance'):
orig = super(Singleton, cls)
@wangyiyang
wangyiyang / find_common_root.py
Last active December 23, 2019 03:17
二叉树最近公共父节点: 有一个普通二叉树,AB分别为两个子节点,求AB最近的公共父节点。 #Algorithm #Python
# find_common_root.py
class TreeNode():
def __init__(self, left, right, val):
self.val = val
self.left = left
self.right = right
def getPath(self, root, decNode, array):
@wangyiyang
wangyiyang / mony_list_target.py
Created June 7, 2016 16:47
多个数组给定数找出多个数之和等于定数
def getresult(a=None, b=None, c=None, target=None):
for aitem in a:
for bitem in b:
if target - aitem - bitem in c:
return a.index(aitem), bitem, target - aitem - bitem
else:
return None
a = [1, 2, 3]
@wangyiyang
wangyiyang / exchange_rate.py
Created July 2, 2016 15:19
雅虎汇率API
# exchange_rate.py
import urllib2
#https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22{from_currency}{to_currency}%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
def get_exchange_rates(from_currency, to_currency):
url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22{from_currency}{to_currency}%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys".format(
from_currency=from_currency, to_currency=to_currency)
response = urllib2.urlopen(url, timeout=20).read()
json_html = eval(response)
@wangyiyang
wangyiyang / Dockerfile
Created July 22, 2016 04:01
oracle-java7
FROM phusion/baseimage:latest
MAINTAINER flurdy
ENV DEBIAN_FRONTEND noninteractive
# accept-java-license
RUN echo /usr/bin/debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
RUN apt-get update && \
@wangyiyang
wangyiyang / 分布式搜索elasticsearch配置文件详解.md
Last active August 19, 2016 07:03
分布式搜索elasticsearch配置文件详解

#分布式搜索elasticsearch配置文件详解

配置文件位于%ES_HOME%/config/elasticsearch.yml文件中

所有的配置都可以使用环境变量,例如: node.rack: ${RACK_ENV_VAR} 表示环境变量中有一个RACK_ENV_VAR变量。

下面列举一下elasticsearch的可配置项:

  1. 集群名称,默认为elasticsearch: cluster.name: elasticsearch
@wangyiyang
wangyiyang / elasticsearch_pulk_del.py
Last active December 7, 2016 02:32
elasticsearch批量删除脚本
# -*- coding: utf-8 -*-
# python elasticsearch_pulk_del.py --keep=31 --ip=10.140.65.12 保留31天index
# python elasticsearch_pulk_del.py --start_index=0 --end_index=10 --ip=10.140.65.12 删除最老的11个index
# python elasticsearch_pulk_del.py --om=true --ip=10.140.65.12 优化merge吞吐量
import urllib2
import json
import time
import datetime
from optparse import OptionParser