小编Mic*_*son的帖子

Facebook签署了请求问题

我想为我的Facebook页面写一个fangate,但它没有工作,我没有在互联网上找到任何帮助

require 'facebook.php';

$app_id = '16850872653xxxx';
$app_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));

$signed_request = $_REQUEST['signed_request'];

//echo $signed_request;

list($encoded_sig, $payload) = explode('.', $signed_request, 2); 


// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);

// check sig
$expected_sig = hash_hmac('sha256', $payload, $app_secret, $raw = true);

function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}

if($signed_request->page->liked) {
echo "This content is for Fans only!";
} else {
echo "Please click on …
Run Code Online (Sandbox Code Playgroud)

json facebook github

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

C++如何使用ifstream变量

void searchString(const string selection,const string filename)
{
    ifstream myfile;
    string sline;
    string sdata;
    myfile.open(filename);
    while(!myfile.eof())
    {
        getline(myfile,sline);
        sdata = sdata + sline;
    }
Run Code Online (Sandbox Code Playgroud)

我如何使用字符串文件名作为myfile.open(文件名)

最初我使用的是file.txt,但是如果我使用一个传入函数的变量,比如string filename,它会给我一个错误

myfile.open("file.txt");
Run Code Online (Sandbox Code Playgroud)

错误消息如下:

main.cpp:203:25: error: no matching function for call to ‘std::basic_ifstream<char>::open(const string&)’
main.cpp:203:25: note: candidate is:
/usr/include/c++/4.6/fstream:531:7: note: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
/usr/include/c++/4.6/fstream:531:7: note:   no known conversion for argument 1 from ‘const string {aka const std::basic_string<char>}’ to ‘const char*’
make: *** [main.o] Error …
Run Code Online (Sandbox Code Playgroud)

c++

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

C++模板专业化问题

我的代码归结为:

//Just a templated array class .. implementation doesn't matter
template<int N>
struct Array {};

//A simple Traits like class
template<typename T>
struct MyTraits {}

//Specialization of the traits class
template<int N>
struct Foo< Array<N> >
{
  static void monkey() {};
}

int main()
{
  Foo< Array<3> >::monkey();
}
Run Code Online (Sandbox Code Playgroud)

不幸的是编译器不喜欢它......

test.cpp: In function ‘int main()’:
test.cpp|17| error: ‘monkey’ is not a member of ‘Foo<Array<3> >’
Run Code Online (Sandbox Code Playgroud)

我做错了什么,我该如何解决?谢谢

c++

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

C&lua metatable用于面向对象的访问

我有这样的东西:(它实际上是C++,但在这种简化的形式中,它没有特定的C++)

struct Blob;

// Some key-value accessors on Blob
char * blob_get_value( Blob * b, char * key );
void set_value( Blob * b, char * key, char * value); 


//Some lua wrappers for these functions
int blob_get_value_lua( lua_State * L );
int blob_set_value_lua( lua_State * L );
Run Code Online (Sandbox Code Playgroud)

我以语法清晰的方式使这些可访问.目前我将Blob对象公开为userdata并将get get和set插入metatable,使用此方法我可以这样做:

blob = Blob.new()
blob:set("greeting","hello")
print( blob:get("greeting") )
Run Code Online (Sandbox Code Playgroud)

但我更喜欢

blob = Blob.new()
blob.greeting = hello
print( blob.greeting )
Run Code Online (Sandbox Code Playgroud)

我知道这可以通过设置__indexto blob_get_value_lua__newindexto来完成blob_set_value_lua.但是,进行此更改将破坏向后兼容性.

有没有简单的方法可以同时使用这两种语法?

c lua

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

在haskell中解析一个字符串

我有一些字符串,我想解析成一个"块"列表.我的字符串看起来像这样

"some text [[anchor]] some more text, [[another anchor]]. An isolated ["
Run Code Online (Sandbox Code Playgroud)

而且我希望得到这样的东西

[
   TextChunk "some text ",
   Anchor "anchor",
   TextChunk " some more text, "
   Anchor "another anchor",
   TextChunk ". An isolated ["
]
Run Code Online (Sandbox Code Playgroud)

我已经成功地编写了一个能够满足我需要的功能和类型,但它们似乎过于丑陋.有没有更好的方法来做到这一点?

data Token = TextChunk String | Anchor String deriving (Show)
data TokenizerMode = EatString | EatAnchor deriving (Show)

tokenize::[String] -> [Token]
tokenize xs =  
  let (_,_,tokens) = tokenize' (EatString, unlines xs, [TextChunk ""])
  in reverse tokens

tokenize' :: (TokenizerMode, String, [Token]) -> (TokenizerMode, String,[Token]) …
Run Code Online (Sandbox Code Playgroud)

haskell

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

将Rust指针传递给C时,我应该得到0x1吗?

我正在尝试在Rust中实现一个基本库,它创建一个对象并将其指针返回给C.我得到的指针看起来不像它在堆上 - 当我打印它时我得到0x1:

use std::fmt;

pub struct SndbDB {}

impl SndbDB {
    fn new() -> SndbDB {
        SndbDB {}
    }
}

impl fmt::Display for SndbDB {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "(sndb_db)")
    }
}

// Implement a destructor just so we can see when the object is destroyed.
impl Drop for SndbDB {
    fn drop(&mut self) {
        println!("[rust] dropping {}", self);
    }
}

#[no_mangle]
pub extern "C" fn sndb_db_create() -> *mut SndbDB {
    let …
Run Code Online (Sandbox Code Playgroud)

c ffi rust

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

如何"真正"清除全局PHP数组

注意:似乎我对发生的事情是错误的,并且没有使用的问题$a = array();.这是因为对数组的所有赋值都是通过复制.(我原本以为有一些引用的访问导致了问题 - 但这只是一个错字.我在下面的答案中添加了一些细节.

我有一些看起来像这样的PHP:

$myArray = array();

function useArray() {
  global $myArray;
  // ... do something with myArray ...
}

function clearArray() {
  global $myArray;
  // ... Somehow clear the global array ...
}
Run Code Online (Sandbox Code Playgroud)

我知道这从设计角度来看很糟糕,但是我需要解决一些我无法改变的第三方代码......

我的问题是我可以在clearArray函数中添加什么来使其工作? 通常使用$myArray=array();unset($myArray); 不工作的建议,因为它们只更改本地版本,而不是全局版本.我想我可以循环遍历数组中的键并依次取消设置 - 就像这样:

function clearArray() {
  global $myArray;
  foreach($key in array_keys($myArray) ) {
     unset( $myArray[$key] );
  }
}
Run Code Online (Sandbox Code Playgroud)

但这似乎很丑陋而且不清楚.有更好的解决方案吗?

php

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

C++中的对象声明

关于c ++中的以下代码,我有两个问题.

  1. 这条线A obj()main()意思是什么?它没有给出任何错误.

  2. 为什么下一行obj.fun();会出现以下错误?

    请求'obj'中的成员'fun',这是非类型'A()'

代码是:

#include<iostream>
using namespace std;

class A{
    public:
        A(){
            cout<<"Constuctor called\n";
        }
        ~A(){
            cout<<"Destuctor called\n";
        }
        void fun(){
            cout<<"YES";
        }
};

int main(){
    A obj();
    obj.fun();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ constructor object

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

标签 统计

c++ ×3

c ×2

constructor ×1

facebook ×1

ffi ×1

github ×1

haskell ×1

json ×1

lua ×1

object ×1

php ×1

rust ×1