Mryqu's Notes


  • 首页

  • 搜索
close

Visual Studio: 使用简体中文(GB2312)编码加载文件, 有些字节已用Unicode替换字符更换

时间: 2015-12-21   |   分类: Tool     |   阅读: 39 字 ~1分钟
遭遇下列VS2010错误: Some bytes have been replaced with the Unicodesubstitution character while loading file base64.cpp with ChineseSimplified (GB2312) encoding. Saving the file will not preserve theoriginal file contents. 我的Visual Studio已经勾选了Auto-detect UTF-8 encoding withoutsignature: Ultraedit不能正常显示base64.cpp,但Sublime Text能正常显示。 原因是base64.cpp并不是UTF-8编码,但是包含一个十六进制为"E9"的字符,即带重音符的e。由于我的系统locale是RPC,所以显示不正常,估计系统locale改成CP1252 - Windows 拉丁语1代码页就可以了。用Sublime Text将其转存为UTF-8编码当然也可以。

[C++] Building twitcurl Library in Unix platform

时间: 2015-12-19   |   分类: DataBuilder   C++     |   阅读: 56 字 ~1分钟
Download twitcurl source from https://github.com/swatkat/twitcurl using Git client. git clone https://github.com/swatkat/twitcurl.git In Unix shell, cd into libtwitcurl directory. Compile all of the twitcurlsource files into object files. g++ -Wall -fPIC -c -I. twitcurl.cpp oauthlib.cpp urlencode.cpp base64.cpp HMAC_SHA1.cpp SHA1.cpp Building twitcurl asstatic library: Use the archive commandto build twitcurl library from object files. ar rvs libtwitcurl.a *.o

[C++] 使用NM查看目标文件的符号列表

时间: 2015-12-18   |   分类: Tool   C++     |   阅读: 592 字 ~3分钟
练习使用nm查看目标文件的符号列表。此外发现G++竟然创建了两套构造函数和析构函数。 nm命令 -a或–debug-syms:显示调试符号。 -B:等同于–format=bsd,用来兼容MIPS的nm。 -C或–demangle:将低级符号名解码(demangle)成用户级名字。这样可以使得C++函数名具有可读性。 -D或–dynamic:显示动态符号。该任选项仅对于动态目标(例如特定类型的共享库)有意义。 -fformat:使用format格式输出。format可以选取bsd、sysv或posix,该选项在GNU的nm中有用。默认为bsd。 -g或–extern-only:仅显示外部符号。 -n、-v或–numeric-sort:按符号对应地址的顺序排序,而非按符号名的字符顺序。 -p或–no-sort:按目标文件中遇到的符号顺序显示,不排序。 -P或–portability:使用POSIX.2标准输出格式代替默认的输出格式。等同于使用任选项-fposix。 -s或–print-armap:当列出库中成员的符号时,包含索引。索引的内容包含:哪些模块包含哪些名字的映射。 -r或–reverse-sort:反转排序的顺序(例如,升序变为降序)。 –size-sort:按大小排列符号顺序。该大小是按照一个符号的值与它下一个符号的值进行计算的。 -tradix或–radix=radix:使用radix进制显示符号值。radix只能为"d"表示十进制、“o"表示八进制或"x"表示十六进制。 –target=bfdname:指定一个目标代码的格式,而非使用系统的默认格式。 -u或–undefined-only:仅显示没有定义的符号(那些外部符号)。 -l或–line-numbers:对每个符号,使用调试信息来试图找到文件名和行号。对于已定义的符号,查找符号地址的行号。对于未定义符号,查找指向符号重定位入口的行号。如果可以找到行号信息,显示在符号信息之后。 -V或–version:显示nm的版本号。 –help:显示nm的任选项。 练习 symtest.hpp #include <iostream> class SymTest { SymTest(); SymTest(int x); ~SymTest(); void foo(); }; symtest.cpp #include "symtest.hpp" SymTest::SymTest() { printf("SymTest::SymTest\n"); } SymTest::SymTest(int x) { printf("SymTest::SymTest(int)\n"); } SymTest::~SymTest() { printf("SymTest::~SymTest\n"); } void SymTest::foo() { printf("SymTest::foo\n"); } 编译 NM: -g 仅显示外部符号 -C 显示用户级名字 学习了StackOverflow上的帖子Dual emission of constructor symbols,才了解这是G++的一个已知问题,两套构造函数分别是complete objectconstructor和base object constructor。 NM: -A 在每个符号前显示文件名 NM: -l 在每个符号前显示行号 mymachine> g++ -c symtest.
阅读全文 »

FileUpload Streaming

