<!-- generator=" CodePongo (Base on Kukkaisvoima version 15b3TA)" -->
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel><title>CodePongo</title><link>http://codepongo.com/blog</link><description></description><pubDate>Tue, 22 Jan 2019 17:30:06 +0200</pubDate><lastBuildDate>Tue, 22 Jan 2019 17:30:06 +0200</lastBuildDate><generator>http://codepongo.com/blog</generator><language>zh-cn</language><item><title>Debug python Script with pdb
</title><link>http://codepongo.com/blog/1uiB67</link><comments>http://codepongo.com/blog/1uiB67#comments</comments><pubDate>Tue, 22 Jan 2019 17:30:06 +0200</pubDate><dc:creator>zuohaitao</dc:creator><category>python</category><guid isPermaLink="false">http://codepongo.com/blog/1uiB67/</guid><description><![CDATA[ 
 [...]]]></description><content:encoded><![CDATA[
Usage

Launch

to debug a script, you can run


  python -m script_to_debug.py arguments


The program will break in the first line of the script.
pdb will automatically enter post-mortem debug and restart

Insert Statment to Break the Running Script


  import pdb;pdb.set_trace()


if you want to suspend on exception in pdb, try post_mortem method


  import pdb;pdb.post_mortem()


Configure

.pdbrc locates home folder or current folder 
aliases is in this file

to include py script into my.pdbrc, use execfile() to run a file containing your Python code.

.pdbrc



alias p_ for k in sorted(%1.keys()): print "%s%-15s= %-80.80s" % ("%2",k,repr(%1[k]))

alias pi p_ %1.__dict__ %1.

alias ps pi self

alias pl p_ locals() local:

alias nl n;;l
alias sl s;;l

execfile(".pdbrc.py")



pdbrc.py

in the same directory as the .pdbrc



print ".pdbrc.py"



Command

Arguments to commands must be separated by whitespace 
multiple commands may be entered on a single, sparated by ;;

Help


h(elp) [command]


Stack Frames


w(here)
d(own)
u(p)


Breakpoints


b(reak) [filename:]:lineno | function[, condition]] 
without argument, list all breaks
tbreak [filename:]:lineno | function[, condition]] 
cl(ear)  [filename:]:lineno | function[, condition]] 
disable [bpnumber [bpnumber ...]]
enable [bpnumber [bpnumber ...]]
ignore bpnumber [count]
condition bpnumber [condition]
commands [bpnumber]


Evaluation


s(tep)
n(ext)
unt(il)
r(eturn)
c(ont(inue))
j(ump) lineno


View


l(ist) [first[, last]]
a(rgs)
p expression


Macro


alias [name [command]]
unalias name


PDB Source Code

Three main classes in this module, the pdb uses the modules bdb and cmd.


cdb.py
cmd.py
pdb.py


Bibliography

