小编zak*_*ces的帖子

生成随机文件名安全和URL安全字符串

我创建了一个系统,用户将视频上传到我服务器的文件系统,我需要一种方法来为视频文件生成唯一的文件名.我应该使用random.getrandbits吗?有没有办法用字母和数字的组合来做到这一点?

python string random

7
推荐指数
3
解决办法
2586
查看次数

如何配置Pyramid的JSON编码?

我正在尝试返回这样的函数:

@view_config(route_name='CreateNewAccount', request_method='GET', renderer='json')
def returnJSON(color, message=None):
    return  json.dumps({ "color" : "color", "message" : "message" }, default=json_util.default)
Run Code Online (Sandbox Code Playgroud)

由于Pyramid自己的JSON编码,它出现了双重编码,如下所示:

"{\"color\": \"color\", \"message\": \"message\"}"
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?我需要使用default参数(或等价物),因为它是Mongo的自定义类型所必需的.

python json pymongo pyramid

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

如何使用AVPlayer播放mp4资源?

我在项目导航器中包含了一个mp4资源.我想在AVPlayer中播放它.我知道如何为AVPlayer对象创建一个AVPlayerItem,所以现在我想加载适当的AVAsset指向我的mp4资源.问题是AVAsset只有一个assetWithURL:方法来创建AVAsset.我想要一个assetWithName:方法,但该方法不存在.如果我没有URL,我怎么能播放我的mp4文件?如果无法通过名称引用播放,我如何获取mp4文件的文件URL?

video objective-c ios avplayer avasset

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

当我为UIView的界限设置动画时,如何重绘UIView的子图层?

我有一个带有几个自定义绘制子层的UIView(一些带有CAShapeLayer掩码的CAGradientLayers等).我正在使用UIView动画方法来动画它的边界(增加它的宽度和高度).

[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{
    CGRect bounds = myView.bounds;
    bounds.size.width += 20;
    bounds.size.height += 20;
    myView.bounds = bounds;
} completion:nil];
Run Code Online (Sandbox Code Playgroud)

这样可以正常工作,除了子图层不会像其动画一样重新绘制.最好的方法是什么?我是否需要设置一些键值观察检测边界变化并在所有子层上调用setNeedsDisplay?

core-animation objective-c uiview uiviewanimation ios

6
推荐指数
2
解决办法
8081
查看次数

如何在我的工作区中为所有项目提供使用CocoaPods安装的pod?

我正在使用XCode 4.6.1.我的工作区中有几个项目,但只有一个能够包含添加的库CocoaPods.其他项目根本没有检测到它们.

如何CocoaPods与整个工作区共享?我是否需要包含libPods.a所有项目的构建依赖项?我是否需要在podfile中添加一些特殊内容?

xcode objective-c ios cocoapods xcode4.6

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

通过JSPM安装Angular组件路由器会导致神秘的404错误

我有一个JSPM/Typescript/Angular 1.5.3项目.我想使用新的组件路由器.在我的项目目录中,我使用了该命令

jspm install npm:@angular/router
Run Code Online (Sandbox Code Playgroud)

哪个安装正常,没有错误.然后我把它添加到我的app.ts文件中

import ngComponentRouter from 'jspm_packages/npm/@angular/router@0.2.0/angular1/angular_1_router'
Run Code Online (Sandbox Code Playgroud)

但是当我开始我的时候lite-server,我明白了

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:3000/jspm_packages/npm/@angular/instruction.json

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:3000/jspm_packages/npm/@angular/utils.json

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:3000/jspm_packages/npm/@angular/url_parser.json
Run Code Online (Sandbox Code Playgroud)

我不确定为什么要加载这些神秘的JSON文件,所以我检查了我的package.json:

{
  "jspm": {
    "name": "app",
    "dependencies": {
      "": "npm:@angular/router@^0.2.0",
      "angular": "npm:angular@^1.5.3", 
Run Code Online (Sandbox Code Playgroud)

嗯......空的""看起来不对劲.如果JSPM无法解析包名并且路由器要求JSON文件,我觉得缺少构建步骤.我在这做错了什么?

npm typescript systemjs jspm angular

6
推荐指数
0
解决办法
566
查看次数

Pyramid.security:从具有unauthenticated_userid(request)的数据库获取用户信息真的安全吗?

我正在尝试使用Pyramid doc的“ 使“用户对象”作为请求属性可用 ”示例来制作可访问的用户数据缓存。

他们正在使用以下代码将用户对象返回给set_request_property:

from pyramid.security import unauthenticated_userid

def get_user(request):
    # the below line is just an example, use your own method of
    # accessing a database connection here (this could even be another
    # request property such as request.db, implemented using this same
    # pattern).
    dbconn = request.registry.settings['dbconn']
    userid = unauthenticated_userid(request)
    if userid is not None:
        # this should return None if the user doesn't exist
        # in the database
        return dbconn['users'].query({'id':userid})
Run Code Online (Sandbox Code Playgroud)

我不明白为什么他们要使用unauthenticated_userid(request)从数据库中查找用户信息……不是很不安全吗?这意味着该用户可能未登录,那么为什么要使用该ID从数据库获取那里的私人信息?

不应该

    userid = authenticated_userid(request)
Run Code Online (Sandbox Code Playgroud)

用来确保用户已登录?使用unauthenticated_userid(request)有什么好处?请帮助我了解这里的情况。

python security authentication pyramid

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

无法让CALayer更新其drawLayer:DURING一个边界动画

我正在尝试为自定义UIView的边界设置动画,同时保持其图层与其父视图的大小相同.为此,我试图在其父视图旁边设置图层边界的动画.我需要图层来调用drawLayer:withContext AS它的动画,所以我的自定义绘图将正确地改变大小和边界.

drawLayer被正确调用并在我开始动画之前正确绘制.但我不能让图层在边界动画的每一步调用它的drawLayer方法.相反,它只是将其称为ONCE,立即跳转到动画最后一帧的"结束边界".

// self.bg is a property pointing to my custom UIView
self.bg.layer.needsDisplayOnBoundsChange = YES;
self.bg.layer.mask.needsDisplayOnBoundsChange = YES;

[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveEaseOut|UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{

    [CATransaction begin];
    self.bg.layer.bounds = bounds;
    self.bg.layer.mask.bounds = bounds;
    [CATransaction commit];

    self.bg.bounds = bounds;
} completion:nil];
Run Code Online (Sandbox Code Playgroud)

为什么边界不报告其动画(不仅仅是最终帧)的变化?我究竟做错了什么?

animation core-animation core-graphics objective-c ios

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

Heroku:sh:cython:没找到

我正在尝试将我的Python3应用程序推送到Heroku.它使用gevent哪个具有Cython依赖性.当我尝试推送到Heroku时,我收到此错误:

Running cython -o gevent.core.c gevent/core.pyx  # !EV_USE_SIGNALFD && !defined(LIBEV_EMBED) && !defined(_WIN32)

   sh: cython: not found

   Traceback (most recent call last):

     File "util/cythonpp.py", line 801, in <module>

       process_filename(filename, options.output_file)

     File "util/cythonpp.py", line 85, in process_filename

       output = run_cython(pyx_filename, sourcehash, output_filename, banner, comment)

     File "util/cythonpp.py", line 529, in run_cython

       system(command, comment)

     File "util/cythonpp.py", line 539, in system

       raise AssertionError('%r failed with code %s' % (command, result))

   AssertionError: 'cython -o gevent.core.c gevent/core.pyx' failed with code 32512

   make: *** …
Run Code Online (Sandbox Code Playgroud)

python heroku cython gevent python-3.x

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

为什么AVAssetExportSession会生成一个空文件?

我正在尝试从UIImagePickerController创建的源视频中导出.mov文件.问题是输出文件AVAssetExportSession创建的只有668个字节.它为什么失败?我的代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSURL *imagePickerVideoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    NSString *filename = @"vid1.mov";

    AVAsset *video = [AVAsset assetWithURL:imagePickerVideoURL];
    AVAssetExportSession *exportSession
      = [AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetMediumQuality];
    exportSession.shouldOptimizeForNetworkUse = YES;
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;
    exportSession.outputURL = [pathToSavedVideosDirectory URLByAppendingPathComponent:filename];
    NSLog(@"processing video...: %@", exportSession);
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
                       NSLog(@"done processing video!");
                   }];
}
Run Code Online (Sandbox Code Playgroud)

video objective-c avfoundation ios avassetexportsession

4
推荐指数
2
解决办法
4979
查看次数