我有一个非常奇怪的问题..我真的希望有人有答案,因为我不知道还有什么要问的.
我正在用C++编写一个cgi应用程序,它由Apache执行并输出HTML代码.我自己压缩HTML输出 - 从我的C++应用程序中 - 因为我的Web主机由于某种原因不支持mod_deflate.
我用Firefox 2,Firefox 3,Opera 9,Opera 10,谷歌Chrome,Safari,IE6,IE7,IE8,甚至wget测试了它.除了IE8之外,它适用于任何东西.
IE8只是说"Internet Explorer无法显示网页",没有任何信息.我知道这是因为压缩只是因为它可以工作,如果我禁用它.
你知道我做错了什么吗?
我使用zlib来压缩它,确切的代码是:
/* Compress it */
int compressed_output_size = content.length() + (content.length() * 0.2) + 16;
char *compressed_output = (char *)Alloc(compressed_output_size);
int compressed_output_length;
Compress(compressed_output, compressed_output_size, (void *)content.c_str(), content.length(), &compressed_output_length);
/* Send the compressed header */
cout << "Content-Encoding: deflate\r\n";
cout << boost::format("Content-Length: %d\r\n") % compressed_output_length;
cgiHeaderContentType("text/html");
cout.write(compressed_output, compressed_output_length);
static void Compress(void *to, size_t to_size, void *from, size_t from_size, int *final_size)
{
int ret;
z_stream stream; …Run Code Online (Sandbox Code Playgroud) 在设计用于配置库/实用程序的C API时,我有一个同事,他更喜欢将所有配置参数集中到一个函数调用中.例如:
int set_diagnostic_email_config( char *to_address,
bool include_timestamp,
bool send_for_crashes,
bool send_daily_status,
bool send_on_event1,
bool send_on_event2 )
Run Code Online (Sandbox Code Playgroud)
一个类似的"get"函数存在许多参数..这个方法的主要优点是如果有人添加了一个新选项,例如"bool send_on_event3",那么因为原型改变了你被迫更新每个地方这个函数调用是使用(假设人们称之为多个地方).
我更喜欢以下内容:
int get_diagnostic_email_config( struct email_config *p_config );
int set_diagnostic_email_config( struct email_config *p_config );
Run Code Online (Sandbox Code Playgroud)
您只需根据需要更改结构元素.但是......如果有人更新了email_config"结构,它不会强迫人们更新所有使用它的地方(即使我们经常想......).而且我的同事抱怨说如果有人试图初始化手动"email_config",然后如果事情后来添加,那么这些新字段将被取消初始化而没有警告.
关于哪种方法首选,是否有任何强烈的共识?或者还有另一种我想念的选择?
有没有办法以编程方式跟踪Java EE应用服务器上特定会话的大小,或者我是否必须使用应用服务器的供应商特定工具来执行此操作?
两种情况:
我正在使用Eratosthenes的Sieve 解决Sphere的在线评判Prime Generator.
我的代码适用于提供的测试用例.但是..因为问题清楚地表明:
输入以单行中的测试用例数t开始(t <= 10).在接下来的t行中的每一行中,存在由空格分隔的两个数m和n(1 <= m <= n <= 1000000000,nm <= 100000).
我知道的方法Integer.parseInt()处理非常大的数字和在线法官表明一个异常被抛出时,抛出一个异常,所以我改变了每一个案件parseInt到parseLong在我的代码.
嗯,在Netbeans 6.5上运行良好,m和n的值很小.
package sphere;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main{
public static void runEratosthenesSieve(long lowerBound, long upperBound) {
long upperBoundSquareRoot = (long) Math.sqrt(upperBound);
boolean[] isComposite = new boolean[(int)upperBound + 1];
for (int m = 2 /*int m = lowerBound*/; m <= upperBoundSquareRoot; m++) {
if (!isComposite[m]) {
if (m>=lowerBound) {System.out.println(m);}
for (int k …Run Code Online (Sandbox Code Playgroud) 我目前正在观看log4j输出的XML文件.我有一个自定义查看器,在GUI中显示日志输出.我需要观察这个文件何时更新,以便GUI可以重新解析和更新自己.在C#中有一个FileWatcher概念,所以在Windows上没有probs,但我在Linux上使用C有什么选择.
有没有一种标准的方法在unix和linux版本(POSIX可能)上执行此操作?
谢谢
抽象这种模式的最佳方法是什么:
class MyClass
attr_accessor :foo, :bar
def initialize(foo, bar)
@foo, @bar = foo, bar
end
end
Run Code Online (Sandbox Code Playgroud)
一个好的解决方案应该考虑超类,并且能够处理仍然能够使用初始化程序来执行更多操作.在您的解决方案中不牺牲性能的额外要点.
我听说可以在Windows服务器上使用PHP(可能高于6.0)来捕获网页.
我得到了一些示例代码并进行了测试 但没有正确执行的代码.
如果您知道一些正确的方法来捕获网页将其保存在Web应用程序中的图像文件?
请教我.
使用CLANG构建代码时遇到此错误:
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:31,
from /Users/waspfish/Documents/NanaimoStudio/Projects/iPhoneMonk/Projects/IdeaOrganizer/IdeaOrganizer_Prefix.pch:13,
from :1:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UILocalizedIndexedCollation.h:13: error: syntax error before ‘AT_NAME’ token
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UILocalizedIndexedCollation.h:21: error: syntax error before ‘}’ token
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/System/Library/Frameworks/UIKit.framework/Headers/UILocalizedIndexedCollation.h:23: fatal error: method definition not in @implementation context
compilation terminated.
{standard input}:32:FATAL:.abort detected. Assembly stopping.
我最终不得不从UIKit.h中排除UILocalizedIndexedCollation.h并且一切都很好.知道什么可能导致问题吗?我无法想象Apple正在发送有缺陷的头文件.
嗨,我正在尝试编写一个Windows虚拟COM端口驱动程序,它将数据转移到IP地址.任何指针,最佳实践都会有所帮助?
c ×2
c++ ×2
java ×2
abstraction ×1
apache ×1
asp.net ×1
bignum ×1
cgi ×1
clang ×1
compression ×1
driver ×1
file ×1
iphone ×1
java-ee ×1
javascript ×1
linux ×1
php ×1
ruby ×1
serial-port ×1
tcp ×1