https://nedbatchelder.com/blog/200704/my_pdbrc.html 
https://wiki.python.org/moin/PdbRcIdea 
https://stackoverflow.com/questions/44155444/how-to-write-a-working-pdbrc-file 
https://docs.python.org/2/library/pdb.html
https://stackoverflow.com/questions/45446944/suspend-on-exception-in-pdb

]]></content:encoded><wfw:commentRss>http://codepongo.com/blog/1uiB67/feed/</wfw:commentRss></item><item><title>High DPI 相关的Windows桌面应用程序开发技术
</title><link>http://codepongo.com/blog/2cXJiu</link><comments>http://codepongo.com/blog/2cXJiu#comments</comments><pubDate>Thu, 16 Aug 2018 17:30:06 +0200</pubDate><dc:creator>zuohaitao</dc:creator><category>windows</category><guid isPermaLink="false">http://codepongo.com/blog/2cXJiu/</guid><description><![CDATA[ 
 [...]]]></description><content:encoded><![CDATA[
High DPI Desktop Application Development on Windows

UWP程序可以被系统自动适配，其他技术实现的程序（raw Win32 programming，Windows 
Form，WPF等）不能自动适配，默认情况下会自动被系统做位图拉伸适配导致显示模糊。

High DPI技术，主要是解决由于显示器分辨率越来越高，如果使用固定DPI（如windows操作系统为96）而导致传统UI上的元素（字体，图形等）显示越来越小，肉眼辨识越来越费力的问题。
在高分辨率下，对元素进行拉伸（放大）处理（即定义一个伸缩率，伸缩率乘以标准DPI则为实际采用的DPI值），如设置更大的字号，加载更大规格的图像资源等。

High DPI技术主要有三类应用场景：


多显示器
远程桌面
实时缩放，即程序运行时，进行显示拉伸改变后，程序可实时自适应。


DPI 感知模式


DPI_AWARENESS_CONTEXT_UNAWARE 应用程序不关心DPI改变，系统始终采用 96DPI 根据比率自动进行像素级适配, 其结果是UI显示很模糊。
DPI_AWARENESS_CONTEXT_SYSTEM_AWARE 应用程序对启动时所在的显示器做适配，不需要系统进行自动适配，这样就保证了，在此模式下，应用程序在其初始化所处的显示器清晰显示，不模糊。但当显示器DPI实时改变或切换显示器显示时，系统会自动进行像素级适配，进而导致渲染效果的模糊。
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE 在DPI发生变化时，系统只做通知，不自动适配，由应用程序自己进行适配（缩放和布局）。
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 PerMonitor 升级版，增强对DPI变化的处理能力。

顶层窗口的子窗体也会收到 DPI 改变的通知
自动处理非客户端区域的DPI适配
自动适配Win32菜单
对话框大小自动适配DPI改变
改善控件对DPI改变的适配
改善对 UxTheme（Visual styles）的支持



不同系统所支持的DPI感知模式是不一样的; 不同UI框架技术，在不同版本系统上的表现也是不一样的。

升级已存在的程序

大部分程序是 DPI awareness 模式。

升级至 PerMonitor 模式的步骤


mainfest 中设置DPI感知模式
重构布局逻辑，使之可以在代码相应DPI发生改变时可重用。
DPI敏感数据（DPI/字体/尺寸/等）应进行换算后更新。
DPI改变发生，位图资源需要重新载入。
替换API为相应的DPI敏感版本
多显示器，多DPI设置场景测试应用
对于无法适配的窗体，可采用混合模式使他们通过位图级别的拉伸进行适配


混合模式 Mixed-Mode DPI Scaling

在时间不够或使用了没有源码的第三方UI库等无法做DPI适配的情况下，可采混合DPI感知
模式的方案，调用 SetThreadDpiAwarenessContext 去改变和恢复DPI感知模式。


线程可以任何时候更改自己的DPI感知模式
DPI感知模式发生变化后，任何API将以与其DPI感知模式相符的情况运行
窗体的DPI感知模式，在其创建时被定义，其窗体过程中将使用保持这个感知模式。


测试


DPI不同的多显示器来回切换应用程序
使用不同DPI值，启动程序
当程序运行时，改变缩放因子，测试程序是否实时适配
切换主显示，测试应用；这个测试对于发现硬编码的坐标和尺寸及其有帮助


注意事项


DPI改变后，确认鼠标始终处于窗体相对位置
避免DPI改变递归循环
通过 WM_GETDPISCALEDSIZE 消息预设大小
一些DPI敏感的API的返回值将根据DPI感知模式被虚拟化。但微软没有提供文档对这些API进行有效的说明。
对没有DPI感知的API，需做一些额外处理。
进程的DPI感知模式，一旦初始化是不能被改变的。 但由于窗体树上的父子窗体必须保持一致的DPI感知模式。所以，进程的DPI感知模式会由窗体父子关系的改变(CreateWindow和SetParent)可能触发而强制重置。 


WPF应用支援High DPI模式

详见: WPF应用支持High DPI

参考


High DPI Desktop Application Development on Windows
关于Windows高DPI的一些简单总结
Visual Styles
High DPI Scaling Improvements for Desktop Applications and “Mixed Mode” DPI Scaling in the Windows 10 Anniversary Update (1607)
High-DPI Scaling Improvements for Desktop Applications in the Windows 10 Creators Update (1703) 【译】Windows 10 创作者更新中用于桌面应用的高 DPI 缩放改进
High DPI
Windows DPI Awareness


]]></content:encoded><wfw:commentRss>http://codepongo.com/blog/2cXJiu/feed/</wfw:commentRss></item><item><title>Comet (programming) 
</title><link>http://codepongo.com/blog/y8txj</link><comments>http://codepongo.com/blog/y8txj#comments</comments><pubDate>Fri, 01 Jun 2018 17:30:06 +0200</pubDate><dc:creator>zuohaitao</dc:creator><category>http</category><category>csharp</category><guid isPermaLink="false">http://codepongo.com/blog/y8txj/</guid><description><![CDATA[ 
 [...]]]></description><content:encoded><![CDATA[
Commet技术，是2000年左右诞生的基于HTTP长连接，服务器向客户端（浏览器）推送数据的一种技术。
目前，websocket技术为此类问题的最优解决方案，C# 也有SignalIR专门用于解决服务器主动向客户端主动推送的问题。




订阅客户端发送订阅请求，发布客户端推送信息，服务器将推送信息转发至订阅客户端
订阅客户端未发起订阅请求，发布客户端推送消息，服务器将消息缓存，带订阅客户端订阅请求到来时转发给订阅客户端
订阅客户端订阅请求超时，仍未有新消息推送，则服务器返回超时


实现


客户端初始化，分配一个缓存消息队列
接收订阅请求后，异步启动遍历消息队列线程循环检查缓存消息队列中是否有消息和是否超时，有消息或超时则返回异步应答订阅请求
发布过程即投递至缓存消息队列中


优化


HTTP 请求和应答采取异步
使用独立线程池或者与http服务器请求应答处理线程公用线程池
消息队列采用NoSQL数据库缓存


参考


comet C#实现

第一部分
第二部分

分享一些Comet开发经验


]]></content:encoded><wfw:commentRss>http://codepongo.com/blog/y8txj/feed/</wfw:commentRss></item><item><title>部署mysql
</title><link>http://codepongo.com/blog/3zpXT2</link><comments>http://codepongo.com/blog/3zpXT2#comments</comments><pubDate>Mon, 24 Apr 2017 17:30:06 +0200</pubDate><dc:creator>zuohaitao</dc:creator><category>database</category><category>mysql</category><guid isPermaLink="false">http://codepongo.com/blog/3zpXT2/</guid><description><![CDATA[ 
 [...]]]></description><content:encoded><![CDATA[
版本


bin\mysqld.exe --version
bin\mysqld.exe  Ver 5.7.18 for Win32 on AMD64 (MySQL Community Server (GPL))


配置


[mysqld]
basedir = "d:\\mysql"
datadir = "d:\\mysql\\data"


初始化


bin\mysqld.exe --console --initialize-insecure


启动


bin\mysqld.exe --console


登录


bin\mysql -u root --skip-password


修改root密码


alter user 'root'@'localhost' identified by 'password';


建立用户


bin\mysql -u root -p
create user 'username'@'%' indentified by 'password'


创建数据库


create database db;


提权


grant all privileges on db.* to username;
flush privileges;


允许root远程



grant all privileges on *.* to 'root'@'%' identified by 'password';

]]></content:encoded><wfw:commentRss>http://codepongo.com/blog/3zpXT2/feed/</wfw:commentRss></item><item><title>PDF文件生成
</title><link>http://codepongo.com/blog/gHn0e</link><comments>http://codepongo.com/blog/gHn0e#comments</comments><pubDate>Mon, 20 Mar 2017 17:30:06 +0200</pubDate><dc:creator>zuohaitao</dc:creator><category>CSharp</category><guid isPermaLink="false">http://codepongo.com/blog/gHn0e/</guid><description><![CDATA[ 
 [...]]]></description><content:encoded><![CDATA[
分析PDF格式


 x.pdf.dump.txt


输出PDF文件源码并还原经过处理的stream对象。


PDF文件以obj为一个单位
&lt;&lt; &gt;&gt;包含obj的一些属性，如Filter格式
[2 0 R]表示引用obj 2 0 对象
/Type为Catalog, Pages, Page的页不可或缺
/Type为Page的obj，/MediaBox表示纸张大小


PDF显示中文

有两种方式显示中文，/Type为Font的obj的/Encoding属性为/Identity-H，
然后/Contents所引用的obj中文字用glyph（文字在字体文件中的编码）表示。
采用这种方式如果不把完整的字体文件或者经过裁剪的字体文件嵌入PDF文件中，
会导致PDF文件兼容性很差，如对应系统中没有安装PDF指定的字体，则PDF将不能
正常显示。 GetGlyphIndices即可得到glyph index。
另一种方式是/Encoding使用/WinAnsiEncoding，中文直接采用unicode编码表示。

PDF 单位

PDF中固定每个单位为1磅即1/72英寸，1英寸为2.54厘米。
所以要在PDF上画1毫米即为72/2.54/10=2.834个单位

示例


%PDF-1.4

1 0 obj
/Type /Catalog 
/Pages 2 0 R 
 
endobj
2 0 obj
/Type /Pages 
/Count 1 
/Kids [ 3 0 R ] 
 
endobj
3 0 obj
/MediaBox [ 0 0 842 595 ] 
 
/Type /Page 
/Parent 2 0 R 
/Contents 9 0 R 
 
endobj
4 0 obj
/Type /FontDescriptor 
/FontBBox [ 0 0 0 0 ] 
 
endobj
5 0 obj
/BaseFont /SimSun 
/Subtype /CIDFontType2 
/FontDescriptor 4 0 R 
/Type /Font 
/CIDSystemInfo /Registry (Adobe)
/Ordering (GB1)
 
 
endobj
6 0 obj
/BaseFont /Helvetica 
/Name /F2 
/Type /Font 
/Encoding /WinAnsiEncoding 
/Subtype /TrueType 
 
endobj
7 0 obj
/FontDescriptor 4 0 R 
/Name /F1 
/DescendantFonts [ 5 0 R ] 
/Subtype /Type0 
/Encoding /UniGB-UCS2-H 
/Type /Font 
/BaseFont /SimSun 
 
endobj
8 0 obj
[ 
/PDF /Text 
]
endobj
9 0 obj
 
stream
1 0 0 1 0 0  cm
1  w
0.2745098 0.509804 0.7058824 rg
0 0 0 RG
56.68 538.32 28.34 28.34  re
 B


BT

/F1 8 Tf
0 0 1 rg
0 0 1 RG
0 0 m 28.34 580.83 TD 0 0 0 rg
0 0 0 RG

/F1 9 Tf
Tj

ET

endstream
endobj
10 0 obj
/ModDate (D:20020306011115+06'00')
/CreationDate (D:20020306011115+06'00')
 
endobj
xref
0 11 
0000000000 65535 f
0000000010 00000 n
0000000063 00000 n
0000000127 00000 n
0000000287 00000 n
0000000356 00000 n
0000000515 00000 n
0000000632 00000 n
0000000791 00000 n
0000000823 00000 n
0000001121 00000 n
trailer
/Root 1 0 R 
/Size 11
/Info 10 0 R 
 
startxref
1220
%%EOF



源代码

C#基于PDFLib实现的一个PDF导出源码。
* 浮点数描述坐标，定位更准。
* 支持中文

https://github.com/codepongo/pdfexporter

参考


PDF.NET - 生成PDF的C#类库
PDFTools - Python开发的PDF文件的工具集
PDF File Writer C# Class Library
GetGlyphIndices function
PDF, the default for the size of the unit


]]></content:encoded><wfw:commentRss>http://codepongo.com/blog/gHn0e/feed/</wfw:commentRss></item></channel></rss>