小编Eri*_*ner的帖子

PHP具有处理递归的能力

我最近在一些地方看到人们说PHP的递归能力很差.最近我为图遍历写了一个递归的php函数,发现它与java相比非常慢.我不知道这是因为php的递归能力还是因为php一般比java慢.

一些谷歌搜索透露了这一点(http://bugs.php.net/bug.php?id=1901)

[1999年8月7日12:25 UTC] zeev at cvs dot php dot net

PHP 4.0(Zend)将堆栈用于密集数据,而不是使用堆.这意味着它的容差递归函数明显低于其他语言.

告诉Zend不要使用堆栈来获取这些数据是相对容易的,而是使用堆来代替 - 这会大大增加可能的递归函数的数量 - 以降低速度的代价.如果您对这样的设置感兴趣,请告诉我,我们可能会添加一个编译时开关.

说php使用堆栈进行密集数据是什么意思?php没有设置运行时堆栈吗?另外,一般情况下,php中的递归比其他语言慢得多吗?多少钱?

谢谢!

php recursion

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

在Java中,对Class.class的引用是做什么的?

我正在构建一个小型的Android应用程序,但这更像是一个Java问题,而不是一个Android问题.查看教程中的行看起来像:

startService(new Intent(this, MyService.class));
Run Code Online (Sandbox Code Playgroud)

"MyService.class"字段到底代表什么?这仅仅是对模板类的引用吗?

谢谢.

java android

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

使用New Graph API在Facebook Canvas App中进行身份验证

我正在构建一个Facebook画布应用程序,它使用Django加载到iframe中.我希望登录过程与Zynga的工作方式类似.在此方法中,如果您未登录,则会重定向到Facebook登录页面,然后再转到应用程序的权限请求页面(没有任何弹出窗口).

据我所知,Zynga必须使用FBML并转发到URL,如下所示:

http://www.facebook.com/login.php?api_key=[api_key]&canvas=1&fbconnect=0&next=[return_url]

无论如何在iframe加载的python应用程序中实现类似的效果?

有一种方法,在这里展示了如何使用新的PHP SDK来实现正确的重定向,但我试图用新的Python SDK其中只有方法:

def get_user_from_cookie(cookies, app_id, app_secret):
"""
Parses the cookie set by the official Facebook JavaScript SDK.
cookies should be a dictionary-like object mapping cookie names to
cookie values.
...
"""
Run Code Online (Sandbox Code Playgroud)

我有一些使用Javascript SDK和get_user_from_cookie方法的工作代码:

<div id="fb-root">
 <script src="http://connect.facebook.net/en_US/all.js"></script>
</div>

<script type="text/javascript">
 FB.init({ apiKey: 'apikey', status: true, cookie: true, xfbml: true});

 FB.Event.subscribe('auth.login', function(response) {
  // Reload the application in the logged-in state
  window.top.location = 'http://apps.facebook.com/myapp/';
 });
</script>
<fb:login-button>Install MyApp</fb:login-button>
Run Code Online (Sandbox Code Playgroud)

此方法的问题在于,它要求用户单击按钮进行登录,然后通过弹出认证屏幕进行操作.(注意:如果直接调用FB.login,也会出现弹出窗口)

那么......有没有办法使用javascript SDK重定向到登录页面而不是将其作为弹出窗口加载?

谢谢你的帮助!--Eric

javascript python django facebook

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

iOS7 AVMutableVideoCompositionLayerInstruction导致视频帧冻结

我正在通过AVMutableVideoCompositionLayerInstructioniOS7 SDK 修改一些视频.

以下代码用于iOS 6.1.3,但在iOS7中,视频在第一帧被冻结(尽管我仍然可以听到音频确定).我摆脱了我申请的所有实际转换,以验证单独添加视频合成会导致问题.

AVURLAsset* videoAsset = [[AVURLAsset alloc] initWithURL:inputFileURL options:NULL];
AVAssetTrack *videoAssetTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];

AVMutableVideoCompositionLayerInstruction *layerInstruction =
[AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoAssetTrack];

AVMutableVideoComposition *mainComposition = [AVMutableVideoComposition videoComposition];
AVMutableVideoCompositionInstruction *mainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
mainInstruction.layerInstructions = [NSArray arrayWithObject:layerInstruction];
mainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, videoAsset.duration);
mainComposition.instructions = [NSArray arrayWithObject:mainInstruction];
mainComposition.frameDuration = videoAsset.duration;
mainComposition.renderSize = CGSizeMake(320, 320);

...
exportSession.videoComposition = mainComposition;
Run Code Online (Sandbox Code Playgroud)

如果我没有设置videoComposition属性exportSession然后视频记录确定,但我不能应用任何转换.有人知道是什么原因引起的吗?

谢谢.

objective-c ios ios6 ios7

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

如何在RealmSwift中为对象生成id?

我正在使用RealmSwift.为对象生成id的最佳/规范方法是什么?

