首页 文章 精选 留言 我的

精选列表

搜索[腾讯极客挑战赛],共10001篇文章
优秀的个人博客,低调大师

(牛客腾讯思维编程题)编码编码分组打印下标(java 版本+ C版本)

假定一种编码的编码范围是a ~ y的25个字母,从1位到4位的编码,如果我们把该编码按字典序排序,形成一个数组如下: a, aa, aaa,aaaa, aaab, aaac, … …, b, ba, baa, baaa, baab, baac … …, yyyw, yyyx,yyyy 其中a的Index为0,aa的Index为1,aaa的Index为2,以此类推。 编写一个函数,输入是任意一个编码,输出这个编码对应的Index. 输入描述: 输入一个待编码的字符串,字符串长度小于等于100. 输出描述: 输出这个编码的index 示例1 输入 baca 输出 16331 题目解析点击进入 JAVA import java.util.*; public class Main { public static int number(String str) { int add = str.length()-1;//要考虑到字符串的长度 int mul1 = 1 + 25 + 25*25 + 25*25*25;//从左往右,第一位(进位所需要乘以的数值) int mul2 = 1 + 25 + 25*25;//第二位 int mul3 = 1 + 25;//第三位 int mul4 = 1;//第四位 int[] mul = new int[4];//把上面的四个数放到数组里,以便在下面的循环中使用 mul[0] = mul1; mul[1] = mul2; mul[2] = mul3; mul[3] = mul4; char[] ch = str.toCharArray(); int result = 0; for(int i = 0;i < ch.length;i++) { result += (ch[i] - 'a')*mul[i]; } result += add;//最后把长度考虑进去,不然会出现错误,比如a和aa都会返回0 return result; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.next(); scanner.close(); int result = number(str); System.out.println(result); } } C /* * 五笔编码 * * 五笔的编码范围是a ~ y的25个字母,从1位到4位的编码,如果我们把五笔的编码按字典序排序,形成一个数组如下: * a, aa, aaa, aaaa, aaab, aaac, … …, b, ba, baa, baaa, baab, baac … …, yyyw, yyyx, yyyy * 其中a的Index为0,aa的Index为1,aaa的Index为2,以此类推。 * 编写一个函数,输入是任意一个编码,比如baca,输出这个编码对应的Index; * 编写一个函数,输入是任意一个Index,比如12345,输出这个Index对应的编码。 */ void WubiIndex(const string &input) { const int NUM = 25; const char* p = input.c_str(); int index = 0; int N = 3; int SUM[4] = {1}; for(int i = 1; i < 4; ++i) SUM[i] = NUM * (SUM[i-1]) + 1; while(*p) { int temp = 0; index += (*p -'a')*SUM[N--]; ++p; } cout<<"index is "<<index<<endl; } void WubiCoding(int index) { const int NUM = 25; int SUM[4] = {1}; for(int i = 1; i < 4; ++i) SUM[i] = NUM * (SUM[i-1]) + 1; char ch[5] = {'\0'}; int N = 3; int M = 0; while(index > 0) { ch[M++] = 'a' + (index - 1)/SUM[N]; index = (index - 1)%SUM[N--]; } cout<<"string is "<<ch<<endl; }

优秀的个人博客,低调大师

无限极分类

$arr = array( 0=>[ 'id'=>1, 'name'=>'科技', 'pid'=>0, ], 1=>[ 'id'=>2, 'name'=>'人工智能', 'pid'=>1, ], 2=>[ 'id'=>3, 'name'=>'美食', 'pid'=>0 ], 3=>[ 'id'=>4, 'name'=>'重庆小面', 'pid'=>3 ], 4=>[ 'id'=>5, 'name'=>'机器人', 'pid'=>2 ] ); public function category($arr,$pid=0,$level=0){ //定义一个静态变量,存储一个空数组,用静态变量,是因为静态变量不会被销毁,会保存之前保留的值,普通变量在函数结束时,会死亡,生长周期函数开始到函数结束,再次调用重新开始生长 //保存一个空数组 static $list=array(); //通过遍历查找是否属于顶级父类,pid=0为顶级父类, foreach($arr as $value){ //进行判断如果pid=0,那么为顶级父类,放入定义的空数组里 if($value['pid']==$pid){ //添加空格进行分层 $arr['level']=$level; $list[]=$value; //递归点,调用自身,把顶级父类的主键id作为父类进行再调用循环,空格+1 self::category($arr,$value['id'],$level+1); } } return $list;//递归出口 } $list = category($arr,0,0);

优秀的个人博客,低调大师

Macaca 极简教程

macaca.jpg Macaca 介绍 教程 image.png 源码空间:https://github.com/macacajs 模块拆分讲解: Macaca 1. macaca-cli Macaca提供的命令行工具 $macaca server 启动server $macaca server --verbose 启动server并打印详细日志 $macaca doctor 检验当前macaca环境配置 2. app-inspector macaca提供的元素查找工具,可以将app视图的结构以布局结构树的格式在浏览器上展示出来,用过点击某个元素,就可以方便的查询到该控件的基本信息,以方便查找。具体使用可参考官网: https://macacajs.com/inspector 3. UI Recorder macaca提供的脚本录制工具,可以通过录制获得脚本,对于入门同学很有帮助。https://macacajs.com/recorder WebDriver-Server Macaca是按照经典的Server-Client设计模式进行设计的,也就是我们常说的C/S架构。WebDriver-server部分便充当了server这部分的角色,他的职责就是等待client发送请求并做出响应。 WebDriver-Client client端简单来讲就是我们的测试代码,我们测试代码中的一些行为,比如控件查找、点击等,这些行为以http请求的方式发送给server,server接收请求,并执行相应操作,并在response中返回执行状态、返回值等信息。 也正是基于这种经典的C/S架构,所以client端具有跨语言的特点,macaca-wd,wd.java,wd.py分别是Macaca团队针对Js Java 以及Python的封装,只要能保证client端按照指定的要求发送Http请求,任意语言都可以。 DriverList 自动化要在不同的平台上跑,需要有对应平台的驱动,这部分驱动接收到来自server的操作命令,驱动各自平台的底层完成对应的操作。 1. Android Macaca针对安卓平台的驱动集合 macaca-android 安卓驱动 macaca-adb 封装了安卓的adb命令,来实现一些adb的操作,比如安装、卸载、启动app、获取设备列表这些操作 android-unicode 经过封装后的输入法,解决中文输入的问题 uiautomator-client 将来自server的操作指令转换为UIAutomator可以识别的指令,驱动uiautomator完成对应的操作 android-performance 用于自动化测试安卓性能相关的支持 2. iOS Macaca针对iOS平台的驱动集合 macaca-ios iOS驱动 xctest-client 同安卓的uiautomator-client异曲同工,对XCUITest的封装,将来自server的操作指令转换为XCUITest可以识别的指令,驱动XCUITest完成对应的操作 ios-simulator 用于对ios模拟器的支持,可以通过模拟器运行用例 remote-debug 用于远程调试 3. Hybrid Macaca针对Hybrid的驱动集合。 macaca-chrome web测试驱动 macaca-chromedriver 驱动chrome浏览器 ios-webkit-debug-proxy 适用于iOS平台对webview的调试 4. Electron Macaca针对pc端网页应用的支持 macaca-electron 快速开始:从无到有搭建 Macaca 环境 (forMac) https://macacajs.com/zh/quick-start 基础环境准备 安装Homebrew 参考官网 简易安装步骤(最新可参考官网) $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 安装Node和npm $ brew install node 安装后可以用node -v查看版本号,如果正常则说明安装成功,Macaca2.0要求当前node版本要高于6.0,如果以前安装过低版本的Node,可以通过如下命令更新Node版本: $brew upgrade node 安装cnpm https://cnpmjs.org/ npm是node.js的包管理工具,可以用他来安装和更新各种node的pacakage,可以理解为Java中Maven类似的作用,但是由于众所周知的那堵墙,直接用npm安装速度会非常慢,这种情况下可以安装阿里巴巴提供的cnpm,cnpm提供了国内的镜像,可以加快包的下载速度,安装方法如下: 命令行工具输入如下命令: $npm install -g cnpm --registry=https://registry.npm.taobao.org 如果在安装过程中提示 Permission 权限相关错误,可以尝试 USER /usr/local,永久破除 sudo 要求。 安装成功后同样可以通过cnpm -v来验证安装是否成功,安装成功后,在原来使用npm的地方,直接替换成cnpm即可, 比如,原始命令为 $npm i -g macaca-cli 替换后为: $cnpm i -g macaca-cli Macaca相关安装 iOS 如果不针对iOS作自动化,可以忽略此处 安装XCode(依赖Mac电脑,AppStore下载即可) 安装相关工具 $ brew install usbmuxd$ brew install ios-webkit-debug-proxy $ brew install carthage Android 安装JDK Macaca支持JDK7及以上,可到官网选择对应版本安装 官网下载 注意安装后需要配置JAVA_HOME环境变量,如果本地命令行工具用的是mac系统的默认命令行工具,将其配置到 ~/.bashprofile中,如果用的是zsh,将其配置到 ~/.zshrc中,如下: export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home" 环境变量修改后需要source一下进行更新,比如如果修改的是~/.zshrc,需要执行$source ~/.zshrc 更新后执行echo $JAVA_HOME 如果能正常打印出环境变量,则证明环境变量已经配置成功. 安装Android Studio 官方安装 3.安装gradle(用于打包UIAutomatorWD) $ brew install gradle 配置gradle环境变量,如果本地命令行工具用的是mac系统的默认命令行工具,将其配置到/.bashprofile中,如果用的是zsh,将其配置到/.zshrc中,如下: export GRADLE_HOME="/usr/local/bin/gradle" 环境变量修改后需要source一下进行更新,比如如果修改的是~/.zshrc,需要执行$source ~/.zshrc 更新后执行GRADLE_HOME 如果能正常打印出环境变量,则证明环境变量已经配置成功 4.安装&配置安卓sdk 通过AndroidStudio内的sdkmanager安装安卓依赖的sdk版本,操作路径: AndroidStudio -> Tools -> Android -> SDK Manager image 需要安装的依赖: SDK Platforms : Android 6.0及以上版本 SDK Tools: Android SDK Platform-Tools && Android SDK Tools && NDK 具体勾选效果如下: image image 上面第一张图中红框标记的ANDROID_HOME地址是安卓SDK的路径,需要配置到环境变量中,配置方法同gradle一样 如上都配置好后,需要将两个环境变量拼接到系统的PATH变量中,全部配置完成后的内容如下: image Macaca命令行工具安装 macaca-cli为macaca的命令行工具,集成了macaca doctor等命令 $ cnpm i -g macaca-cli // 备注 -g 表示全局安装,如果不加-g参数会在当前目录下安装macaca-cli 驱动安装 执行如下命令安装对应不同平台的驱动,可以选择性安装 $ cnpm i macaca-ios -g // iOS驱动(用于iOS平台自动化)$ cnpm i macaca-android -g // Android驱动(用于安卓平台自动化)$ cnpm i macaca-chrome -g // chrome 驱动$ cnpm i macaca-electron -g // electron 驱动 备注: 当需要更新相应驱动时,直接执行如上的安装命令即可 cnpm i macaca-ios -g 如果提示 xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance 命令行执行如下即可: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer 至此,便完成了完整的Macaca相关环境的安装,此时我们可以通过macaca doctor命令检查当前环境配置: image 如图为常规的Macaca环境配置结果,现在Macaca在环境上做了相对严格的校验,如果有部分依赖安装不成功,会给出相应的提示,针对性解决即可。 https://macacajs.com/ 代码实例 https://github.com/microu2018/macaca-java-biz-sample macaca-chromedriver https://github.com/macacajs/macaca-chromedriver awesome-macaca A curated list of awesome things regarding Macaca ecosystem. Table of Contents Resources Tutorials Examples Clients Tools Inspector Recorder DataHub Marmot Coverage NoSmoke Monkey Testing Computer Vision Page UITest Browser Testing Reporter Bot Other Tools Drivers Video Articles English Chinese Presentations Slides Community Contributing Licence Resources Macaca Official Site Macaca GitHub Macaca Community GitHub Macaca FAQ Tutorials Quick Start Environment Setup CLI Documentation Examples sample-nodejs - Macaca test sample for Node.js sample-java - Macaca test sample for Java sample-python - Macaca test sample for Python react-sample - Macaca test sample for browser React vue-sample - Macaca test sample for browser framework Vue.js webpack-datahub-sample - Webpack proxy middleware sample for DataHub antd-sample - Ant Design sample for DataHub angular-datahub-sample - Angular's ng toolchain sample for DataHub android-datahub-sample - Android sample for DataHub ios-datahub-sample - iOS sample for DataHub macaca-java-biz-framework - A framework for uiautomation business development based on wd.java macaca-java-biz-sample - Sample for Macaca business development based on wd.java macaca-reporter-standalone-sample - Sample for Macaca reporter android-docker-ci-sample - Sample for Macaca docker ci cv-sample-python - Sample for Macaca CV Python macaca_ci_android_ios - Macaca iOS 和 Android 并行测试 po-sample-python - 基于 PageObject 跨平台的设计模式 Clients macaca-wd - Node.js WebDriver Client for Macaca wd.java - Java client binding for Macaca wd.py - Python client binding for Macaca Tools Inspector App-inspector - App-inspector is a mobile UI viewer in browser Recorder UI Recorder - UI Recorder is a UI test case recorder like Selenium IDE DataHub DataHub - Continuous data provider for development, testing, staging and production. datahub-proxy-middleware - DataHub proxy middleware for Express.js datahub-nodejs-sdk - DataHub Node.js SDK datahub-java-sdk - DataHub SDK for Android and Java applications datahub-ios-sdk - DataHub SDK for iOS egg-datahub - Egg.js plugin for Macaca DataHub umi-plugin-datahub - UmiJS plugin for Macaca DataHub Marmot Marmot - Release management suite with continuous delivery support for deployments Coverage web-coverage-sample - Coverage sample for Web android-coverage-sample Coverage sample for Android ios-coverage-sample Coverage sample for iOS NoSmoke NoSmoke - A cross platform UI crawler which scans view trees then generate and execute UI test cases. Monkey Testing zhangzhao4444/Fastmonkey - 非插桩 iOS Monkey, 支持控件,每秒4-5 action事件 baozhida/iosMonkey - 基于 Macaca 和 webdriveragent 模拟 monkey 的执行 mengdegong/iosMonkey - iOS Monkey zalando/SwiftMonkey - A framework for doing randomised UI testing of iOS apps Computer Vision nodecv - Node.js binding to OpenCV nodecv-server - NodeCV server side Page UITest Torchjs - Test framework to light up the world uitest - UI Test framework for Node.js based on Macaca Browser Testing f2etest - F2etest是一个多浏览器兼容性测试整体解决方案 Reporter macaca-reporter - Macaca reporter is a reporter used for mocha and other frameworks Bot macaca-bot - :octocat: bot to resolve the issues and PR of Macaca Other Tools macaca-adb - Node.js wrapper for ADB XCTestWD - A Swift implementation of WebDriver server for iOS that runs on Simulator/iOS devices ios-simulator - Node.js wrapper for iOS simulator UIAutomatorWD - Node.js wrapper for Android UIAutomator iosHookViewId - A solution for ios hook view id android-unicode - Android unicode UTF-7 input apk command-line-test - command-line test tool for Node.js android-performance - Node.js wrapper to android performance with adb Drivers macaca-android - Macaca Android driver macaca-ios - Macaca iOS driver macaca-chrome - Macaca Chrome driver macaca-electron - Macaca Electron driver macaca-puppeteer - Macaca Puppeteer driver Video Macaca Test Framework - Youtube Channels Articles English Can you find XPath for mobile apps? Extract Xpath from App using Macaca Inspector Macaca inspector for Apple Mac - Automation Testing World!! Mobile and Web UI Testing with Macaca and OpenCV Chinese UI 自动化框架调研总结 基于 Node.js 的自动化持续集成 获取 Android 应用的性能 小马 Macaca 入门指引合集 Macaca-Java 版入门指南 Mac OSX 布署 Reliable Macaca 基础原理浅析 应用自动添加控件 ID 探索 Strikingly 团队2017技术展望 Macaca 测试用例单步调试 混合 H5 应用 UI 自动化入门 Android 输入中文的实现 Presentations Slides Automation Facing The Future Community Testerhome Cnodejs StackOverflow Contributing Your contributions and suggestions are always welcome! :smiley: Contributors This project follows the git-contributor spec, auto upated at Sat Apr 21 2018 17:02:08 GMT+0800. License [图片上传失败...(image-c99436-1537499061724)] macaca-wd.js 'use strict'; /** * Query the server's current status. * @summary Support: Android iOS Web(WebView) * @returns {Promise.<Object>} The server's current status. */ function status() {} /** * Create a new session. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-new-session|POST /session} * @param {Object} desired Desired Capabilities * @type session * @returns {Promise.<Object>} */ function init(desired) {} /** * Returns a list of the currently active sessions. * @summary Support: Android iOS Web(WebView) * @returns {Promise.<Array>} */ function sessions() {} /** * Delete the session. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-delete-session|DELETE /session/:sessionId} * @returns {Promise} * @type session */ function quit() {} /** * Get the current context. * @summary Support: Android iOS * @returns {Promise.<string>} */ function currentContext() {} /** * Set the current context. * @summary Support: Android iOS * @param {string} contextRef context reference from contexts * @returns {Promise} */ function context(contextRef) {} /** * Get a list of the available contexts. * @summary Support: Android iOS * @returns {Promise.<Array>} A list of available contexts. */ function contexts() {} /** * Set the amount of time the driver should wait. * @summary Support: Android iOS Web(WebView) * @param {number} ms The amount of time to wait, in milliseconds * @returns {Promise} */ function sleep(ms) {} /** * Take a screenshot of the current page. * @summary Support: Android iOS Web(WebView) * @returns {Promise.<string>} The screenshot as a base64 encoded PNG. */ function takeScreenshot() {} /** * Save the screenshot of the current page. * @summary Support: Android iOS Web(WebView) * @param {str} filepath The path to save the screenshot or left blank (will create a file in the system temp dir). * @returns {Promise.<string>} The filepath of the screenshot. */ function saveScreenshot(filepath) {} /** * Get the current page source. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-get-page-source|GET /session/:sessionId/source} * @returns {Promise.<string>} */ function source() {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @returns {Promise.<Element>} */ function element(using, value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The class name * @returns {Promise.<Element>} */ function elementByClassName(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The css selector * @returns {Promise.<Element>} */ function elementByCss(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The ID attribute * @returns {Promise.<Element>} */ function elementById(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The name attribute * @returns {Promise.<Element>} */ function elementByName(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The text * @returns {Promise.<Element>} */ function elementByLinkText(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The partially text * @returns {Promise.<Element>} */ function elementByPartialLinkText(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The tag name * @returns {Promise.<Element>} */ function elementByTagName(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The XPath expression * @returns {Promise.<Element>} */ function elementByXPath(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @returns {Promise.<Array>} */ function elements(using, value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The class name * @returns {Promise.<Array>} */ function elementsByClassName(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The css selector * @returns {Promise.<Array>} */ function elementsByCss(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The ID attribute * @returns {Promise.<Array>} */ function elementsById(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The name attribute * @returns {Promise.<Array>} */ function elementsByName(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The text * @returns {Promise.<Array>} */ function elementsByLinkText(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The partially text * @returns {Promise.<Array>} */ function elementsByPartialLinkText(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The tag name * @returns {Promise.<Array>} */ function elementsByTagName(value) {} /** * Search for multiple elements on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/elements} * @param {string} value The XPath expression * @returns {Promise.<Array>} */ function elementsByXPath(value) {} /** * All the element-related methods above (except which suffixed with OrNull, IfExists) could be prefixed with the "waitFor-" (need to capitalize the 'e', e.g., waitForElementByClassName) * @summary Support: Android iOS Web(WebView) * @param {string} using The locator strategy to use, omitted when using specific method like waitForElementByClassName. * @param {string} value The css selector * @param {function} [asserter] The asserter function (commonly used asserter function can be found at wd.asserters) (optional) * @param {number} [timeout=1000ms] The timeout before find the element (optional) * @param {number} [interval=200ms] The interval between each searching (optional) * @example waitForElementByClassName('btn', 2000, 100) Search for element which class name is 'btn' at intervals of 100ms, last for 2000ms. * @returns {Promise.<Array>} */ function waitForElement(using, value, asserter, timeout, interval) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @returns {Promise.<Element|null>} */ function elementOrNull(using, value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The class name * @returns {Promise.<Element|null>} */ function elementByClassNameOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The css selector * @returns {Promise.<Element|null>} */ function elementByCssOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The ID attribute * @returns {Promise.<Element|null>} */ function elementByIdOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The name attribute * @returns {Promise.<Element|null>} */ function elementByNameOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The text * @returns {Promise.<Element|null>} */ function elementByLinkTextOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The partially text * @returns {Promise.<Element|null>} */ function elementByPartialLinkTextOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The tag name * @returns {Promise.<Element|null>} */ function elementByTagNameOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The XPath expression * @returns {Promise.<Element|null>} */ function elementByXPathOrNull(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @returns {Promise.<Element|null>} */ function elementIfExists(using, value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The class name * @returns {Promise.<Element|undefined>} */ function elementByClassNameIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The css selector * @returns {Promise.<Element|undefined>} */ function elementByCssIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The ID attribute * @returns {Promise.<Element|undefined>} */ function elementByIdIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The name attribute * @returns {Promise.<Element|undefined>} */ function elementByNameIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The text * @returns {Promise.<Element|undefined>} */ function elementByLinkTextIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The partially text * @returns {Promise.<Element|undefined>} */ function elementByPartialLinkTextIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The tag name * @returns {Promise.<Element|undefined>} */ function elementByTagNameIfExists(value) {} /** * Search for an element on the page, starting from the document root. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The XPath expression * @returns {Promise.<Element|undefined>} */ function elementByXPathIfExists(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} using The locator strategy to use. * @param {string} value The search target. * @type assert * @returns {Promise.<boolean>} */ function hasElement(using, value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The class name. * @type assert * @returns {Promise.<boolean>} */ function hasElementByClassName(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The ID attribute. * @type assert * @returns {Promise.<boolean>} */ function hasElementById(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The name attribute. * @type assert * @returns {Promise.<boolean>} */ function hasElementByName(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The text. * @type assert * @returns {Promise.<boolean>} */ function hasElementByLinkText(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The partially text. * @type assert * @returns {Promise.<boolean>} */ function hasElementByPartialLinkText(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The tag name. * @type assert * @returns {Promise.<boolean>} */ function hasElementByTagName(value) {} /** * Check if element exists. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#elements|POST /session/:sessionId/element} * @param {string} value The XPath expression. * @type assert * @returns {Promise.<boolean>} */ function hasElementByXPath(value) {} /** * Click on an element. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-element-click|POST /session/:sessionId/element/:id/click} * @returns {Promise} */ function click() {} /** * Send a sequence of key strokes to the active element. * @summary Support: Android iOS Web(WebView) * @param {string} keys The keys sequence to be sent. * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-element-send-keys|POST /session/:sessionId/element/:id/sendKeys} * @type element * @returns {Promise} */ function sendKeys(keys) {} /** * Send a sequence of key strokes to the active window. * @summary Support: Android Web(WebView) More: https://github.com/alibaba/macaca/issues/487 * @param {string} keys The keys sequence to be sent. * @returns {Promise} */ function keys(keys) {} /** * Returns the visible text for the element. * @summary Support: Android iOS Web(WebView) * @type element * @returns {Promise.<string>} */ function text() {} /** * Clear a TEXTAREA or text INPUT element's value. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#element-clear|POST /session/:sessionId/element/:id/clear} * @type element * @returns {Promise.<string>} */ function clear() {} /** * Determine if an element is currently displayed. * @summary Support: Android Web(WebView) * @type element * @returns {Promise.<string>} */ function isDisplayed() {} /** * Get the result of a property of a element. * @summary Support: Android iOS Web(WebView). iOS: 'isVisible', 'isAccessible', 'isEnabled', 'type', 'label', 'name', 'value', Android: 'selected', 'description', 'text' * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-get-element-property|GET /session/:sessionId/element/:id/property/:name} * @param {string} name The property name * @type element * @returns {Promise.<string>} */ function getProperty(name) {} /** * Query the value of an element's computed CSS property. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-element-css-value|GET /session/:sessionId/element/:id/css/:propertyName} * @param {string} propertyName The property name * @type element * @returns {Promise.<string>} */ function getComputedCss(propertyName) {} /** * Get the dimensions and coordinates of the given element with a object including x/y/height/width. * @summary Support: Android iOS. * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-get-element-rect|GET /session/:sessionId/element/:id/rect} * @type element * @returns {Promise.<string>} */ function getRect() {} /** * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#executing-script|POST /session/:sessionId/execute} * @param code script * @param [args] script argument array * @returns {Promise.<string>} */ function execute() {} /** * Get the current page title or focus activity or viewController. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#accept-alert|GET /session/:sessionId/title} * @returns {Promise.<string>} */ function title() {} /** * Accepts the currently displayed alert dialog. * @summary Support: Android iOS * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#accept-alert|POST /session/:sessionId/accept_alert} * @returns {Promise.<string>} */ function acceptAlert() {} /** * Dismisses the currently displayed alert dialog. * @summary Support: Android iOS * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dismiss-alert|POST /session/:sessionId/dismiss_alert} * @returns {Promise.<string>} */ function dismissAlert() {} /** * Gets the text of the currently displayed JavaScript alert(), confirm(), or prompt() dialog. * @summary Support: iOS * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#send-alert-text|GET /session/:sessionId/alert_text} * @returns {Promise.<string>} */ function alertText() {} /** * Sends keystrokes to a JavaScript prompt() dialog. * @summary Support: iOS * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#send-alert-text|POST /session/:sessionId/alert_text} * @param keys * @returns {Promise.<string>} */ function alertKeys() {} /** * Retrieve the URL of the current page. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-current-url|GET /session/:sessionId/url} * @returns {Promise.<string>} */ function url() {} /** * Navigate to a new URL. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get|POST /session/:sessionId/url} * @param url get a new url. * @type browser * @returns {Promise.<string>} */ function get() {} /** * Navigate forwards in the browser history, if possible. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#back|POST /session/:sessionId/forward} * @type browser * @returns {Promise.<string>} */ function forward() {} /** * Navigate backwards in the browser history, if possible. * @summary Support: Android Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#back|POST /session/:sessionId/back} * @type browser * @returns {Promise.<string>} */ function back() {} /** * Refresh the current page. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#refresh|POST /session/:sessionId/refresh} * @type browser * @returns {Promise.<string>} */ function refresh() {} /** * Change focus to another window. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#switch-to-window|POST /session/:sessionId/window} * @returns {Promise.<string>} */ function window() {} /** * Close the current window. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#close-window|DELETE /session/:sessionId/window} * @type window * @returns {Promise.<string>} */ function close() {} /** * Retrieve the current window handle. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-window-handle|GET /session/:sessionId/window_handle} * @returns {Promise.<string>} */ function windowHandle() {} /** * Retrieve the list of all window handles available to the session. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-window-handles|GET /session/:sessionId/window_handles} * @returns {Promise.<string>} */ function windowHandles() {} /** * Get the size of the specified window. * @summary Support: Android iOS Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-window-size|GET /session/:sessionId/window/size} * @param [handle] window handle to set size for (optional, default: 'current') * @returns {Promise.<string>} */ function getWindowSize() {} /** * Change the size of the specified window. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#set-window-size|POST /session/:sessionId/window/size} * @param width width in pixels to set size to * @param height height in pixels to set size to * @param [handle] window handle to set size for (optional, default: 'current') * @returns {Promise.<string>} */ function setWindowSize() {} /** * Maximize the specified window if not already maximized. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#dfn-maximize-window|POST /session/:sessionId/window/maximize} * @param handle window handle * @type browser * @returns {Promise.<string>} */ function maximize() {} /** * Change focus to another frame on the page. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#switch-to-frame|POST /session/:sessionId/frame} * @param {string|number|null} frameRef Identifier(id/name) for the frame to change focus to * @returns {Promise.<string>} */ function frame(frameRef) {} /** * Apply touch actions on devices. * @summary Support: iOS, Android * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#actions|POST /session/:sessionId/actions} * @param {string} action Name of the action, tap/doubleTap/press/pinch/rotate/drag. * @param [object] args Parameters of the action {@link https://github.com/alibaba/macaca/issues/366 more params} * @example driver.touch('doubleTap', {x: 100, y: 100}); * @returns {Promise.<string>} */ function touch(action, args) {} /** * Returns all cookies associated with the address of the current browsing context’s active document. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#get-all-cookies|GET /session/:sessionId/cookie} * @returns {Promise.<string>} */ function allCookies() {} /** * Adds a single cookie to the cookie store associated with the active document’s address. {url: 'https://macacajs.github.io', name:'foo', value:'bar'} Optional cookie fields: secure, expiry * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#add-cookie|POST /session/:sessionId/cookie} * @returns {Promise.<string>} */ function setCookie() {} /** * Delete either a single cookie by parameter name, or all the cookies associated with the active document’s address if name is undefined. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#delete-cookie|DELETE /session/:sessionId/cookie/:name} * @returns {Promise.<string>} */ function deleteCookie() {} /** * Allows deletion of all cookies associated with the active document’s address. * @summary Support: Web(WebView) * @see {@link https://w3c.github.io/webdriver/webdriver-spec.html#delete-all-cookies|DELETE /session/:sessionId/cookie/:name} * @returns {Promise.<string>} */ function deleteAllCookies() {} const helper = require('./helper'); const wd = require('../wd/lib/main'); module.exports = wd; module.exports.helper = helper; module.exports.webpackHelper = helper(wd);

优秀的个人博客,低调大师

Docker极简入门

一、Docker概述 Docker通过一个包括应用程序运行时所需的一切的可执行镜像启动容器,包括配置有代码、运行时、库文件、环境变量和配置文件等。 1.文件系统隔离:每个容器都有自己得root文件系统。 2.进程隔离:每个容器都运行再自己得进程环境中。 3.容器间得虚拟网络接口和IP地址都是分开的。 4.资源隔离和分组:使用cgroup将CPU和内存之类的资源独立分配给每个Docker容器。 5.写时复制:文件系统都是通过写时复制创建的,这就意味着文件系统是分层的、快速的,并且占用磁盘空间小。 6.日志:容器产生的STDOUT、STDIN和STDERR这些IO流都会被收集并记入日志,用来进行日志分析和故障排除。 7.交互式shell:用户可以创建一个伪tty终端、将其连接到STDIN,为容器提供一个交互式shell。 8.灵活性:大多数应用程序均能被装箱。 9.轻量级:容器利用并共享主机内核。 10.可交互:可以即时的更新和升级。 11.可移植:一处构建,到处运行。 12.可扩展性:可以增加和分发容器副本。 二、Docker容器的安装与入门 1.Docker的安装过程很简单,本次试验是在CentOS7.4中进行的,因此不存在内核版本及系统平台不支持的情况。简单的安装配置如下: [root@ChatDevOps ~]# yum -y install docker [root@ChatDevOps ~]# docker --version Docker version 1.13.1, build 94f4240/1.13.1 [root@ChatDevOps ~]# systemctl start docker [root@ChatDevOps ~]# systemctl status docker [root@ChatDevOps ~]# systemctl enable docker [root@ChatDevOps ~]# docker info 2.docker info:返回所有容器和镜像的数量、Docker使用的执行驱动和存储驱动及Docker的基本配置。 [root@ChatDevOps ~]# docker info Containers: 15 Running: 1 Paused: 0 Stopped: 14 Images: 4 Server Version: 1.13.1 ... ... 3.docker images:列出当前系统中本地镜像。例如,列出本地镜像中REPOSITORY为ubuntu的镜像: [root@ChatDevOps ~]# docker images ubuntu REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/ubuntu latest 452a96d81c30 3 weeks ago 79.6 MB 4.docker ps:列出所有正在运行的容器。 [root@ChatDevOps ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e93e508dbc38 centos "/bin/bash" 2 hours ago Up 2 minutes fervent_turing 加上选项-a则列出的是所有的容器,包括正在运行的和未运行的。加选项-n则代表列出前n个容器,n后面跟需要列出的容器的个数。 [root@ChatDevOps ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dfd4fe17d6ce httpd "/bin/bash" 2 hours ago Exited (0) 43 minutes ago stoic_gates 7b4ddbb18811 ubuntu "/bin/bash" 2 hours ago Exited (0) 43 minutes ago priceless_bassi e93e508dbc38 centos "/bin/bash" 2 hours ago Up About a minute fervent_turing [root@ChatDevOps ~]# docker ps -n 10 docker run:创建一个新的容器并运行一个命令。 [root@ChatDevOps ~]# docker run --name ivandu -i -t centos /bin/bash [root@009c8df5e30d /]# 上面例子中创建了一个名为ivandu的容器。Docker首先检查本地是否存在镜像centos,如果不存在,则会连接到Docker官方维护的Docker Hub Registry,查看Docker Hub是否存在该镜像,如果存在则下载该镜像并保存到本地宿主机。选项-i表示容器的stdin是开启的,选项-t表示为要被创建的容器分配一个伪tty终端,centos表示创建这个容器使用的是centos这个镜像,/bin/bash表示容器创建完成之后执行容器中的该命令。选项-d则会将容器置于后台运行。 5.docker start:启动一个容器,可以是容器的ID和名称(NAMES)。 [root@ChatDevOps ~]# docker start dfd4fe17d6ce dfd4fe17d6ce [root@ChatDevOps ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dfd4fe17d6ce httpd "/bin/bash" 4 hours ago Up 10 seconds 80/tcp stoic_gates e93e508dbc38 centos "/bin/bash" 4 hours ago Up 2 hours fervent_turing [root@ChatDevOps ~]# docker start stoic_gates stoic_gates [root@ChatDevOps ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES dfd4fe17d6ce httpd "/bin/bash" 4 hours ago Up 8 minutes 80/tcp stoic_gates e93e508dbc38 centos "/bin/bash" 5 hours ago Up 2 hours fervent_turing 同理,docker stop及docker restart的用法大同小异。 6.docker attach:可以进入一个已经在运行的容器。命令后面的容器id也可以换成容器名称。需要注意的是,如果退出容器的shell,容器也会随之停止运行。 [root@ChatDevOps ~]# docker start 7b4ddbb18811 7b4ddbb18811 [root@ChatDevOps ~]# docker attach 7b4ddbb18811 root@7b4ddbb18811:/# cat /etc/issue Ubuntu 18.04 LTS \n \l root@7b4ddbb18811:/# exit [root@ChatDevOps ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7.docker rm:删除一个已经停止的容器。如果这个容器正在运行,需要先停止该容器的运行或者使用选项-f进行强制删除。 [root@ChatDevOps ~]# docker rm -f 009c8df5e30d 009c8df5e30d 一次性删除所有的容器: [root@ChatDevOps ~]# docker rm `docker ps -a -q` 8.docker logs:获取容器的日志,我们可以通过该日志了解容器内部正在进行什么样的操作。可以跟选项-f,类似于tail命令,显示日志最后部分。选项-t则为每条日志加上了时间戳。 [root@ChatDevOps ~]# docker logs -tf dfd4fe17d6ce 2018-05-22T05:35:24.196281000Z root@dfd4fe17d6ce:/usr/local/apache2# exit root@dfd4fe17d6ce:/usr/local/apache2# 2018-05-22T08:56:00.809591000Z root@dfd4fe17d6ce:/usr/local/apache2# ls 2018-05-22T08:56:00.811456000Z bin build cgi-bin conf error htdocs icons include logs modules 2018-05-22T08:56:06.779932000Z root@dfd4fe17d6ce:/usr/local/apache2# ps -aux 2018-05-22T08:56:06.782810000Z USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 2018-05-22T08:56:06.783173000Z root 1 0.0 0.1 20236 1980 ? Ss 08:40 0:00 /bin/bash 2018-05-22T08:56:06.783462000Z root 6 0.0 0.1 17492 1144 ? R+ 08:56 0:00 ps -aux 2018-05-22T08:56:19.520653000Z root@dfd4fe17d6ce:/usr/local/apache2# httpd -k start 2018-05-22T08:56:19.550996000Z AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message 2018-05-22T08:57:01.656035000Z root@dfd4fe17d6ce:/usr/local/apache2# cat /etc/issue 2018-05-22T08:57:01.656305000Z Debian GNU/Linux 8 \n \l 2018-05-22T08:57:01.656609000Z 2018-05-22T08:57:07.888609000Z root@dfd4fe17d6ce:/usr/local/apache2# exit 2018-05-22T08:57:07.888981000Z exit 9.docker top:查看正在运行的容器内部的进程运行情况。停止的容器并不支持此法进行查看。 [root@ChatDevOps ~]# docker start 7bc9a41a53cd 7bc9a41a53cd [root@ChatDevOps ~]# docker top 7bc9a41a53cd UID PID PPID C STIME TTY TIME CMD root 6869 6855 0 17:26 pts/0 00:00:00 /bin/bash 10.docker exec:在一个运行中的容器内部执行命令或者进入一个正在运行的容器内。选项-d表示命令在后台执行,-d后跟容器名和要执行的命令。也可以通过选项-i和-t搭配使用进入一个正在运行的容器,与attach不同的是,如果退出容器的shell,该容器并不会停止运行。 [root@ChatDevOps ~]# docker exec -d 7bc9a41a53cd touch /home/ChatDevOps.log [root@ChatDevOps ~]# docker exec -i -t 7bc9a41a53cd /bin/bash [root@7bc9a41a53cd /]# ll /home/ChatDevOps.log -rw-r--r--. 1 root root 0 May 22 09:40 /home/ChatDevOps.log 11.docker inspect:返回一个低水平的Docker对象信息。可以用选项-f或--format来获取选定结果。支持完整的go语音模板,可以充分利用go语音的优势。 [root@ChatDevOps ~]# docker inspect dfd4fe17d6ce [ { "Id": "dfd4fe17d6ce1e17ca55e741c6979b16b32383c909ad2145f1c1fcb231612ecf", "Created": "2018-05-22T04:03:10.289044219Z", "Path": "/bin/bash", "Args": [], "State": { ... ... [root@ChatDevOps ~]# docker inspect --format='{{.State.Running}}' dfd4fe17d6ce false [root@ChatDevOps ~]# docker inspect --format='{{.NetworkSettings.IPAddress}}' 7bc9a41a53cd 172.17.0.2 12.docker kill:杀死一个或多个正在运行的容器。 [root@ChatDevOps ~]# docker kill 7bc9a41a53cd 7bc9a41a53cd 三、总结 通过本篇,我们了解了Docker的优点及简单入门知识。文中并未进行大量详细的原理性的内容阐述,主要通过实践来演示一入门常用的一些命令及其使用注意事项。以此来加深对Docker原理的理解。本篇博文是来北京工作后的第一篇文章,纪念一下。

优秀的个人博客,低调大师

梯度下降极简入门

导 语 梯度下降及其变体被用作训练过程的关键部分在机器学习中广泛使用。梯度下降中的“梯度”是指单变量导数的推广形式,即多元变量求导。 梯度下降法是解决“优化问题”的迭代方法,其中优化问题是指围绕寻找函数的全局最小值或最大值而展开的数学问题。我们将很快看到,对于简单的优化问题可以不用梯度下降。当事情变得复杂时,我们则需要用诸如梯度下降之类的迭代法,当然和神经网络相关的优化问题确实足够复杂。 01 重新回顾优化问题 假设你已经购买了200米的铁丝网。您想使用此围栏为羊群创建一个矩形牧场。如何确定使牧场内部面积最大化时,牧场对应的长度和宽度? 使用标准的分析方法来解决这个问题,我们首先要写一个方程式来表示我们的问题。首先,我们知道两件事: area(面积)=length(长度)*width(宽度)(2 * length)+(2 * width)= 200 但是我们想用一个变量而不是两个变量来表示面积,所以我们可以求解这两个方程中的第二个变量的宽度: 2 * width = 200–2 * lengthwidth = [200-2 * length] / 2width = 100 - length 现在我们可以用100- length代替width,则: area= length * [100–length]area = f(length)=100 * length- length² 取面积的导数: area’=100-2*length;length=50 现在,我们找到了函数的“临界点”,即一阶导数等于零时对应的长度,当然函数在该点处的斜率也为零。我们关心这种值,因为它们是唯一能对应函数最小值或函数最大值的数。在临界点处,该点两侧的值可能都小于或都大于临界点处的值。因为函数中该点外的斜率都不为零,这意味着临界点上一边的点对应的面积将小于该临界点对应的面积,而另一边的点对应的面积将大于该临界点对应的面积。也就是说,该函数在非临界点处正在增加或减少,因此不能为最大值或最小值。 area’=100-2*length=0-->length=50 这表明如果存在全局最大值或最小值,则必须在长度= 50时发生。也就是说,如果矩形的长度存在最佳选择,则为50米。可能存在临界点既不是最小值也不是最大值,所以应该检测已发现的临界点确实是最值。在微积分课程中,有相关的检验方法(比如二阶导数检验),现在用更简单的方法(类似梯度下降法)来解决该问题,比如在临界点长度= 50的左右两侧测试2个点。 f(49)= 4900–2401 = 2499f(50)= 5000–2500 = 2500f(51)= 5100–2601 = 2499 这并不能确认矩阵面积最大时对应长度值就是50,或者某些时候有比50更好的点,不过这种近似的方法最终将应用于训练模型。对于这个简单的问题,通过绘制函数了解该方法和实际的误差: 02 梯度下降—迭代式猜测 那么这与梯度下降方法有什么关系呢?梯度下降方法比较粗糙,就像刚才所做的那些不精确的猜测一样。看上去它是比随机猜测稍强一点的显得杂乱的体系,不过它将最终成为我们解决围栏问题的方法: 猜测围栏的最佳长度 计算此时的梯度值 根据梯度的值,调整猜测 重复猜测直到满足条件则终止 假设我们随机选取57当作长度的第一个猜测值,在57处,面积函数的导数为: f(57)=100*57 - 57*57 = 2451f'(57)=100–2*(57)=-14 ‍ length = 57处的斜率不为0,因此不是临界点。此外斜率为-14表示如果将长度增加 1,则面积将减小 14(假设函数的斜率不变)。梯度下降使用此值作为进行下一个猜测的指导。比如要增加面积的值,因为斜率是负数,所以应该57基础上减小长度,以此增加面积的值。 然而即使知道当前应该减少length的值,也没有先验的方法可以确切地知道“合适”的数来调整我们的当前的猜测(length=57)。在像TensorFlow这样的软件包中,我们用来调整当前length的快慢将由一个称为“学习率”的超参数控制,可以在训练时设置该参数。提高学习率将导致梯度下降对当前当前length调整很快;减小学习率会导致梯度下降对当前当前length调整较慢。现在假设将当前length减少3,虽然有点武断,但实际上效果可以接受。 57–3 = 54f(54)= 5400–(54²)-->f(54)= 5400–2916 -->f(54)= 2484 2484大于2451,说明找到的面积比上次大。再次使用导数来检查是否处于临界点,如果不是,则调整猜测值: f'(54)= 100–2 * 54 = 100–108 = -8 我们的当前猜测值(54)仍然很大,斜率-8低于-14,应该适当减缓对当前猜测值的更改幅度,比如在54基础上减少2,则: f(52)= 5200–52² --> f(52)= 5200–2704 -->f(52)= 2496 我们将重复此过程,直到找到一个临界点。或者直到f'(length)的值非常接近零,才能认为length已足够接近临界点。手工完成此过程是重复且繁琐的,但是计算机善于解决重复繁琐的任务。通俗点说,将像在爬山和滚球,一直沿着抛物线上升,直到无法进一步上升为止。 请注意导数(蓝色),它在最大值的右边是负数,在最大值的左边是正数。在这种情况下,很容易找到最大值。 由于试图找到面积的最大值,上面的示例称之为“梯度上升”更好。在梯度下降中,每次计算梯度值时都将其相反数。 马上将提到的梯度下降和在神经网络里面用到的梯度下降有两个不一样的地方。首先,神经网络对应的函数比f(length)更复杂。我们的神经网络具有成千上万的可调参数,而其中f(length)只有一个。我们使用诸如梯度下降之类的迭代方法主要是因为神经网络模型非常复杂,而不是选用之前查找临界点时的分析过程。计算当前如此庞大规模的神经网络所表示的一般性的函数导数根本不可行。第二个区别是,在此示例中,有一个充当标准结果的实函数,并且发现了该函数的最佳值。在神经网络中,没有显式的函数;取而代之的是,我们尝试创建一个不存在标准结果的函数。 03 用于函数查找的梯度下降 在前面的示例中,使用梯度下降方法沿该曲线可以找到最佳值。在机器学习中,对于训练集中的数据,我们希望创建一条曲线来更好地拟合这些数据。回顾一下刚刚研究的围栏问题,将它转化为我们更倾向于用机器学习解决的问题。 我们从围栏数据库中收集了很多数据样本。我们数据集中的每个数据点的背景都是来自用100米围栏材料来建造矩形牧场。每个数据点有2个参数:围栏一侧的长度和围栏的面积。在这个问题中,不是尝试找到围栏的最佳长度,而是试图找到一个函数,该函数可以根据给定的边长来预测矩形围栏的面积。我们的输入数据如下所示: 看起来数据中有一个模式,我们可以使用机器学习来定义模式吗? 机器学习解决此问题的方法是认为:“看起来有点像某种数学函数,想知道到底是哪个函数?”,更进一步,我们猜测该函数是某种抛物线函数,则该函数的一般表达式是: F(x)=ax²+ bx 在数据集中已知x值和y值,现在我们将使用梯度下降法来找到a和b的最佳值。为此,我们引入了另一个函数--损失函数,并运行梯度下降以最小化损失函数。将F(x)当作“正在进行训练的函数”,其中x仍然是围栏一侧的长度,y是围栏的真实面积。单次预测的绝对误差为: L(x)= | F(x)- y | 我们需要给误差加上绝对值。如果不这样做且连续做两次预测,假设一次错了1000,另一次错了-1000,则两次错误刚好抵消,实际上这样一共错了两次。 最终我们会用这样的一个损失函数:平均绝对误差,它是数据集中所有的点对应L(x)的平均值。使用诸如均方误差之类的指标更为常见,但是不同的损失函数对不同的数据集。 假设我们随机选择权重的起始值:a = -2和b = 30。在对应的F(x)变为: L(x)= | -2x²+ 30x-y | 接下来的内容略带技巧性。我们想要调整a和b的值以最小化损失函数。因此我们需要计算损失函数对a和b的梯度(偏导数)。以前的函数中,x的值可以不断变化。但是这个问题里面,情况并非如此。x的值始终只是我们数据集中的某个固定值。因此单个数据点对应的损失函数为:L(a, b) = ax² + bx – y,其中x、y是常数。 使用平均绝对误差的损失函数为: L(a,b)=1/m*SUM(|F(a,b)—yi|)L(a,b)=(1 / m)* SUM(|axi²+ bxi — yi |) 其中xi和yi代表我们数据集中的单个数据点,而m是我们数据集中点的总数。这里有两个细节上的问题:一个是我们必须使用链式规则来计算涉及绝对值的梯度;另一个是绝对值函数在预测值恰好等于真实值的点上是不可求导的,并且。 如果平均绝对误差为0,可以通过停止计算梯度来解决不可导的问题。这是有实际意义的。如果我们在这个数据点上的预测值与实际值都符,那么就不需要用改善绝对误差的方式来调整模型: d | x |/ dx = 1,如果x为正d | x |/ dx = -1,如果x为负则损失函数对a、b求偏导数可以写成:L(a, b) = (1/m) * SUM( | axi² + bxi — yi | )L’_a(a, b) = (1 / m) * SUM( 1 * xi² ); F(xi) > yiL’_a(a, b) = (1 / m) * SUM( -1 * xi² ); F(xi) < yiL’_b(a, b) = (1 / m) * SUM( 1 * x ); F(xi) > yL’_b(a, b) = (1 / m) * SUM( -1 * x );F(xi) < yi 这些公式实际上为我们提供了一个非常简单的更新规则:如果我们的预测太小,则将a和b都增大。如果我们的预测太大,则将a和b都减小。 深刻地理解梯度下降以及优化损失函数的思路可以更好地理解过拟合之类的问题,同时它还可以帮助我们更好地了解神经网络训练的过程。 1 END 1 长 按 关 注 获取最新AI资讯与实战案例 实用AI客栈 小编微信号 : langu86 本文分享自微信公众号 - 实用AI客栈(gh_0b0b5e56231f)。如有侵权,请联系 support@oschina.cn 删除。本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

优秀的个人博客,低调大师

极简模板语言实现

在项目中遇到这样一个功能,需要用户输入一段带参数的字符串模板,然后服务端根据一个上下文去解析它。查了一些资料发现了StrSubstitutor 这个小工具。其自带例子如下: Map valuesMap = HashMap(); valuesMap.put("animal", "quick brown fox"); valuesMap.put("target", "lazy dog"); String templateString = "The ${animal} jumped over the ${target}."; StrSubstitutor sub = new StrSubstitutor(valuesMap); String resolvedString = sub.replace(templateString

优秀的个人博客,低调大师

极简Mybatis之旅(一):CRUD

摘要 最近在研究mybatis框架,作为一个优秀ORM框架,mybatis很多优秀的设计思想值得借鉴。 mybatis的配置文件里,主要是config和mapper。config定义了全局参数:数据源类型(POOL, UNPOOLED, JNDI)、事务管理类型(默认为managed)、库url、账户信息和mapper文件路径。 config配置 // config.xml <configuration> <environments default="classfly"> <environment id="classfly"> <transactionManager type="JDBC"/> <dataSource type="POOLED"> <property name="driver" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/test?characterEncoding=utf-8" /> <property name="username" value="yourusername" /> <property name="password" value="yourpassword" /> </dataSource> </environment> </environments> <mappers> <mapper resource="mapper/UserMapper.xml" /> </mappers> </configuration> DBNAME='test',是mybatis默认分配的库: mapper配置 首先我们要问自己以下三个问题: 为什么要配置mapper文件? 怎么配置mapper文件? mybatis如何解析mapper文件? mapper文件的作用 mapper文件提供一种持久化层与应用层的"通信协议",通过mysql关键字resultMap, parameterType等维护应用代码DO对象与持久化存储数据之间的关联关系。 mapper文件里定义了select, insert, update, delete四种常用的DML语句,并定义statement={mapper namespace}.{operation}实现在应用代码层执行调用DB操作。 配置mapper文件 这里先给出测试用例用到的mapper配置文件的关键部分: <!-- 代码清单-1 --> <mapper namespace="com.classfly.mapper.UserMapper"> <resultMap id="user" type="pojo.User"> <result column="user_id" property="userId" /> <result column="user_name" property="userName" /> <result column="password" property="password" /> <result column="age" property="age" /> </resultMap> <select id="query" resultMap="user"> SELECT * FROM user; </select> <insert id="insert" parameterType="pojo.User"> insert into user ( user_id, user_name, password, age) values ( #{userId}, #{userName}, #{password}, #{age} ) <selectKey resultType="pojo.User" keyProperty="id" order="AFTER"> select LAST_INSERT_ID() as id </selectKey> </insert> <update id="update" parameterType="pojo.User"> UPDATE user SET user_name = #{userName} , password = #{password} , age = #{age} WHERE user_id = #{userId} </update> <delete id="delete"> DELETE FROM user WHERE user_id = #{userId} </delete> </mapper> mapper namespace定义了DML语句的作用范围,那如果两个不同的mapper文件定义相同的namespace会发生什么?由于mysql保持namespace的全局唯一性,所以在解析mapper文件时mysql会抛异常提示开发者修改mapper文件以保持namespace的全局唯一性。 resultMap resultMap关键字将代码和持久化层的数据映射抽象出来,用户无需关心两者之间如何映射。 我们可以使用HashMap完成代码和持久化层的数据映射关系,不但缺乏通用型且代码层需要将对象转换成map结构。resultMap接受HashMap结构和JavaBean或者POJO对象,提供轻量级的参数映射方案。 resultMap有"别名"的功能,你无需每个DML都写一大串的映射语句,秉着"仅定义一次"的原则,我们可以这么做: // config.xml <typeAlias type="pojo.User" alias="User"/> // 用typeAlias的User别名替换了resultMap中的user <select id="query" resultType="User"> SELECT * FROM user ORDER BY id DESC </select> Now if only the world was always that simple! 当POJO类成员变量并未完全和Table列名"对齐"时,可通过定义resultMap的方式来实现mapper: <resultMap id="user" type="User"> <result property="userId" column="user_id" /> <result property="username" column="user_name"/> <result property="password" column="hashed_password"/> </resultMap> <select id="query" resultMap="user"> SELECT * FROM user ORDER BY id DESC </select> '#'和'$' 从"代码清单-1"里可以看出,#和$均可实现POJO字段和DB表列名的映射关系。#将参数部分用?替换,而$仅根据执行sql时通过POJO对象透传的值进行字符串替换,容易被注入恶意代码,不可取!如: select * from ${tableName} where name = #{name} 如果tableName='user; delete user; --',最终sql语句变为: select * from user; delete user; -- where name = #{name} 导致user整张表数据被删除。 mybatis如何解析mapper文件 To be continued... 测试用例 /** * Created by fujianbo on 2018/4/22. * * @author fujianbo * @date 2018/04/22 */ public class TestMybatis { @Test public void testQuery() { SqlSession sqlSession = buildMySqlEnv("config.xml"); List<User> userList = sqlSession.selectList("com.classfly.mapper.UserMapper.query"); for (User p : userList) { System.out.println(p); } } @Test public void testInsert() { SqlSession sqlSession = buildMySqlEnv("config.xml"); User user = new User(); user.setUserId(124L); user.setAge(26); user.setPassword("test_123"); user.setUserName("芸Rey"); if (sqlSession.insert("com.classfly.mapper.UserMapper.insert", user) > 0) { sqlSession.commit(); } } @Test public void testUpdate() { SqlSession sqlSession = buildMySqlEnv("config.xml"); User user = new User(); user.setUserId(124L); user.setAge(26); user.setUserName("芸Rey"); user.setPassword("test_modified"); if (sqlSession.update("com.classfly.mapper.UserMapper.update", user) > 0) { sqlSession.commit(); } } @Test public void testDelete() { SqlSession sqlSession = buildMySqlEnv("config.xml"); User user = new User(); user.setUserId(123L); if (sqlSession.update("com.classfly.mapper.UserMapper.delete", user) > 0) { sqlSession.commit(); } } private static SqlSession buildMySqlEnv(String resource) { try { return new SqlSessionFactoryBuilder() .build(org.apache.ibatis.io.Resources.getResourceAsStream(resource)) .openSession(); } catch (IOException e) { System.out.printf("Failed to build mysql environment!"); return null; } } } 代码链接实现

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册