我创建了一个系统,用户将视频上传到我服务器的文件系统,我需要一种方法来为视频文件生成唯一的文件名.我应该使用random.getrandbits吗?有没有办法用字母和数字的组合来做到这一点?
我正在尝试返回这样的函数:
@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的自定义类型所必需的.
我在项目导航器中包含了一个mp4资源.我想在AVPlayer中播放它.我知道如何为AVPlayer对象创建一个AVPlayerItem,所以现在我想加载适当的AVAsset指向我的mp4资源.问题是AVAsset只有一个assetWithURL:方法来创建AVAsset.我想要一个assetWithName:方法,但该方法不存在.如果我没有URL,我怎么能播放我的mp4文件?如果无法通过名称引用播放,我如何获取mp4文件的文件URL?
我有一个带有几个自定义绘制子层的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?
我正在使用XCode 4.6.1.我的工作区中有几个项目,但只有一个能够包含添加的库CocoaPods.其他项目根本没有检测到它们.
如何CocoaPods与整个工作区共享?我是否需要包含libPods.a所有项目的构建依赖项?我是否需要在podfile中添加一些特殊内容?
我有一个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文件,我觉得缺少构建步骤.我在这做错了什么?
我正在尝试使用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)有什么好处?请帮助我了解这里的情况。
我正在尝试为自定义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)
为什么边界不报告其动画(不仅仅是最终帧)的变化?我究竟做错了什么?
我正在尝试将我的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) 我正在尝试从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) ios ×5
objective-c ×5
python ×4
pyramid ×2
video ×2
angular ×1
animation ×1
avasset ×1
avfoundation ×1
avplayer ×1
cocoapods ×1
cython ×1
gevent ×1
heroku ×1
json ×1
jspm ×1
npm ×1
pymongo ×1
python-3.x ×1
random ×1
security ×1
string ×1
systemjs ×1
typescript ×1
uiview ×1
xcode ×1
xcode4.6 ×1