小编Cal*_*orm的帖子

将postgres日期表示转换为ISO 8601字符串

我正在尝试将Postgres日期表示格式化为ISO 8601字符串.我假设有一个Postgres函数可以做到,但我发现文档简短的例子.

我的疑问是

SELECT
  now()::timestamp
Run Code Online (Sandbox Code Playgroud)

返回

[{{2016, 8, 9}, {3, 56, 55, 754181}}]
Run Code Online (Sandbox Code Playgroud)

我正在尝试将日期变成看起来更像的格式 2016-8-9T03:56:55+00:00.

我需要对查询进行哪些更改才能实现此目的?谢谢你的帮助.

postgresql date iso8601 elixir ecto

29
推荐指数
5
解决办法
2万
查看次数

当我取消引用malloc中的NULL指针时,为什么我的程序不会出错?

我一直使用这种malloc风格

int *rc = 0;
rc = malloc(sizeof(*rc));
Run Code Online (Sandbox Code Playgroud)

然而,这并不赛格故障,即使当我打电话sizeof(*rc)我认为rc==0,而且我解引用NULL指针.

c segmentation-fault

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

带有Pthreads的Hello World损坏内存

我正在研究llnl.computing.gov pthreads教程中的一些简单的pthread示例.网站上的程序打印出threadid的地址,但是我想将id的地址传递给PrintHello,然后使用取消引用地址来获取id.我认为在那里睡眠每个线程应该打印8(线程数).代码是

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define NUM_THREADS  8

void *PrintHello(void *threadid)
{
   long *taskid = (long *)threadid;
   sleep(1);
   printf("Hello from thread %ld\n", *taskid);
   pthread_exit(NULL);
} 

int main(int argc, char *argv[])
{
  pthread_t threads[NUM_THREADS];
  int rc;
  long t;

  for(t=0;t<NUM_THREADS;t++) {
    printf("Creating thread %ld\n", t);
    rc = pthread_create(&threads[t], NULL, PrintHello, (void *) &t);
    if (rc) {
      printf("ERROR; return code from pthread_create() is %d\n", rc);
      exit(-1);
    }
 }
 pthread_exit(NULL);
}
Run Code Online (Sandbox Code Playgroud)

当我在Cygwin中编译并运行它时,它会出现堆栈损坏错误.如果我将PrintHello重写为:

void *PrintHello(void *threadid)
{
  long taskid = …
Run Code Online (Sandbox Code Playgroud)

c c++ pthreads segmentation-fault

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

如何调用纯虚函数

我正在使用libPoco创建一个虚拟服务器来测试一些客户端代码.

class ServerRunnable: public Poco::Runnable {
  public:
ServerRunnable(StreamSocket conn) : conn(conn) {
}

void run(){
  string mess("Can you hear me?\n");
  try{
    this->conn.sendBytes(mess.c_str(), mess.size());
  } catch (Poco::Exception& ex){
    cerr << ex.displayText() << endl;
    return;
  }
  cerr << "The message has been sent." << endl;
}

void setConn(StreamSocket inConn){
  this->conn = inConn;
}
  private:
StreamSocket conn;
};


int main(int argc, char **argv){
  ServerSocket s;
  try{
    s.bind(8083, true);
  } catch (Exception &ex){
    cerr << ex.displayText() << endl;
    exit(1);
  }
  s.listen(124);

  Poco::ThreadPool Pool(10, 25, …
Run Code Online (Sandbox Code Playgroud)

c++

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

Rust Actix-Web线程不安全运动

我正在尝试使用actix-web 1.0编写HTTP端点。我已经简化了该函数,以便仅返回传递给该函数的用户,但编译器仍会给出错误。

extern crate actix_web;
extern crate chrono;
extern crate futures;
extern crate listenfd;
#[macro_use]
extern crate serde_derive;
extern crate dotenv;
use actix_web::{error, web, App, Error, HttpResponse, HttpServer};
use futures::future::Future;

#[derive(Debug, Deserialize, Serialize)]
pub struct LoginUser {
    pub username: String,
    pub password: String,
}

pub fn login(
    login_user: web::Json<LoginUser>,
) -> impl Future<Item = HttpResponse, Error = error::BlockingError<Error>> {
    web::block(move || {
        let login_user = login_user.into_inner();
        let user = LoginUser {
            username: login_user.username,
            password: login_user.password,
        };
        Ok(HttpResponse::Ok().json(user))
    })
}

pub …
Run Code Online (Sandbox Code Playgroud)

rust rust-actix actix-web

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

如何输入lodash/fp curried函数?

我正在尝试添加流式打字.我从lodash/fp模块开始,因为这对我自己最有用.但是,我正在努力解决如何正确键入它.

一个简单的例子如果dropRightWhile:

declare function dropRightWhile<T>(iteratee: (val: T)=>boolean, data?: Array<T>): Array<T> | (data: Array<T>)=>Array<T>;
Run Code Online (Sandbox Code Playgroud)

这是我尝试输入它.dropRightWhile必须采取迭代,它可以采取数据.如果你没有给它数据,那么它返回一个获取数据的函数,但如果你给它数据,那么它返回一个数组.

我所做的类型并不严格地在参数个数和返回类型之间建立连接.但是,当我尝试使用咖喱时,dropRightWhile我得到一个错误

var c = dropRightWhile((x) => x> 0); c([0, 1, 2, 3]); error: Function cannot be called on array type

我会认为既然dropRightWhile可以返回一个函数然后我就可以调用它,但似乎数组类型正在阻碍.

有什么建议?

lodash flowtype

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

ifstream :: eof在if语句中抛出类型错误

我有一个A类,它有一个std :: ifstream filestr成员.在其中一个类函数中,我测试以查看流是否已达到eof.

class A
{
private:
   std::ifstream filestr;

public:
   int CalcA(unsigned int *top);  
}
Run Code Online (Sandbox Code Playgroud)

然后在我的cpp文件中

int CalcA(unsigned int *top)
{
   int error;
   while(true)
   {
      (this->filestr).read(buffer, bufLength);

      if((this->filestr).eof);
      {
         error = 1;
         break;
      }
   }
   return error;
}
Run Code Online (Sandbox Code Playgroud)

我收到编译错误

error: argument of type ‘bool (std::basic_ios<char>::)()const’ does not match ‘bool’
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何正确使用eof?或者我收到此错误的任何其他原因?

c++ ifstream

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

当我尝试将一对插入地图时,Qt程序会出现故障

我正在研究我的第一个Qt应用程序,小部件,当我尝试用一<int, QString>对填充标准库映射时,我得到了一个段错误.我的目标是用int键和QString值填充地图.我不知道对是否是最好的方法,所以任何建议都会很棒.

这是除main之外唯一的源文件.

#include "linuxtips.h"
#include "ui_linuxtips.h"

LinuxTips::LinuxTips(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::LinuxTips)
{
  loadRandTip();
  ui->setupUi(this);
}

LinuxTips::~LinuxTips()
{
  delete ui;
}

void LinuxTips::on_learnMore_clicked()
{

}

void LinuxTips::on_viewAll_clicked()
{

}

void LinuxTips::loadRandTip()
{
  int i = 0;
  std::map<int, QString>::iterator it;

  QString line;
  QFile inputFile(":/tipFile.txt");
  inputFile.open(QIODevice::ReadOnly);

  QTextStream in(&inputFile);
  do{
    line = in.readLine();
  //  this->TipMap.insert(it, std::pair<int, QString >(i,line));
    i++;
  }while(!in.atEnd());
}
Run Code Online (Sandbox Code Playgroud)

如果我取消注释this->TipMap.insert(it, std::pair<int, QString >(i,line));,它将运行.由于它是一个seg错误,我确定它是一个内存溢出或空指针,但我只是不确定它是什么.谢谢你的帮助.

c++ qt4 map segmentation-fault

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

抛出对象范围

我想知道抛出的对象是否遵循c ++中与其他所有相同的范围规则.这是一个例子.

try{
  Error err;
  err.num = 10;
  err.str = "This will be thrown."
  throw err;
}
catch(Error e){
  cout << "Error num is: " << e.num << " error string is: " << e.str << endl;
}
Run Code Online (Sandbox Code Playgroud)

这是否有效或是否errtry块中创建的事实阻止它在catch块中使用?

c++ exception-handling exception

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

有没有办法浏览erlang术语存储(ETS)

我有一个使用erlang术语存储的小型Elixir应用程序,我想浏览它并查看存储的内容.有没有办法用Elixir或Erlang做到这一点?

我想知道它有多大,里面有什么.

编辑:我知道我可以查看进程:observer.start,但没有列出的进程或应用程序ets.有Elixir.Hex.Registry.ETS,但状态或其他过程信息看起来不正确.

我也可以打印出来,iex但这不是一次很棒的体验.

erlang elixir ets

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