问题列表 - 第18151页

如何在数组中对数组进行排序?

我需要根据数组的一个数组值对数组中的数组进行排序.

例如:

$data = array( array( 1, "Article One", 132, 12402773, 3 ),
               array( 2, "Article Two", 251, 12519283, 5 ),
               array( 3, "Article Three", 107, 12411321, 3 ),
               array( 4, "Article Four", 501, 12228135, 4 ) );
Run Code Online (Sandbox Code Playgroud)

默认情况下,如果我打印每个数组的第二个元素:

  • 第一条
  • 第二条
  • 第三条
  • 第四条

我需要通过子数组的第3个元素按降序对其进行排序.

所以它会是这样的:

  • 第四条
  • 第二条
  • 第一条
  • 第三条

因为501> 251> 132> 107.

有什么建议吗?

php

4
推荐指数
1
解决办法
1718
查看次数

如何编写这两个(ANSI)SQL查询?

我有一个表格,其数据如下所示:

create table demo_patient_info (
  attend timestamp,  
  patient_id int, 
  blood_pressure double
);
Run Code Online (Sandbox Code Playgroud)

我想编写(最好是ANSI)SQL查询,允许我执行以下操作:

QUERY1:

返回所有患者的bp之间的差异(使用WHERE子句限制笛卡尔积中返回的行数)

QUERY2:

返回每个患者的bp与表中一个特定(即指定)患者之间的差异

sql

1
推荐指数
1
解决办法
205
查看次数

为什么fsockopen在PHP中发送POST请求时有性能问题而不是fopen?

