我有两个应用程序,一个是反应前端,第二个是rails-api应用程序.
我一直很高兴使用isomorphic-fetch,直到我需要将PATCH方法发送到服务器.
我正进入(状态:
Fetch API cannot load http://localhost:3000/api/v1/tasks. Method patch is not allowed by Access-Control-Allow-Methods in preflight response.
Run Code Online (Sandbox Code Playgroud)
但来自服务器的OPTIONS响应包括Access-Control-Allow-Methods列表中的PATCH方法:
这是fetch的实现方式:
const API_URL = 'http://localhost:3000/'
const API_PATH = 'api/v1/'
fetch(API_URL + API_PATH + 'tasks', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: 'patch',
body: JSON.stringify( { task: task } )
})
Run Code Online (Sandbox Code Playgroud)
POST,GET,DELETE设置几乎相同,它们工作正常.
知道这里发生了什么吗?
更新:
方法补丁区分大小写:
https://github.com/github/fetch/blob/master/fetch.js#L200
不确定这是故意还是错误.
更新2
这是预期的,方法类型PATCH需要区分大小写.将行从fetch方法更新为:
method: 'PATCH'
Run Code Online (Sandbox Code Playgroud)
解决了这个问题.
我有一个小问题.在从服务请求数据后,我得到了一个iframe代码作为响应.
<iframe src="https://www.example.com/show?data..." width="540" height="450"></iframe>
Run Code Online (Sandbox Code Playgroud)
我想把它作为道具传递到我的模态组件并显示它,但是当我只是{this.props.iframe}在渲染函数中它显然将它显示为一个字符串.
将其显示为html的基本方式是什么?
我有:
const props = {
gallery: [],
select: () => null,
one: 1,
two: 2,
}
Run Code Online (Sandbox Code Playgroud)
我可以用它来构造它:
const {gallery, select, ...other} = props
Run Code Online (Sandbox Code Playgroud)
我现在有三个变量:
[]() => null{one: 1,two: 2}是否有可能选择指定分组?
这样的事情(这不会起作用,但我希望看到我想要做的事情很清楚):
const {{gallery, select}: specific, ...other} = props
Run Code Online (Sandbox Code Playgroud)
所以我将有2个变量:
{gallery: [], select: () => null}{one: 1,two: 2}我可以在更高级别解决它并以这种方式构建道具:
const props = {
specific: {
gallery: [],
select: () => null,
},
other: {
one: 1,
two: 2, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Intl 作为默认货币格式化程序,它几乎是完美的。
\nIntl.NumberFormat()使用构造函数中的示例:
const number = 123456.789;\n\nconsole.log(new Intl.NumberFormat(\'de-DE\', { style: \'currency\',\ncurrency: \'EUR\' }).format(number)); // expected output: "123.456,79 \xe2\x82\xac"\n \n// the Japanese yen doesn\'t use a minor unit \nconsole.log(new Intl.NumberFormat(\'ja-JP\', { style: \'currency\', currency: \'JPY\'\n}).format(number)); // expected output: "\xef\xbf\xa5123,457"\nRun Code Online (Sandbox Code Playgroud)\n这几乎是完美的,但我实际上想从输出中删除该符号。所以我希望看到:
\n// expected output: "123.456,79"\n// expected output: "123,457"\nRun Code Online (Sandbox Code Playgroud)\n我觉得很奇怪,我花了一个多小时寻找解决方案,却只找到了某种替换/修剪的用法。
\n为什么没有一个选项可以使用所有国际功能来格式化数字,而只删除货币符号?!?
\n我希望我错过了,说实话。
\n使用webpack-contrib/extract-text-webpack-plugin中的示例:
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
//resolve-url-loader may be chained before sass-loader if necessary
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: [
new ExtractTextPlugin('style.css')
//if you want to pass in options, you can do so:
//new ExtractTextPlugin({
// filename: 'style.css'
//})
]
}
Run Code Online (Sandbox Code Playgroud)
后备选项的目的是什么?
我如何看待这个代码片段是:
我指示webpack使用它遇到的ExtractTextPlugin每个.scss文件.我告诉ExtractTextPlugin使用['css-loader', 'sass-loader']加载器生成css.然后Webpack将发出style.css包含css的额外文件.
然后我可以在我的index.html中引用这个文件,或者如果我使用的是html-webpack-plugin,它会自动添加到它.
我可以删除该fallback: 'style-loader',选项,一切都继续工作.
回归是什么意思style-loader …
我想在用户评论中添加一个简单的markdown.
当用户提交此评论时:
我刚拿到[卡:黑莲花]男人.POW!
我希望它显示如下:
我刚买了黑莲花男.POW!
但有额外的HTML标记:
I just got <span class="preview" data-card="/cards/card.id">Black Lotus</span> man. POW!
1)我看着Redcarpet,但无法弄清楚如何添加[card:...]降价.
2)或者我应该运行正则表达式并在将内容保存到数据库之前替换内容然后sanitize(ActionView::Helpers::SanitizeHelper) span在显示注释之前进行标记?
我有大熊猫DataFrame,df与index命名date和列columnA,columnB并columnC
我正在尝试使用语法将图散布index在x轴和columnAy轴上DataFrame。
当我尝试:
df.plot(kind='scatter', x='date', y='columnA')
我KeyError: 'date'可能会收到一个错误,可能是因为date不是列
df.plot(kind='scatter', y='columnA')
我可能会收到一个错误,ValueError: scatter requires and x and y column因此X轴上没有默认索引。
df.plot(kind='scatter', x=df.index, y='columnA')
我出错了KeyError: "DatetimeIndex(['1818-01-01', '1818-01-02', '1818-01-03', '1818-01-04',\n '1818-01-05', '1818-01-06', '1818-01-07', '1818-01-08',\n '1818-01-09', '1818-01-10',\n ...\n '2018-03-22', '2018-03-23', '2018-03-24', '2018-03-25',\n '2018-03-26', '2018-03-27', '2018-03-28', '2018-03-29',\n '2018-03-30', '2018-03-31'],\n dtype='datetime64[ns]', name='date', length=73139, freq=None) not in index"。
如果matplotlib.pyplot直接使用我可以画出来 …
我知道之前有过类似的问题:
根据屏幕分辨率AngularJS更改指令的templateUrl
这是一年前首次提出的问题,从那以后AngularJS发生了一些变化.我很想知道是否有其他方法可以实现类似的东西,因为我没有找到关于templateUrl交换的许多信息,所以也许我在这里咆哮错误的树.
我有一个没有任何路线的单页应用程序.
HTML:
<body ng-app="App">
// lots of html same for both desktop/mobile
<my-dir></my-dir>
// even more here
</body>
Run Code Online (Sandbox Code Playgroud)
模板1:
<p>Mobile</p>
Run Code Online (Sandbox Code Playgroud)
模板2:
<p>Desktop</p>
Run Code Online (Sandbox Code Playgroud)
我想在屏幕低于700px时渲染模板1,否则渲染模板2.模板改变了my-dir指令中的内容.例如,模板1呈现列表和模板2呈现表.
另一个要求是尽可能使其响应(在调整窗口大小时,模板会发生变化)
目前我可以使用上述问题的解决方案,但有没有其他方法可以做到这一点?
我已经设置了简单的实验来检查运行sklearn GridSearchCV时多核CPU的重要性KNeighborsClassifier.我得到的结果令我感到惊讶,我想知道我是否误解了多核的好处或者我没有做对.
2-8个工作的完成时间没有差异.怎么会 ?我注意到CPU性能选项卡上的差异.当第一个单元运行时,CPU使用率为~13%,并且最后一个单元逐渐增加到100%.我期待它完成得更快.也许不是线性更快,即8个工作比4个工作快2倍,但速度要快一些.
我就是这样设置的:
我使用的是jupyter-notebook,cell指的是jupyter-notebook cell.
我已加载MNIST并使用0.05测试大小来3000表示数字X_play.
from sklearn.datasets import fetch_mldata
from sklearn.model_selection import train_test_split
mnist = fetch_mldata('MNIST original')
X, y = mnist["data"], mnist['target']
X_train, X_test, y_train, y_test = X[:60000], X[60000:], y[:60000], y[60000:]
_, X_play, _, y_play = train_test_split(X_train, y_train, test_size=0.05, random_state=42, stratify=y_train, shuffle=True)
Run Code Online (Sandbox Code Playgroud)
在下一个单元格中我设置KNN了一个GridSearchCV
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import GridSearchCV
knn_clf = KNeighborsClassifier()
param_grid = [{'weights': ["uniform", "distance"], 'n_neighbors': [3, 4, 5]}]
Run Code Online (Sandbox Code Playgroud)
然后我为8个n_jobs值完成了8个单元格.我的CPU是i7-4770,有4个内核8个线程.
grid_search …Run Code Online (Sandbox Code Playgroud) 我有一个样式按钮:
import { Link } from 'react-router-dom'
import styled from 'styled-components'
const Button = styled(Link)`
display: block;
border: 1px solid white;
padding: 5px;
`
Run Code Online (Sandbox Code Playgroud)
我可以将它用作Link:
<Button to='/' />
Run Code Online (Sandbox Code Playgroud)
但有时我想将其用作a:
<Button as='a' href='/' />
Run Code Online (Sandbox Code Playgroud)
但在第二种情况下,TypeScript 抱怨:
Type '{ children: string; as: string; href: string; }' is not assignable to type 'Readonly<ThemedOuterStyledProps<WithOptionalTheme<LinkProps, any>, any>>'.
Property 'to' is missing in type '{ children: string; as: string; href: string; }'.
Run Code Online (Sandbox Code Playgroud)
javascript ×4
python ×2
angularjs ×1
ecmascript-6 ×1
fetch-api ×1
iframe ×1
knn ×1
markdown ×1
matplotlib ×1
pandas ×1
php ×1
reactjs ×1
redcarpet ×1
ruby ×1
scikit-learn ×1
typescript ×1
webpack ×1