小编Jef*_*son的帖子

Node.js和postgres LISTEN

我想使用Heroku,PostgreSQL和Node.js,并设置它,以便我随时在postgres数据库中添加记录Node.js将该行的内容打印到控制台.

我试图将它设置为以下指示:
http : //lheurt.blogspot.com/2011/11/listen-to-postgresql-inserts-with.html
http://bjorngylling.com/2011-04-13/ Postgres的-听-通知-与节点,js.html

这是node.js代码

var pg = require('pg');
conString = '/*my database connection*/';

var client = new pg.Client(conString);
client.connect(function(err) {
  if(err) {
    return console.error('could not connect to postgres', err);
  }
    client.connect();
    client.query('LISTEN "loc_update"');
    client.on('notification', function(data) {
        console.log(data.payload);
    });
});
Run Code Online (Sandbox Code Playgroud)

这是在postgres数据库上执行的函数

    String function = "CREATE FUNCTION notify_trigger() RETURNS trigger AS $$ "
            + "DECLARE "
            + "BEGIN "
            + "PERFORM pg_notify('loc_update', TG_TABLE_NAME || ',longitude,' ||    NEW.longitude || ',latitude,' || NEW.latitude );"
            + "RETURN new;"
            + "END;"
            + …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous heroku node.js heroku-postgres

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

Mac OSX 10.7.4,Xcode 4.4.1,没有<array>头文件?

我正在编写一个程序,它将使用C++标准库的数组容器来保存一些对象.但是,每当我尝试在我的程序中包含以下代码行时:

#include <array>
Run Code Online (Sandbox Code Playgroud)

我在编译时收到以下错误:

75-143-76-177:soft jeffersonhudson$ g++ mms.cpp -o mms
mms.cpp:5:17: error: array: No such file or directory 
75-143-76-177:soft jeffersonhudson$ 
Run Code Online (Sandbox Code Playgroud)

注释#include让我编译得很好.当然我忽略了一些简单的事情?我在Xcode中安装了"命令行工具",我还缺少什么吗?

编辑:

我在计算机上找到了阵列的位置

/usr/clang-ide/lib/c++/v1
Run Code Online (Sandbox Code Playgroud)

知道了,我该怎么办?

arrays xcode g++ include

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

简单程序中的奇怪C错误(作业)

下面是一些应该接受来自控制台的整数输入的简单代码.它一直正常工作,直到给出无效(非整数)输入.

 1 #include <stdio.h>
 2 
 3 int main()
 4 {
 5   int x = 0;
 6   int inp = 0;
 7   int nums[20]; 
 8   int idx = 0;
 9   for(;;){
10     printf("Enter an integer: ");
11     inp=scanf("%d", &x);
12     if(inp == 0){
13       printf("Error: not an integer\n");
14     }
15     else{
16       if(idx<20){
17         nums[idx] = x;
18         idx++;
19       }
20     } 
21   }
22   return 0;
23 }
Run Code Online (Sandbox Code Playgroud)

这是gdb的输出,显示我在输入值"g"后单步执行程序.看看它如何跳转到第18行,然后无法从用户那里寻找进一步的输入.

Starting program: /Users/jeffersonhudson/xxxx/hw1 
Enter an integer: g

Breakpoint 1, …
Run Code Online (Sandbox Code Playgroud)

c io

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

C++,检查两个字符串的大小写不敏感

可能重复:
C++中不区分大小写的字符串比较

我已经为c ++编写了一些代码来比较两个字符串的相等性.我想要的是校对.我计划将来使用它来制作更多的程序,所以这个功能很好地完成它的工作很重要.这个功能看起来像可重复使用,便携式等吗?是否有更"最新"的方法来做到这一点?我用过ac库,但这是一个c ++程序,是禁忌吗?

谢谢,JH.

//function to compare two strings regardless of case 
//-- returns true if the two strings are equal
//-- returns false if
//  --the strings are unequal
//  --one of the strings is longer than 255 chars
bool isEqual(string str1, string str2){

  if(str1.length()!=str2.length())  //the strings are different lengths,
    return false;               //they can't be equal
  if((str1.length()>255) || (str2.length()>255))
    return false;

  char * cstr1 = new char [str1.length()+1];
  strcpy (cstr1, str1.c_str());
  char * cstr2 = new char …
Run Code Online (Sandbox Code Playgroud)

c++ code-reuse function

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

PostgreSQL:哪种数据类型更适合这种情况?

我正在构建一个数据库,用于定义和跟踪组织内部使用的文档.这些文件中的每一个都有与之相关的类别.将每个文档的类别作为"TEXT"存储在主表中是否更有效,或者将每个文档的类别存储为"SMALLINT"更高效,并且具有将该值等同于该值的查找表一个"TEXT"字段?

postgresql performance lookup-tables

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

为什么我的CSS没有呈现?

这是我的网页内容:

  1 <html>
  2 <head>
  3     <link ref="stylesheet" type="text/css" href="main.css" media="all">
  4 </head>
  5 <body>
  6 <a href="link4">Link4</a>
  7 <br>
  8 <a href="link3">Link3</a>
  9 <br>
 10 <a href="link2">Link2</a>
 11 <br>
 12 <a href="link1">Link1</a>
 13 </body>
 14 </html>
Run Code Online (Sandbox Code Playgroud)

这是我的CSS文件:

  1 body {
  2     background-color:#000000;
  3 }
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我只想要一个使背景变黑的外部样式表

html css

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

指向模板抽象类的指针向量?

有人能告诉我为什么下面的代码无法编译吗?我试图自己解决这个问题,但我发现的每个答案似乎都与当前的问题略有不同。这是尝试编译的结果:

\n\n
jefferson@ubuntu:~$ g++ -std=c++14 templates.cpp\ntemplates.cpp: In function \xe2\x80\x98int main()\xe2\x80\x99:\ntemplates.cpp:26:19: error: template argument 1 is invalid\n   std::vector<Foo*> flubs;\n                   ^\ntemplates.cpp:26:19: error: template argument 2 is invalid\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是有问题的代码:

\n\n
  1 #include <stdio.h>\n  2 #include <vector>\n  3 template <class T>\n  4 class Foo {\n  5   public:\n  6     virtual void f() const = 0;\n  7 };\n  8\n  9 class Bar : public Foo<Bar> {\n 10   public:\n 11     void f() const { printf("foobar\\n"); };\n 12 };\n 13\n 14 class Baz : public Foo<Baz> {\n …
Run Code Online (Sandbox Code Playgroud)

c++ generics templates abstract-class compiler-errors

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