小编kyl*_*ewm的帖子

Facebook Graph API:从帖子URL中查找图形对象

鉴于公开Facebook帖子的URL,如何在FB Graph API中找到帖子对象?(其次,当通过API访问时,为什么这么多用户提要为空或几乎为空?)

我们希望能够在评论喜欢通过V2.X图形API后,鉴于这篇文章的网址.这样做需要post的对象ID,我们可以做一些有根据的猜测,但是通过API访问实际对象已被证明是不可靠的(适用于某些帖子但不适用于其他帖子).

API的v2引入了应用范围的用户ID,帖子ID通常似乎是{app-scoped user id} _ {unique post id}的形式.以下是使用这些ID的各种组合(全局用户ID,应用程序范围的用户ID和帖子ID)在API中查找帖子的一些尝试的详细信息.

好吧让我们试试另一个方向.我们将浏览用户的Feed,直到找到相关帖子.感觉这更像是API 的预期用例......

facebook facebook-graph-api facebook-graph-api-v2.2 indieweb

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

SWIG:为生成的.py文件添加注释

使用SWIG为C++应用程序生成Python接口,有没有办法让它在生成的.py文件中注释函数?我实际上将整个.h文件放入.i文件中,但是一个小例子:

%module example

bool do_something_interesting(int number, string text);
Run Code Online (Sandbox Code Playgroud)

swig -python example.i 产生:

...
def do_something_interesting(*args):
  return _example.do_something_interesting(*args)
do_something_interesting = _example.do_something_interesting
Run Code Online (Sandbox Code Playgroud)

理想情况下,我希望它能够使用原始方法签名自动添加注释

#bool do_something_interesting(int number, string text)
def do_something_interesting(*args):
  return _example.do_something_interesting(*args)
do_something_interesting = _example.do_something_interesting
Run Code Online (Sandbox Code Playgroud)

但我完全可以在某处写自己的评论(特别是如果评论可能以某种方式在.h文件中).我认为%pythonprepend可能是一个可能的解决方案,但它在函数定义中而不是在它之前插入代码.

编辑:这是我在.h文件中提出的.不是最漂亮的东西,但它会做:

#ifdef SWIG
   %pythonprepend do_something_interesting(int, string) %{
    """Do some interesting thing

    number:Int -- a number
    text:String -- some text

    """
  %}
#endif
bool do_something_interesting(int number, string text);
Run Code Online (Sandbox Code Playgroud)

c++ python swig comments

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

lambda参数,带有可选的返回值

我正在尝试编写一个类似的功能std::for_each,除了正常使用外,还可以使用std::function<bool (param)>.错误的返回值意味着我想要摆脱循环.下面的代码是我到目前为止所获得的代码.

a.visit([&](int) -> void)在评估时,第二次调用不会编译!visitor(i).是否有可能使这项工作或我咆哮错误的树?

我正在使用MSVC 2010,但希望代码通常与C++ 11兼容.

#include <list>
#include <string>
#include <iostream>

struct A 
{
    std::list<int> _lst;

    template<typename _F>
    void visit(_F visitor) 
    {
        for(std::list<int>::const_iterator it = _lst.begin(), end = _lst.end() ; it != end ; it++) {
            int i = *it;
            if (std::is_void<decltype(visitor(i))>::value) {
                visitor(i);
            } else {
               if (!visitor(i)) { // <----- error C2171: '!' : illegal on operands of type 'void'
                   break;
               }
            }
        }
    }

};

int main(int argc, char* …
Run Code Online (Sandbox Code Playgroud)

c++ lambda return-value c++11

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

在Clojure中适当表示2D游戏板

我正在Clojure的一个小游戏中进行学习练习.我想我已经在任何特定时间确定了游戏状态的表示,作为"可移动物"列表和"地形"(板块正方形)的2D矢量矢量.

95%的时间我希望检查2D矢量看起来合适的特定方块中的碰撞.但在少数情况下,我需要转向另一个方向 - 找到符合某些条件的单元格的(x,y)位置.第一次尝试是这样的:

(defn find-cell-row [fn row x y]
  (if (empty? row) nil
    (if (fn (first row)) [x y]
      (find-cell-row fn (rest row) (inc x) y))))

(defn find-cell [fn grid y]
  (if (empty? grid) nil
    (or (find-cell-row fn (first grid) 0 y)
        (find-cell (rest grid) (inc y)))))

(def sample [[\a \b \c][\d \e \f]])
(find-cell #(= % \c) sample 0) ;; => [2 0]
Run Code Online (Sandbox Code Playgroud)

我用map-indexed尝试了一些更简洁的东西,但是很快就变得丑陋而且仍然没有给我我想要的东西.是否有更惯用的方式来进行此搜索,或者我可能会更好地使用不同的数据结构?也许是地图{[xy] - > cell}?使用地图来表示矩阵对我来说感觉很不对:)

clojure data-structures

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