我尝试了两种不同的实现来模拟POST表单.一个使用fsockopen(例如:http://www.faqts.com/knowledge_base/view.phtml/aid/7962)和其他用途fopen(例如:http://netevil.org/blog/2006/nov/http- post-from-php-without-curl).

我遇到了一些严重的性能问题fsockopen- 当我使用调试器逐步完成它时,一切似乎都运行得很好,但是当我没有附加调试器时,页面需要花费很长的时间来加载(可能超过10秒). fopen完美的工作(加上我不必解析响应头).有谁知道为什么fsockopen会出现这些性能问题?是否与超时设置有关?

我在下面提供了我的代码.


//fsockopen implementation
/**
 * The class that posts form data to a specified URL.
 * @package Core
 * @subpackage Classes
 */
class SU_form_poster_class
{
    /**
     * The file handle which is created when a form is posted.
     * @var resource
     */
    protected $file_handle;

    protected $port;

    protected $timeout;


    /**
     * Creates a new instance of this class.
     * …
Run Code Online (Sandbox Code Playgroud)

php performance post fopen fsockopen

2
推荐指数
1
解决办法
1200
查看次数

C vs C++代码优化,用于简单的数组创建和i/o

我一直试图说服我的朋友避免使用动态分配的数组并开始转移到STL向量.我给他发了一些示例代码来展示可以用STL和仿函数/生成器完成的一些事情:

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

#define EVENTS 10000000

struct random_double {
  double operator() () { return (double)rand()/RAND_MAX; }
};  

int main(int argc, char **argv){

  std::vector<double> vd (EVENTS);

  generate(vd.begin(), vd.end(), random_double());
  copy(vd.begin(), vd.end(), std::ostream_iterator<double>(std::cout, "\n"));

  return 0;
} 
Run Code Online (Sandbox Code Playgroud)

他对此的回答,虽然他觉得它更优雅,但是他自己的代码更快(几乎是2倍!)这是他回答的C代码:

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>

#define EVENTS 10000000

__inline double random_double() {
  return (double)rand()/RAND_MAX;
}


int main(int argc, char **argv){
  unsigned int i;
  double *vd;
  vd = (double *) malloc(EVENTS*sizeof(double));

  for(i=0;i<EVENTS;i++){ vd[i]=random_double(); }

  for(i=0;i<EVENTS;i++){ printf("%lf\n",vd[i]); …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-construction io optimization

2
推荐指数
2
解决办法
855
查看次数

log4net配置异常

我正在使用log4net进行日志记录.我的日志配置存储在单独的文件中.

Web.Config中:ConfigSections

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
Run Code Online (Sandbox Code Playgroud)

在AssemblyInfo.cs中指定我的配置文件

[assembly: log4net.Config.XmlConfigurator(ConfigFile="Log4Net.config", Watch = true)] 
Run Code Online (Sandbox Code Playgroud)

当我初始化我的LogManager时,我收到此错误

"System.TypeLoadException"
message: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'.
Run Code Online (Sandbox Code Playgroud)

是的它说"Log4NetConfigurationSectionHlandler",它不是一个错字

后来,这个错误

An error occurred creating the configuration section handler for log4net: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'. 
Run Code Online (Sandbox Code Playgroud)

编辑:试过Mauricio Scheffer的建议

拿到

log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
Run Code Online (Sandbox Code Playgroud)

logging log4net web-config configsection

19
推荐指数
1
解决办法
2万
查看次数

未加密的SSL协议?

是否可以通过https发送未加密的消息?例如,要求进行证书验证和授权,但不加密通过套接字发送的实际数据?

encryption ssl https certificate pki

7
推荐指数
2
解决办法
7143
查看次数

C#闭包,为什么循环变量通过引用捕获?

在这个例子中,我试图通过值传递,但是传递了引用.

for (int i = 0; i < 10; i++)
{
    Thread t = new Thread(() => new PhoneJobTest(i);
    t.Start();
}
Run Code Online (Sandbox Code Playgroud)

这样可以解决:

 for (int i = 0; i < 10; i++)
{
    int jobNum = i;
    Thread t = new Thread(() => new PhoneJobTest(jobNum);
    t.Start();
}
Run Code Online (Sandbox Code Playgroud)

这是怎么回事?为什么原始示例传递引用?

c#

10
推荐指数
2
解决办法
3446
查看次数

防止RegEx在大型比赛中挂起

这是日期的一个很好的正则表达式...但它在我尝试的这一页上无限期挂起...我想尝试这个页面(http://pleac.sourceforge.net/pleac_python/datesandtimes.html)它确实有很多日期,我想抓住所有这些日期.我不明白为什么它在其他页面上没有悬挂...为什么我的正则表达式挂起和/或我怎么能清理它以使它更好/更有效?

Python代码:

monthnames = "(?:Jan\w*|Feb\w*|Mar\w*|Apr\w*|May|Jun\w?|Jul\w?|Aug\w*|Sep\w*|Oct\w*|Nov(?:ember)?|Dec\w*)"

pattern1 = re.compile(r"(\d{1,4}[\/\\\-]+\d{1,2}[\/\\\-]+\d{2,4})")

pattern4 = re.compile(r"(?:[\d]*[\,\.\ \-]+)*%s(?:[\,\.\ \-]+[\d]+[stndrh]*)+[:\d]*[\ ]?(PM)?(AM)?([\ \-\+\d]{4,7}|[UTCESTGMT\ ]{2,4})*"%monthnames, re.I)

patterns = [pattern4, pattern1]

for pattern in patterns:
    print re.findall(pattern, s)
Run Code Online (Sandbox Code Playgroud)

顺便说一句...当我说我试图反对这个网站..我正在尝试它反对网页来源.

python regex

3
推荐指数
1
解决办法
3401
查看次数

来自void指针缓冲区的struct实例化

这里有一些看起来很有趣的C++代码,但我知道它有效.

有一个结构定义,在程序中我们使用void指针分配内存.然后使用分配的缓冲区创建结构.

这是一些代码

typedef struct{
 char buffer[1024];
} MyStruct

int main()
{
   MyStruct* mystruct_ptr = 0;

   void* ptr = malloc(sizeof(MyStruct));

   // This is the line that I don't understand
   mystruct_ptr = new (ptr) MyStruct();

   free(ptr);

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

代码有更多的东西,但这是它的要点.

我没有测试过这段代码,但我正在查看的代码经过了很好的测试,并且可以运行.但是怎么样?

谢谢.

编辑:修复了内存泄漏.

c++ struct allocation void-pointers placement-new

4
推荐指数
2
解决办法
1278
查看次数

通过WCF序列化异常

我有一个在使用WCF连接回服务器的远程系统上运行的任务.任务很可能会抛出异常,我希望将这些异常引导回服务器.基本上我想做这样的事情:

客户:

server.SendException(new UnauthorizedAccessException("Some Exception"));
Run Code Online (Sandbox Code Playgroud)

服务器:

public void SendException(Exception e)
{
    throw e;
}
Run Code Online (Sandbox Code Playgroud)

合同:

[ServiceContract]
public interface IServerContract
{
    [OperationContract]
    void SendException(Exception e);
}
Run Code Online (Sandbox Code Playgroud)

我一直在阅读有关故障异常的一些内容,但根据我的理解,它们用于在通过WCF调用的方法中运行的特定异常.我想要的是发送应用程序抛出WCF上下文之外的任何类型的异常,然后将它们传回服务器进行进一步处理.如果它有助于解决方案,则服务器还具有返回客户端的连接.

c# wcf exception-handling

12
推荐指数
2
解决办法
7372
查看次数