docker/desktop-kubernetes kubernetes-v1.22.4-cni-v0.8.5-critools-v1.17.0-debian 493a106d3678 2 months ago 294MB
k8s.gcr.io/kube-apiserver v1.22.4 8a5cc299272d 2 months ago 128MB
k8s.gcr.io/kube-controller-manager v1.22.4 0ce02f92d3e4 2 months ago 122MB
k8s.gcr.io/kube-scheduler v1.22.4 721ba97f54a6 2 months ago 52.7MB
k8s.gcr.io/kube-proxy v1.22.4 edeff87e4802 2 months ago 104MB
k8s.gcr.io/etcd 3.5.0-0 004811815584 7 months ago 295MB
k8s.gcr.io/coredns/coredns v1.8.4 8d147537fb7d 7 months ago 47.6MB
k8s.gcr.io/pause 3.5 ed210e3e4a5b 10 months ago 683kB
python RPC框架-2 简单交互
空闲时间完善了一下RPC交互的demo,
后续有新进展会继续连载。
client.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
import re,json,os,log,uuid errorMessage = ''' ========================================= arkClient useage: client = arkClient() client.call("api.run", args) client.api.run(args) ========================================= ''' from socket import * from time import ctime def run(data): bufsize = 1024 host = '127.0.0.1' port = 8100 addr = (host,port) client_sock = socket(AF_INET,SOCK_STREAM) client_sock.connect(addr) running = True while running: client_sock.sendall(data) data = client_sock.recv(bufsize) print('收到---->%s %s' %(ctime(),data)) running = False client_sock.close() return data.decode("utf-8") class ArkServProxy: """ The service proxy. """ __serviceName__ = None __functionList__ = {} __meta__ = {} def __init__(self, *args, **kwargs): if "__meta__" in kwargs: self.__meta__ = dict(self.__meta__, **kwargs.get("__meta__")) def setServiceName(self, serviceName): self.__serviceName__ = serviceName def __getattr__(self, functionName, *args, **kwargs): if not functionName in self.__functionList__ : self.__functionList__[functionName] = self.FunctionExecutor(__meta__=self.__meta__) self.__functionList__[functionName].setFunctionName(functionName) self.__functionList__[functionName].setServiceName(self.__serviceName__) return self.__functionList__[functionName].execute def __call__(self): raise Exception(errorMessage) def __str__(self): raise Exception(errorMessage) class FunctionExecutor: """ To building the param, call the remote function and get the result. """ __serviceName__ = None __functionName__ = None __meta__ = {} def setFunctionName(self, name): self.__functionName__ = name def setServiceName(self, name): self.__serviceName__ = name def __init__(self, *args, **kwargs): if "__meta__" in kwargs: self.__meta__ = dict(self.__meta__, **kwargs.get("__meta__")) def __call__(self): raise Exception(errorMessage) def __str__(self): raise Exception(errorMessage) def execute(self, *args, **kwargs): log.info("call remote service:" + self.__serviceName__ + "." + self.__functionName__) requestId = str(uuid.uuid4()) meta = { "__serviceName__":self.__serviceName__, "__functionName__":self.__functionName__, "__requestId__":requestId } meta = dict(meta, **self.__meta__) data = { '__meta__': meta, 'data': { 'args': args, 'kwargs': kwargs } } data = json.dumps(data) return run(data.encode()) class ArkServClient: serviceList = {} __meta__ = { "__clientVersion__" : "1.0.0.beta" } def __init__(self, **configs): config_file = 'config.json' if "config_file" in configs: config_file = configs["config_file"] config_file = os.path.abspath(config_file) config_exists = os.path.exists(config_file) if not config_exists: log.error("config file does not exists") else: config_fd = open(config_file) if config_fd.readable(): config = "".join(config_fd.readlines()) config = json.loads(config) print(config.get('ArkServ')) log.info("ArkServClient init!") def __getattr__(self, serviceName): if not serviceName in self.serviceList: self.serviceList[serviceName] = ArkServProxy(__meta__ = self.__meta__) self.serviceList[serviceName].setServiceName(serviceName) return self.serviceList[serviceName] def setMeta(self, meta): keys = meta.keys() for key in keys: if not key in self.__meta__: self.__meta__[key] = meta[key] log.info("key %s merge into meta" % key) else: log.warn("meta key %s exists, not allow merge into meta" % key) def call(self, serviceName, *args, **kwargs): if not re.match('^[\w.]+$', serviceName): raise Exception(errorMessage) service = serviceName.split('.') if service.__len__() == 2: remoteService = self.__getattr__(service[0]) return remoteService.__getattr__(service[1])(*args, **kwargs) else: log.error(errorMessage) raise Exception(errorMessage) ''' 简单的调用测试 ''' client = ArkServClient(config_file="config.json") client.setMeta({"xxxxxxxx":"aaaaaaa"}) res1 = client.member.aaa("xxx2x", a="x1x") print(res1) res3 = client.member.bbb("xxx2xxxxx", c="x1x222222", d={"xxx":"aaaaa"}) print(res3) res2 = client.call("memberaa.aa", "xxxx", a="xx") print(res2) |
python RPC框架-1 客户端demo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import re def error(*args, **kwargs): print('function not exists') errorMessage = ''' ========================================= arkClient useage: client = arkClient() client.call("api.run", args) client.api.run(args) ========================================= ''' class ArkServProxy: _serviceName = None def setServiceName(self, serviceName): self._serviceName = serviceName def __getattr__(self, func, *args, **kwargs): print("call remote service:" + self._serviceName + "." + func) return self.__callFunction def __callFunction(self, *args, **kwargs): print(args) print(kwargs) ret = '此处触发远程调用并取回返回值' return ret def __call__(self): # 屏蔽只有服务名,无函数名的调用 raise Exception(errorMessage) def __str__(self): # 屏蔽远程对象转字符串 raise Exception(errorMessage) class ArkServClient: serviceList = {} ''' 定义第一种远程调用模式,通过 client.服务名.函数名(参数) 类似本地方法直接调用的模式,执行并获取返回值。 demo: client = ArkServClient() ret = client.member.info("参数", uid="123") print(ret) ''' def __getattr__(self, serviceName): if not serviceName in self.serviceList: self.serviceList[serviceName] = ArkServProxy() self.serviceList[serviceName].setServiceName(serviceName) return self.serviceList[serviceName] ''' # 定义第二种远程调用模式,通过 client.call("服务名.函数名", (参数)) 来执行并获取返回值。 demo: client = ArkServClient() ret = client.call("membera.info", "参数", uid="123") print(ret) ''' def call(self, serviceName, *args, **kwargs): if not re.match('^[\w.]+$', serviceName): raise Exception(errorMessage) service = serviceName.split('.') if service.__len__() == 2: remoteService = self.__getattr__(service[0]) return remoteService.__getattr__(service[1])(*args, **kwargs) else: raise Exception(errorMessage) client = ArkServClient() res1 = client.member.aaa("xxx2x", a="x1x") print(res1) res2 = client.call("membera.aa", "xxxx", a="xx") print(res2) |
最简单的推荐系统实践
参考网络上的部分资料,做了个最简单的推荐系统的demo实例。
我们将使用MovieLens数据集,它是在实现和测试推荐引擎时所使用的最常见的数据集之一,包含来自943个用户以及精选的1682部电影的评分。
数据的下载地址:ml-100k
直接上代码,具体的说明在注释里。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#!/usr/bin/env python #coding:utf-8 import numpy as np import pandas as pd import time from sklearn import cross_validation as cv from sklearn.metrics.pairwise import pairwise_distances from sklearn.metrics import mean_squared_error from math import sqrt def read_file(): header = ['user_id', 'item_id', 'rating', 'timestamp'] df = pd.read_csv("/Users/lei.wang/data/ml-100k/u.data",sep = '\t',names = header) #去重之后得到一个元祖,分别表示行与列,大小分别为943与1682 n_users = df.user_id.unique().shape[0] n_items = df.item_id.unique().shape[0] print 'all users is :' + str(n_users) + ', all items is :' + str(n_items) #将样本分为训练集与测试机 train_data,test_data = cv.train_test_split(df,test_size = 0.25) train_data_matrix = np.zeros((n_users,n_items)) for line in train_data.itertuples(): train_data_matrix[line[1]-1, line[2]-1] = line[3] test_data_matrix = np.zeros((n_users,n_items)) for line in test_data.itertuples(): test_data_matrix[line[1]-1,line[2]-1] = line[3] #计算user相似矩阵与item相似矩阵,大小分别为943*943,1682*1682 user_similar = pairwise_distances(train_data_matrix, metric = "cosine") item_similar = pairwise_distances(train_data_matrix.T, metric = "cosine") return (train_data_matrix,test_data_matrix,user_similar,item_similar) train_data_matrix,test_data_matrix,user_similar,item_similar = read_file() print 'user_similar.shape is :',user_similar.shape print 'item_similar.shape is :',item_similar.shape def predict(rating, similar, type = 'user'): if type == 'user': mean_user_rating = rating.mean(axis = 1) rating_diff = (rating - mean_user_rating[:,np.newaxis]) pred = mean_user_rating[:,np.newaxis] + similar.dot(rating_diff) / np.array([np.abs(similar).sum(axis=1)]).T elif type == 'item': pred = rating.dot(similar) / np.array([np.abs(similar).sum(axis=1)]) return pred user_prediction = predict(train_data_matrix, user_similar, type = 'user') item_prediction = predict(train_data_matrix, item_similar, type = 'item') def rmse(prediction,ground_truth): prediction = prediction[ground_truth.nonzero()].flatten() ground_truth = ground_truth[ground_truth.nonzero()].flatten() return sqrt(mean_squared_error(prediction, ground_truth)) print 'User based CF RMSE: ' + str(rmse(user_prediction, test_data_matrix)) print 'Item based CF RMSe: ' + str(rmse(item_prediction, test_data_matrix)) |
文章来源:bitcarmanlee
Windows 10秋季创意者更新 Build 16193 ISO镜像下载
今天早些时候,微软在为Windows 10四个正式版发布累积更新补丁,与此同时,还放出了Build 16251秋季创意者更新的ISO镜像。新特性方面,微软允许安卓手机和电脑合二为一,即跨设备同步浏览(iPhone、安卓均已支持)。二是免打开浏览器可在小娜中直接获取网页搜索结果,三是小娜的语音命令(目前仅英语)现在可以直接实现锁定、睡眠、关机和重启电脑等高阶操作。
可供下载的ISO有:
Windows 10 Insider Preview – Build 16251
Windows 10 Insider Preview Enterprise(企业版) – Build 16251
Windows 10 Insider Preview Education (教育版)- Build 16251
Windows 10 Insider Preview Home Single Language (家庭单语言版)- Build 16251
Windows 10 Insider Preview Home China (中国家庭版)- Build 16251
不过需要注意的是,下载安装该镜像需要绑定为Insider会员的微软账号。
官方下载页面如下:https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewadvanced
基于约束的SQL攻击
值得庆幸的是如今开发者在构建网站时,已经开始注重安全问题了。绝大部分开发者都意识到SQL注入漏洞的存在,在本文我想与读者共同去探讨另一种与SQL数据库相关的漏洞,其危害与SQL注入不相上下,但却不太常见。接下来,我将为读者详细展示这种攻击手法,以及相应的防御策略。
背景介绍
最近,我遇到了一个有趣的代码片段,开发者尝试各种方法来确保数据库的安全访问。当新用户尝试注册时,将运行以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php // Checking whether a user with the same username exists $username = mysql_real_escape_string($_GET['username']); $password = mysql_real_escape_string($_GET['password']); $query = "SELECT * FROM users WHERE username='$username'"; $res = mysql_query($query, $database); if($res) { if(mysql_num_rows($res) > 0) { // User exists, exit gracefully . . } else { // If not, only then insert a new entry $query = "INSERT INTO users(username, password) VALUES ('$username','$password')"; . . } } |
使用以下代码验证登录信息:
跨平台重签ios应用 – python解决方案 isign
A tool and library to re-sign iOS applications, without proprietary Apple software.
For example, an iOS app in development would probably only run on the developer’s iPhone. isign can alter the app so that it can run on another developer’s iPhone.
Apple tools already exist to do this. But with isign, now you can do this on operating systems like Linux.
https://github.com/saucelabs/isign
注意,有些细微的坑,不建议用于生产。