时间: 2015-12-13   |   分类: Service+JavaEE     |   阅读: 87 字 ~1分钟
最近看一下org.apache.tomcat.util.http.fileupload,这个包是从commons-fileupload和commons-io复制而来,为了避免冲突而改名。 Apache Commons FileUpload是用于servlet和web应用的健壮、高性能文件上传库,它支持 RFC 1867和RFC2047。 传统的文件上传API假设文件在被用户访问前必须存储在某处,这种途径便捷、易于访问,但是消耗内存和耗时。流处理API允许在高性能和低内存配置之间做一点折中。 首先,需要确保请求是一个文件上传请求。这通过与传统API相同的静态方法实现: // Check that we have a file upload request boolean isMultipart = ServletFileUpload.isMultipartContent(request); 现在需要解析请求获取成分项: // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(); // Parse the request FileItemIterator iter = upload.getItemIterator(request); while (iter.hasNext()) { FileItemStream item = iter.next(); if (!item.isFormField()) { String name = item.getFieldName(); if(name==null) continue; InputStream stream = item.openStream(); System.out.println("File field " + name + " with file name " + item.
阅读全文 »

Sublime Text2+Ctags+Cscope使用实践

时间: 2015-12-09   |   分类: Tool   C++     |   阅读: 168 字 ~1分钟
安装 安装Package Control 步骤见https://packagecontrol.io/installation#st2 安装CTags插件 通过 Preference -> Package Control -> InstallPackage安装Ctags插件(快捷键Ctrl+Shift+P,输入install) 打开Preference -> Package Settings -> Ctags ->Settings-Default和Setting-User,将Settings-Default中的内容拷贝到Setting-User中,将"command": "" 中的 "" 填入Ctags.exe的路径位置 打开C工程根目录,在上点击右键,选择Ctags:Rebuild tags 安装Cscope插件 同样通过 Preference -> Package Control -> InstallPackage安装Cscope插件(快捷键Ctrl+Shift+P,输入install) 通过cscope –Rb在C工程根目录创建cscope.out文件 Cscope在ST2上没有包配置菜单,需要打开CscopeSublime.sublime-settings文件(我的机器在C:/Users/yqu/AppData/Roaming/SublimeText 2/Packages/Cscope目录下),将 “executable”: "" 中的 ““填入Cscope.exe的路径位置,将 “database_location”: "” 中的"“填入cscope.out的路径位置。 使用 CTags命令 |Command|Key Binding|Alt Binding|Mouse Binding |—– |rebuild_ctags|ctrl+t, ctrl+r| | |navigate_to_definition|ctrl+t, ctrl+t|ctrl+>|ctrl+shift+left_click |jump_prev|ctrl+t, ctrl+b|ctrl+<|ctrl+shift+right_click |show_symbols|alt+s| | |show_symbols (all files)|alt+shift+s| | |show_symbols (suffix)|ctrl+alt+shift+s| | Cscope命令 Ctrl + \ - Show Cscope options Ctrl + L , Ctrl + S - Look up symbol undercursor Ctrl + L , Ctrl + D - Look up definition undercursor Ctrl + L , Ctrl + E - Look up functions calledby the function under the cursor Ctrl + L , Ctrl + R - Look up functionscalling the function under the cursor Ctrl + Shift + [ - Jump back Ctrl + Shift + ] - Jump forward 其他快捷键 Ctrl + p - 快速定位项目中的文件 Ctrl + R - 获取当前文件中的函数列表(# 和 @分别为变量和函数),这个功能也使得ST2不需要taglist插件了。 参考 使用Sublime Text3+Ctags+Cscope替代Source Insight Exuberant Ctags笔记 Cscope笔记

[C++] 使用readelf

