handler

Which thread does Runnable run on?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 02:53:47
问题 I want to update UI every 100ms. After searching in StackOverflow, I found a solution using Runnable and Handler like this final Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { //update UI here handler.postDelayed(this, 100); } }; runnable.run(); It works! But I have some questions: Which thread does this Runnable run on? MainThread or another thread? Here is the docs about postDelay Handler is attached MainThread, so is Runnable running on

python 回调函数的简单使用

吃可爱长大的小学妹 提交于 2019-12-06 02:36:21
def apply_async(func, args=(), callable=None): """需要调用的回调函数的函数""" result = func(*args) # 元组拆包*args callable(result) def print_result(result): """打印日志信息""" print("Got:", result) def add(x, y): """计算函数""" return x + y class ResultHandler: """第一种 保存内部序列号""" def __init__(self): self.sequence = 0 def handler(self, result): self.sequence += 1 print('[{}] Got:{}'.format(self.sequence, result)) def make_handler(): """第二种 类的替代,可以使用闭包捕获状态值""" sequence = 0 def handler(result): nonlocal sequence # 只能用于嵌套函数中 sequence += 1 print('[{}] Got:{}'.format(sequence, result)) return handler def make_handler_2(): ""

jQuery $(document).ready()和JavaScript onload事件详解区别

寵の児 提交于 2019-12-06 02:06:42
jQuery $(document).ready()和window.onload   根据 ready() 方法的API说明 http://api.jquery.com/ready/   这个方法接收一个function类型的参数ready(handler), 方法的作用是: Specify a function to execute when the DOM is fully loaded.   即当DOM加载完毕的时候,执行这个指定的方法.   因为只有document的状态ready之后,对page的操作才是安全的.    $(document).ready()仅在DOM准备好的时候执行一次.   与之相比, load事件会等到页面渲染完成执行,即等到所有的资源(比如图片)都完全加载完成的时候.    $(window).load(function(){…})会等整个页面,不仅仅是DOM,还包括图像和iframes都准备好之后,再执行.   而ready()是在DOM准备好之后就执行了,即DOM树建立完成的时候.所以通常ready()是一个更好的时机.   如果DOM初始化完成之后再调用ready()方法,传入的新的handler将会 立即执行 .    注意:ready()方法多次调用,传入的handler方法会串联执行(追加).   而JavaScript中,window

urllib

我是研究僧i 提交于 2019-12-06 00:38:25
About urllib是Python内置的HTTP请求库。urllib 模块提供的上层接口,使访问 www 和 ftp 上的数据就像访问本地文件一样,并且它也是requests的底层库。 其中包括4个主要模块: urllib.request:请求模块。 urllib.error:异常处理模块。 urllib.parse:URL解析模块。 urllib.robotparser:robots.txt解析模块。 这里以Python3.6为例。 urllib、urllib2、urllib3 在Python2.x中,分为urllib和urllib2,简单来说,urllib2是urllib的增强版,但urllib中的函数又比urllib2多一些,对于简单的下载之类的,urllib绰绰有余,如果涉及到实现HTTP身份验证或者cookie或者扩展编写自定义协议,urllib2更好一些。 urllib支持设置编码的函数urllib.urlencode,在模拟登陆的时候经常需要传递经过post编码之后的参数,如果不想使用第三方库完成模拟登录,就必须使用到标准库中的urllib。urllib提供一些比较原始基础的方法而urllib2并没有,比如urllib中的urlencode方法用来GET查询字符串的产生。 urllib2比较有优势的地方在于urllib2

C++ unhandled exceptions

半城伤御伤魂 提交于 2019-12-05 23:18:27
问题 Does C++ offer a way to 'show' something visual if an unhandled exception occurs? What I want to do is to make something like assert(unhandled exception.msg()) if it actually happens (like in the following sample): void foo() { throw std::exception("Message!"); } int main() { foo(); } I expect this kind of code not to terminate immediately (because exception was unhandled), rather show custom assertion message ( Message! actually). Is that possible? 回答1: There's no way specified by the

Mybatis通用JSON Type Handler

╄→гoц情女王★ 提交于 2019-12-05 22:49:39
项目中使用postgresql的json类型存储了些数据。为了实现po中的类和json之间的转换,写了个通用的JSON Type Handler,分享出来。 使用jackson来实现json和object之间转换。 使用的时候在resultMap中,对应的列配置,例如: <result column="specs" property="specs" typeHandler="cn.devmgr.tutorial.typehandler.JsonTypeHandler" /> Mapper XML中配置的update/insert语句需要指明typeHandler update table_xxx set colA=#{beanA.xxx, typeHandler=cn.devmgr.tutorial.typehandler.JsonTypeHandler} where id=xx JsonTypeHandler.java (继承Mybatis提供的BaseTypeHandler,很简单,关键是范型的处理) package cn.devmgr.tutorial.typehandler; import java.io.IOException; import java.sql.CallableStatement; import java.sql.PreparedStatement;

Eclipse RCP 4 - Handler method parameters

无人久伴 提交于 2019-12-05 22:43:40
I'm currently taking a look to the new Eclipse RCP framework and have a questions about handlers. In RCP 3.x a handler class needed to implement an interface, so the methods where given. In RCP 4 the handler class doesn't need to implement an interface. Instead you annotate the methods. E.g. if you have an ExitHandler as in Vogellas Tutorial you have an @Execute annotation. As you can see, there's an IWorkbench parameter passed. package com.example.e4.rcp.todo.handler; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.workbench.IWorkbench; public class ExitHandler {

Python中的logging模块就这么用

一曲冷凌霜 提交于 2019-12-05 22:22:52
Python中的logging模块就这么用 1、日志 日志一共分成5个等级,从低到高分别是:DEBUG INFO WARNING ERROR CRITICAL DEBUG:详细的信息,通常只出现在诊断问题上 INFO:确认一切按预期运行 WARNING:一个迹象表明,一些意想不到的事情发生了,或表明一些问题在不久的将来(例如。磁盘空间低”)。这个软件还能按预期工作。 ERROR:更严重的问题,软件没能执行一些功能 CRITICAL:一个严重的错误,这表明程序本身可能无法继续运行 这5个等级,也分别对应5种打日志的方法: debug 、info 、warning 、error 、critical。默认的是WARNING,当在WARNING或之上时才被跟踪。 2、日志输出 有两种方式记录跟踪,一种输出控制台,另一种是记录到文件中,如日志文件。 2.1、将日志输出到控制台 比如,编写一个叫做log.py的文件,如下: # coding=utf-8 __author__ = 'liu.chunming' import logging logging.basicConfig(level=logging.WARNING, format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s') #

XSS跨站脚本

跟風遠走 提交于 2019-12-05 21:57:17
靶机地址:192.168.43.156 攻击机地址:192.168.43.89 一、AppScan检查靶机sql漏洞 二、使用sqlmap利用SQL注入漏洞 1.sqlmap -u " http://192.168.43.156/cat.php?id=1 " –dbs 查看数据库名 2.sqlmap -u " http://192.168.43.156/cat.php?id=1 " -D "photoblog" --tables 表名 3.sqlmap -u " http://192.168.43.156/cat.php?id=1 " -D "photoblog" T "user" --columns 查看字段 4.sqlmap -u " http://192.168.43.156/cat.php?id=1 " -D "photoblog" T "user" -C "login" --dump 用同种方法查找密码 三、建立反弹shell msfvenom -p php/meterpreter/reverse_tcp lhost=攻击机IP地址 lport=4444 -f raw 在桌面建一个文件shell.php 四、登录后台页面 刚在数据库拿到的用户名:admin 密码需要用MD5解密为: P4ssw0rd 在kali系统内 msf > use exploit/multi

a 的href="#"与href="javascript:void(0)"的区别

梦想的初衷 提交于 2019-12-05 21:05:51
無作用連結多半是用來執行 click event ,例如: <a href="javascript: void(0)" onclick="handler()" >Link</a> 點下連結時,不會連往另一頁,而是執行函式 handler() 。 無作用連結大致有兩種寫法, <a href="#" > 和 <a href="javascript: void(0)" > : <a href="#" > 的問題是點下連結時: 網址列的最後面會多一個 # 。 網頁的捲軸會移到最上面。 要解決這兩個問題必須在 click event 動手腳,加上 return false 、 event.preventDefault() 、 或 event.returnValue = false ,避免 <a> 原先應該做的動作。 該如何加,取決於 click event 註冊的方式,詳盡的 Event 註冊方式介紹請參考 淺談 JavaScript 的 DOM Event 註冊方式 。這裡直接列出各種註冊方式的 <a href="#" > 問題解決方法,假設我已用 getElementById 或 getElementsByTagName 抓到了 <a> 這個 node ,並且取名為 oLink : 傳統式 inline 註冊 <a href="#" onclick="handler(); return