像大多数应用程序一样,我正在编写一个在http响应/请求处理程序中需要大量类似逻辑的应用程序.例如,我必须始终检查刷新令牌并将它们保存到AsyncStorage,或者始终将头设置为我的AuthService头,甚至检查404以路由到相同的404错误页面.
我是Angular中http拦截器的忠实粉丝; 你可以在哪里定义和注册一个http拦截器(缺少一个更好的术语)拦截所有的http流量,然后运行组合的通用逻辑.
我有两个主要问题:
我使用Django REST Framework编写了一个API.对于身份验证,我使用的是django-oauth2-provider:https://github.com/caffeinehit/django-oauth2-provider
我在我的设置页面中配置了cors(使用Corsheaders中间件).
MIDDLEWARE_CLASSES = (
...
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
...
)
CORS_ORIGIN_ALLOW_ALL = True # Dangerous (using for testing purposes)
Run Code Online (Sandbox Code Playgroud)
我的客户端应用程序是使用Angular JS构建的.但是,每次我们发出任何请求(包括GET请求)时,都会发出一个选项请求.此选项请求需要约50 - 500 ms,具体取决于请求.
api调用看起来像" https://example.com/api/v1/posts/?page=1(2,3,4 ......等)"
我需要了解为什么要提出此请求,以及如何提高应用程序的性能.
javascript django angularjs django-rest-framework django-cors-headers
我试图让一个组件的位置反应原生.
说我有一个观点:
<ScrollView>
lots of items...
lots of items...
lots of items...
<View></View>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
最后,我希望能够最终滚动到View所在的位置.
此链接显示如何使用本机ui管理器获取位置,但是在运行时它返回:
"尝试测量布局,但偏移或尺寸为NaN"
我试过了
this.refs.VIEW.measure((ox, oy, width, height, px, py) => {
//ox ... py all = 0
});
Run Code Online (Sandbox Code Playgroud) 我已经使用Django Rest Framework构建了API。我想更改分页以获得更好的用户体验。
问题:
客户打电话要求所有帖子。该请求看起来像:
http://website.com/api/v1/posts/?page=1
Run Code Online (Sandbox Code Playgroud)
这将返回帖子的第一页。但是,总是会创建新的帖子。因此,当用户请求时:
http://website.com/api/v1/posts/?page=2
Run Code Online (Sandbox Code Playgroud)
这些帖子几乎总是与第1页相同(因为总是有新数据出现,我们正在按排序-created)。
可能的解决方案?
我的想法是随请求一起发送对象ID,以便我们在获取帖子时使用。我们针对最后一个查询抓住它们。
http://website.com/api/v1/posts/?page=2&post_id=12345
Run Code Online (Sandbox Code Playgroud)
当我们分页时,我们在哪里过滤 post_id < 12345
但这仅在我们的post_id为整数的情况下有效。
现在我目前仅使用基本 ListAPIView
class PostList(generics.ListAPIView):
"""
API endpoint that allows posts to be viewed
"""
serializer_class = serializers.PostSerializer # just a basic serializer
model = Post
Run Code Online (Sandbox Code Playgroud)
有没有更好的分页方法?这样,在创建新数据时,该用户会话的下一个请求就不会像第一个请求那样。
我目前正在编写一个关于 react-native version 的应用程序0.7.1。我正在尝试编写一个聊天组件。
通过聊天,您通常在底部输入文本,消息从屏幕底部推送到顶部。此外,当聊天屏幕初始化时,它会在屏幕底部初始化并允许用户向上滚动。我想在 react-native 中实现相同的行为。ScrollView 的当前行为将项目从顶部推到底部。为此,我尝试了几种不同的解决方案:
this.refs.messages.scrollTo(contentHeight)。有人提到了以下功能:this.refs.messages.measure(callbackWithTheseParams((a, b, width, height, px,py )). 但是测量函数结果是未定义的。scrollTo(0,0). 但是,似乎此功能仅在 0.8.0-rc 中可用。我不确定它是否稳定(或者更稳定)。编辑 - 添加示例
我的构造函数:
componentDidMount() {
this.measureComponent()
}
// measureComponent
measureComponent() {
console.log('this gets called');
this.refs.messages.measure((ox, oy, width, height) => {
console.log(height); // does not get called.
});
}
Run Code Online (Sandbox Code Playgroud)
我的渲染功能是:
return (
<ScrollView
scrollEventThrottle={200}
ref="messages"
style={styles.container}>
<View style={styles.messages}>
{messages.map(this.renderMessage)}
</View>
<TextInput
style={styles.newMessage}
value={this.state.message}
onSubmitEditing={this.sendMessage}
onChangeText={(text) => this.setState({message: …Run Code Online (Sandbox Code Playgroud) 我有一个 AlexNet 的实现。我感兴趣的是在完全连接的分类层之前提取训练模型的特征向量
我想首先训练模型(下面我包括了训练和测试的评估方法)。
在分类之前,如何获取训练/测试集中所有图像的最终输出特征向量列表(在前向传递过程中)?
这是代码(完整版本可用https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3%20-%20Neural%20Networks/alexnet.py):
weights = {
'wc1': tf.Variable(tf.random_normal([3, 3, 1, 64])),
'wc2': tf.Variable(tf.random_normal([3, 3, 64, 128])),
'wc3': tf.Variable(tf.random_normal([3, 3, 128, 256])),
'wd1': tf.Variable(tf.random_normal([4*4*256, 1024])),
'wd2': tf.Variable(tf.random_normal([1024, 1024])),
'out': tf.Variable(tf.random_normal([1024, 10]))
}
biases = {
'bc1': tf.Variable(tf.random_normal([64])),
'bc2': tf.Variable(tf.random_normal([128])),
'bc3': tf.Variable(tf.random_normal([256])),
'bd1': tf.Variable(tf.random_normal([1024])),
'bd2': tf.Variable(tf.random_normal([1024])),
'out': tf.Variable(tf.random_normal([n_classes]))
}
def alex_net(_X, _weights, _biases, _dropout):
# Reshape input picture
_X = tf.reshape(_X, shape=[-1, 28, 28, 1])
# Convolution Layer
conv1 = conv2d('conv1', _X, _weights['wc1'], _biases['bc1'])
# …Run Code Online (Sandbox Code Playgroud) Stuart Geman在"神经网络与偏差/方差困境"一文中提出的问题是否已经 在今天使用的架构中得到解决?
react-native ×3
django ×2
javascript ×2
python ×2
angularjs ×1
ios ×1
pagination ×1
reactjs ×1
rest ×1
swift ×1
tensorflow ×1