目前我使用PRE标签在我的javadoc中格式化代码示例,例如:
/**
* Example javadoc
*
<pre>
String foo = "bar";
</pre>
*
* @return true if the operation completed
*/
Run Code Online (Sandbox Code Playgroud)
但是在生成的javadoc中,这看起来相当单调乏味,我宁愿有一些类似于SyntaxHighlighter的语法高亮.
如何才能做到这一点?
我正在尝试使用包含Web Developer Tools的Eclipse Ganymedes 3.4.1版编辑phpbb HTML模板文件.
这些模板文件包含带有模板变量标记的HTML标记,格式为{ variable_name }.现在,当试图打开这样的文件时,Eclipse会尝试验证这些模板变量标记.
例如模板包含
<meta http-equiv="content-type" content="text/html; charset={S_CONTENT_ENCODING}" />
Run Code Online (Sandbox Code Playgroud)
在编辑器主体上打开Eclipse后显示:
Unsupported Character Body
Character encoding "{S_CONTENT_ENCODING}" is not supported by this platform.
<button>Set encoding...</button>
Run Code Online (Sandbox Code Playgroud)
如何使用WTP解决这个问题,还是有更好的编辑器用于模板编辑?
我有以下代码,最终永远读取'/ proc/cpuinfo',因为它每次读取都会得到相同的结果.为什么文件指针不会先进并达到eof?似乎这个特殊文件有不同的语义.
const int bufSize = 4096;
char buf[bufSize + 1];
const string cpuInfo = "/proc/cpuinfo";
int cpuFD = ::open(cpuInfo.c_str(), O_RDONLY);
if (cpuFD == -1) {
logOutputStream << "Failed attempt to open '" << cpuInfo << "': "
<< strerror(errno) << endl;
} else {
assert(bufSize <= SSIZE_MAX);
logOutputStream << "Contents of: '" << cpuInfo << "'.\n";
for (int nRead = ::read(cpuFD, buf, bufSize); nRead != 0;) {
if (nRead == -1) {
logOutputStream << "Failed attempt to read '" …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个网络刮板,它将解析出版物的网页并提取作者.网页的骨架结构如下:
<html>
<body>
<div id="container">
<div id="contents">
<table>
<tbody>
<tr>
<td class="author">####I want whatever is located here ###</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我一直在尝试使用BeautifulSoup和lxml来完成这项任务,但我不知道如何处理这两个div标签和td标签,因为它们具有属性.除此之外,我不确定我是否应该更多地依赖于BeautifulSoup或lxml或两者的组合.我该怎么办?
目前,我的代码如下所示:
import re
import urllib2,sys
import lxml
from lxml import etree
from lxml.html.soupparser import fromstring
from lxml.etree import tostring
from lxml.cssselect import CSSSelector
from BeautifulSoup import BeautifulSoup, NavigableString
address='http://www.example.com/'
html = urllib2.urlopen(address).read()
soup = BeautifulSoup(html)
html=soup.prettify()
html=html.replace(' ', ' ')
html=html.replace('í','í')
root=fromstring(html)
Run Code Online (Sandbox Code Playgroud)
我意识到很多import语句可能是多余的,但我只是复制了我目前在更多源文件中所拥有的内容.
编辑:我想我没有说清楚,但我在页面中有多个标签,我想要刮.
我需要一个独特的内部int来代表几种随机内容类型,我不能硬编码为类常量或配置选项.然而,当我可以使用更容易理解的术语"帖子"时,我不想提及"2".因此,尽管从一个字符串中获取INT值的方法似乎对几个项目相当无冲突.
有没有办法在PHP而不是我建立的方式做到这一点?
$strings = array('post', 'comment', 'blog', 'article', 'forum', 'news', 'page');
foreach( $strings as $string ) {
print $string . ' = ';
$string = str_split($string);
$sum = 0;
foreach( $string as $char ) {
$sum += ord($char);
}
var_dump( $sum );
print '<br />';
}
Run Code Online (Sandbox Code Playgroud)
这与用户输入无关,因此不必担心设计中存在明显的缺陷.
:编辑:
我需要一个数字索引来存储在数据库中以便快速查找.即从"文章"或"新闻"中讲述"帖子".但是我不知道那些1-8类型的内容会被调用,所以我不能在应用程序中将它们硬编码为常量.因此,我能想到的最好的方法是创建每个单词的数字版本(这意味着要检查以确保两个单词不能总结为相同的数字).
如果这是一个超过8个单词的系统,那么这种方法注定要失败,并且总和碰撞的概率很高.此外,如果我可以选择知道将使用哪些单词,那么这也将是一个糟糕的设计,因为类常量会更好.
如您所知,在Java中创建Dom元素的正确方法是执行类似的操作.
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Document d;
Element e;
e = d.createElement("tag");
Run Code Online (Sandbox Code Playgroud)
您需要使用d来生成元素,因为它需要文档上下文.(我不是100%肯定为什么,但也许误解这是我的问题的一部分)
我不明白的是,为什么你不能做这样的事情
Element e;
Element e2;
e2 = e.createElement("anothertag");
Run Code Online (Sandbox Code Playgroud)
由于e已经具有d的上下文,为什么我不能从元素创建另一个元素?它肯定会简化我的设计,而不必在任何地方保留对文档的引用.
我想在ASM上调用Sleep函数.所以我写了以下内容:
push 5000
call Sleep
Run Code Online (Sandbox Code Playgroud)
虽然一切都很顺利,但我还是有这样的想法,每当我在堆栈上推送一个值时,我也应该弹出它(否则它会在程序的后期变得杂乱无章?).我应该弹出它吗?我该怎么办?
我正在尝试使用RSA私钥加密某些内容.
我正在关注这个例子:http:
//www.junkheap.net/content/public_key_encryption_java
但将其转换为使用私钥而不是公共密钥.在这个例子之后,我认为我需要做的是:
那么,步骤:
密钥是从openssl生成的:
openssl genrsa -aes256 -out private.pem 2048
然后转换为DER格式:
openssl rsa -in private.pem -outform DER -out private.der
我生成PKCS8EncodedKeySpec:
byte[] encodedKey = new byte[(int)inputKeyFile.length()];
try {
new FileInputStream(inputKeyFile).read(encodedKey);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(encodedKey);
return privateKeySpec;
Run Code Online (Sandbox Code Playgroud)
然后生成私钥对象:
PrivateKey pk = null;
try {
KeyFactory kf = KeyFactory.getInstance(RSA_METHOD);
pk = …Run Code Online (Sandbox Code Playgroud) 有时需要将字符串的长度与常量进行比较.
例如:
if ( line.length() > 2 )
{
// Do something...
}
Run Code Online (Sandbox Code Playgroud)
但我试图避免在代码中使用"魔术"常量.
通常我使用这样的代码:
if ( line.length() > strlen("[]") )
{
// Do something...
}
Run Code Online (Sandbox Code Playgroud)
由于函数调用,它更具可读性,但效率更高.
我写了模板函数如下:
template<size_t N>
size_t _lenof(const char (&)[N])
{
return N - 1;
}
template<size_t N>
size_t _lenof(const wchar_t (&)[N])
{
return N - 1;
}
// Using:
if ( line.length() > _lenof("[]") )
{
// Do something...
}
Run Code Online (Sandbox Code Playgroud)
在发布版本(VisualStudio 2008)中,它生成了非常好的代码:
cmp dword ptr [esp+27Ch],2
jbe 011D7FA5
Run Code Online (Sandbox Code Playgroud)
好的是编译器在二进制输出中不包含"[]"字符串.
它是特定于编译器的优化还是常见行为?