时间: 2015-12-08   |   分类: Tool   C++     |   阅读: 1371 字 ~7分钟
在计算机科学中,ELF文件(Executableand LinkableFormat)是一种用于二进制文件、可执行文件、目标代码、共享库和核心转储格式文件,是UNIX系统实验室(USL)作为应用程序二进制接口(ApplicationBinaryInterface,ABI)而开发和发布的,也是Linux的主要可执行文件格式。1999年,被86open项目选为x86架构上的类Unix操作系统的二进制文件标准格式,用来取代COFF。因其可扩展性与灵活性,也可应用在其它处理器、计算机系统架构的操作系统上。 ELF文件由4部分组成,分别是ELF头(ELF header)、程序头表(Program headertable)、节(Section)和节头表(Section headertable)。实际上,一个文件中不一定包含全部内容,而且他们的位置也未必如同所示这样安排,只有ELF头的位置是固定的,其余各部分的位置、大小等信息由ELF头中的各项值来决定。 而readelf用于显示ELF文件的信息。 Usage: readelf <option(s)> elf-file(s) Display information about the contents of ELF format files Options are: -a --all 全部 Equivalent to: -h -l -S -s -r -d -V -A -I -h --file-header ELF头 Display the ELF file header -l --program-headers 程序头表 Display the program headers --segments An alias for --program-headers -S --section-headers 节头 Display the sections' header --sections An alias for --section-headers -g --section-groups 节组 Display the section groups -t --section-details 节细节 Display the section details -e --headers 全部头 Equivalent to: -h -l -S -s --syms 符号表 Display the symbol table --symbols An alias for --syms --dyn-syms 动态符号表 Display the dynamic symbol table -n --notes 核心注释 Display the core notes (if present) -r --relocs 重定位 Display the relocations (if present) -u --unwind Display the unwind info (if present) -d --dynamic 动态节 Display the dynamic section (if present) -V --version-info 版本节 Display the version sections (if present) -A --arch-specific 架构信息 Display architecture specific information (if any) -c --archive-index 该架构下符号/文件索引 Display the symbol/file index in an archive -D --use-dynamic Use the dynamic section info when displaying symbols -x --hex-dump=<number|name> Dump the contents of section <number|name> as bytes -p --string-dump=<number|name> Dump the contents of section <number|name> as strings -R --relocated-dump=<number|name> Dump the contents of section <number|name> as relocated bytes -w[lLiaprmfFsoRt] or --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames, =frames-interp,=str,=loc,=Ranges,=pubtypes, =gdb_index,=trace_info,=trace_abbrev,=trace_aranges, =addr,=cu_index] 显示DWARF2调试节 Display the contents of DWARF2 debug sections --dwarf-depth=N Do not display DIEs at depth N or greater --dwarf-start=N Display DIEs starting with N, at the same depth or deeper -I --histogram 柱状图 Display histogram of bucket list lengths -W --wide 输出宽度 Allow output width to exceed 80 characters @<file> Read options from <file> -H --help 帮助 Display this information -v --version 版本 Display the version number of readelf 练习 - 查看ELF文件头 hadoop@node51054:/usr/bin$ readelf -h curl ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0x4023b1 Start of program headers: 64 (bytes into file) Start of section headers: 152600 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 9 Size of section headers: 64 (bytes) Number of section headers: 27 练习 - 查看符号表 hadoop@node51054:/usr/bin$ readelf -s curl Symbol table '.
阅读全文 »

[C++] 使用ldd

时间: 2015-12-07   |   分类: Tool   C++     |   阅读: 1437 字 ~7分钟
ldd是用来查看共享库依赖的Shell脚本命令。下面来看一下ldd命令的参数。 -v:显示所有信息,例如包括符号版本信息。 -u:显示没有使用的直接依赖。 -d:执行重新定位,报告任何缺失对象(仅针对ELF) -r:对数据对象和函数执行重新定位,报告任何缺失对象或函数(仅针对ELF) Oracle - Linker and Libraries Guide - Relocations介绍了重新定位技术的来龙去脉,也介绍了ldd命令的相关使用。 ldd练习 hadoop@node51054:/usr/bin$ ldd curl linux-vdso.so.1 => (0x00007ffefe989000) libcurl.so.4 => /usr/lib/x86_64-linux-gnu/libcurl.so.4 (0x00007fb86cf8f000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fb86cd76000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb86cb58000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb86c790000) libidn.so.11 => /usr/lib/x86_64-linux-gnu/libidn.so.11 (0x00007fb86c55d000) librtmp.so.0 => /usr/lib/x86_64-linux-gnu/librtmp.so.0 (0x00007fb86c343000) libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007fb86c0e4000) libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007fb86bd08000) libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007fb86bac1000) liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007fb86b8b2000) libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007fb86b661000) /lib64/ld-linux-x86-64.so.2 (0x00007fb86d1f6000) libgnutls.so.26 => /usr/lib/x86_64-linux-gnu/libgnutls.so.26 (0x00007fb86b3a2000) libgcrypt.
阅读全文 »

[C++] GNU Binutils之ar和ranlib