这是我想出的:

class MyObject: Object {
    dynamic var id = ""
    dynamic var createdAt = NSDate()

    override class func primaryKey() -> String {
        return "id"
    }

    func save() {
        let realm = try! Realm()

        if(self.id == "") {
            while(true) {
                let newId = NSUUID().UUIDString
                let saying = realm.objectForPrimaryKey(MyObject.self, key: newId)
                if(saying == nil) {
                    self.id = newId
                    break
                }
            }
        }

        try! realm.write {
            realm.add(self)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想要一个将对象持久保存到Realm的函数,并根据id覆盖或创建一个新函数.这似乎工作正常,但我不确定是否有内置的东西来做到这一点.或者,还有更好的方法?

谢谢.

realm swift

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

如何使用PushNotificationIOS在React Native中检查是否禁用了推送通知?

我想确定是否使用React Native和PushNotificationIOS的用户禁用了推送通知。

PushNotificationIOS具有方法checkPermissions,但此方法仅告诉我是否启用了通知。

我想使用React Native来判断我的应用是否提示用户启用通知而用户拒绝了该权限,或者用户是否独立进入设置和禁用通知。

在本机代码,你会使用UNUserNotificationCenter,并检查getNotificationSettingsauthorizationStatus与价值.denied

谢谢。

react-native

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

使用php创建和提供压缩文件

我正在尝试使用以下代码从目录创建zip文件,并通过http下载将其提供给用户:

 // write the file
file_put_contents($path . "/index.html", $output);

// zip up the contents
chdir($path);
exec("zip -r {$course->name} ./");

$filename = "{$course->name}.zip";

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' .urlencode($filename));
header('Content-Transfer-Encoding: binary');

readfile($filename);
Run Code Online (Sandbox Code Playgroud)

我能够创建zip文件,但通过http下载它不起作用.如果我下载使用ftp客户端创建的zip文件,那么Mac的Stuffit Expander就可以解压缩文件了,但如果我通过http下载它,mac unzipper会创建一个无限循环.我的意思是说我下载的文件名为course.zip,然后解压缩文件给出course.zip.cpgz并解压缩该文件再次给出course.zip ..然后再打开.

有人有主意吗?

谢谢!

php zip gzip unzip

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

将函数从递归转换为迭代

我有这个函数,我写的是非常慢,因为PHP不能很好地处理递归.我试图将它转换为while循环,但我无法绕过如何做到这一点.

谁能给我一些提示?

    public function findRoute($curLoc, $distanceSoFar, $expectedValue) {

    $this->locationsVisited[$curLoc] = true;
    $expectedValue += $this->locationsArray[$curLoc]*$distanceSoFar;

    $at_end = true;
    for($i = 1; $i < $this->numLocations; $i++) {
        if($this->locationsVisited[$i] == false) {
            $at_end = false;

            if($expectedValue < $this->bestEV)
                $this->findRoute($i, $distanceSoFar + $this->distanceArray[$curLoc][$i], $expectedValue);
        }
    }

    $this->locationsVisited[$curLoc] = false;

    if($at_end) {
        if($expectedValue < $this->bestEV) {
            $this->bestEV = $expectedValue;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

php iteration recursion

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

Swift integerForKey:如果指定的key不存在,这个方法返回0

我想在 NSUserDefaults 中存储一个可能为 0 的整数。如何区分存储为 0 的整数和 NSUserDefaults 中不存在的键?

根据NSUserDefaults 文档, integerForKey如果 NSUserDefaults 中不存在该键,则返回 0。所以,我的问题是:如何区分不存在的密钥和我存储为 0 的密钥?

nsuserdefaults ios swift

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

FieldError:select_related:'userinfo'中给出的无效字段名称.选择是:userinfo

尝试使用,当我得到这个错误only使用select_related.

FieldError: Invalid field name(s) given in select_related: 'userinfo'. Choices are: userinfo
Run Code Online (Sandbox Code Playgroud)

它报告我试图选择的字段是一个错误,这有点奇怪.这是我的查询:

users_with_schools = User.objects.select_related('userinfo').only(
    "id",
    "date_joined",
    "userinfo__last_coordinates_id",
    "userinfo__school_id"
).filter(
    userinfo__school_id__isnull=False,
    date_joined__gte=start_date
)
Run Code Online (Sandbox Code Playgroud)

我已经能够在我的代码中的其他地方使用select_related,only所以我不知道为什么会发生这种情况.

编辑:这是完整的追溯

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "env/lib/python2.7/site-packages/django/db/models/query.py", line 138, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "env/lib/python2.7/site-packages/django/db/models/query.py", line 162, in __iter__
    self._fetch_all()
  File "env/lib/python2.7/site-packages/django/db/models/query.py", line 965, in _fetch_all
    self._result_cache = list(self.iterator())
  File "env/lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
    results = …
Run Code Online (Sandbox Code Playgroud)

python django django-queryset

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