时间: 2015-12-06   |   分类: Tool   C++     |   阅读: 67 字 ~1分钟
GNU binutils是一组二进制工具集。包括:ld、as、addr2line、ar、gprof、nm、objcopy、objdump、ranlib、size、strings、strip等。本文重点学习一下其中的ar和ranlib。 ar命令 ar用于建立、修改、提取档案文件(archive)。archive是一个包含多个被包含文件的单一文件(也称之为库文件),其结构保证了可以从中检索并得到原始的被包含文件(称之为archive中的member)。member的原始文件内容、模式(权限)、时间戳、所有者和组等属性都被保存在archive中。member被提取后,他们的属性被恢复到初始状态。 ar命令第一个参数可混合指令代码(operationcode p)和修饰符标志(modifier flags mod),可按意愿添加一个折线。 ar [--plugin name] [-X32_64] [-]p[mod [relpos] [count]] archive [member...] 指令参数 d:删除档案文件中的成员文件。 m:移动在档案文件中的成员文件,改变次序。可以借助修饰符标志a、b、i移动到指定位置。 p:显示档案文件中的成员文件内容。 q:将文件快速附加在档案文件末端。不检查、不替换已有同名成员文件,也不更新档案文件的符号表索引,修饰符标志a、b、i无效。然而很多不同系统都假设q指令重建档案文件的符号表索引,因此GNU将其按照r指令进行相同实现。 r:将文件插入档案文件中。检查并替换已有同名成员文件,重建档案文件的符号表索引,借助修饰符标志a、b、i将文件插入到指定位置。 t:显示档案文件中所包含的文件。 x:自档案文件中取出成员文件。 修饰符标志 a <成员文件>:将文件插入档案文件中指定的成员文件之后。 b<成员文件>:将文件插入档案文件中指定的成员文件之前。 c:建立档案文件。当更新档案文件时,档案文件不存在则创建档案文件,但会告警。此标志可抑制告警。 D:以确定模式工作。 f:为避免过长的文件名不兼容于其他系统的ar指令指令,可利用此参数,截掉要放入档案文件中过长的成员文件名称。 i <成员文件>:将文件插入档案文件中指定的成员文件之前。(等同标志b) I:可接受但不使用。 N:使用count参数。当档案文件中存在多个同名成员,用于指定提取/删除的个数。 o:保留档案文件中文件的日期。如无此参数,则输出文件的修改时间为提取时间。 s:若档案文件中包含了对象模式,可利用此参数建立档案文件的符号表。 S:不产生符号表。 T:使指定档案文件成为瘦档案文件。例如将多个档案文件加入目标档案文件,目标档案文件可以包含符号索引及对源档案文件中成员文件的引用。 u:只将日期较新文件插入档案文件中。 v:程序执行时显示详细的信息。 V:显示版本信息。 练习 # 将当前目录下所有.o打包成libyqutest.a档案文件:r插入,v显示操作信息,s生成符号表。 ar rvs libyqutest.a *.o # 制作瘦档案文件:r插入,c建立档案文件,T指定为瘦档案文件。 ar -rcT libkx.a libke.a libxiao.a ranlib命令 为档案文件创建符号索引。 ranlib [-vVt] archive 选项: -v、-V或–version:显示版本 -t:更新档案文件符号映射的时戳。 最早在Unix系统上ar程序是单纯用来打包多个.o到.a(类似于tar做的事情),而不处理.o里的符号表。Linker程序则需要.a文件提供一个完整的符号表,所以当时就写了单独的ranlib程序用来产生linker所需要的符号信息,也就是说那时,产生一个对linker合格的的.a文件需要做ar和ranlib两步 。如今,ar-s就做了ranlib的工作,但为了保证这些早期Makefile文件的兼容性,ranlib被保留下来了。

[MapR培训笔记] Hadoop生态系统

时间: 2015-12-05   |   分类: BigData     |   阅读: 378 字 ~2分钟
SQL: Language designed for querying & transformingdata held in a relational database management system. NoSQL: Database model that’s not necessaryly held intabular format. Often, NoSQL refers to data that is flat or nestedin format. Log Data: Information captured about organization’sinternal system, external customer interactions & how they’reused Streaming Data: Twitter, Facebook, Web click data, Webform data. Flume: Reliable, scalable service used to collectstreaming data in Hadoop cluster. Sqoop: Transfers data between external data store &Hadoop cluster.
阅读全文 »

[Spring Boot] 让非Spring管理的类获得一个Bean

时间: 2015-12-04   |   分类: Service+JavaEE   Spring     |   阅读: 62 字 ~1分钟
我有一个工具类,它既会被SpringBean调用,也会被非Spring管理的类调用。我想在这个工具类里获得Spring注入了拦截器的RestTemplate。一开始考虑了ApplicationContextAware、ContextLoaderListener和ContextLoaderServlet,最后采用了下面这种改动最小的解决方案。 示例代码 Application.java @SpringBootApplication public class Application{ public static void main(String[] args) { final ApplicationContext applicationContext = SpringApplication.run(Application.class, args); MyUtil.setApplicationContext(applicationContext); } @Bean public RestTemplate restTemplate() { return new RestTemplate(); } } MyUtil.java public class MyUtil { private static ApplicationContext applicationContext; public static void setApplicationContext(ApplicationContext context) { applicationContext = context; } public static void doSomething() { RestTemplate _restTemplate = applicationContext.getBean(RestTemplate.class); ........ } }
14 15 16 17 18 19 20 21 22

Programmer & Architect

662 日志
27 分类
1472 标签
RSS 订阅
GitHub Twitter FB Page
© 2009 - 2023 Mryqu's Notes
Powered by - Hugo v0.120.4
Theme by - NexT
0%