当我无法访问原始源代码时,如何使用用户脚本(例如 Tampermonkey 注入的代码)修改 React 组件而不破坏应用程序?
直接修改 React 组件的 DOM 可能会破坏应用程序,因为协调算法可能会因手动 DOM 更改而感到困惑。因此,我想修改我的用户脚本中的 React 组件,以便 React 可以不受阻碍地继续渲染。
在一个简单的设置中,React 会发现全局命名空间中的组件,我们可以轻松修改组件(请参阅此小提琴以获取工作示例):
oldComponent = Component
function Component(props) {
// modify the props to change the appearance of the component
return oldComponent(modifiedProps);
}
Run Code Online (Sandbox Code Playgroud)
然而,部署应用程序时情况会更加复杂,因为组件通常使用webpack进行捆绑。我如何能够在组件已捆绑的应用程序中重现上面的示例?
我想在PyCharm 2016.2中使用python3语法并将解释器配置为使用python3.5.我执行它时代码运行正常,但PyCharm抱怨python2不支持python3语法.
我如何说服PyCharm python3语法没问题?
我想包形状的阵列(..., n * (n - 1) / 2)与形状的张量的下三角部分(..., n, n),其中...表示一个任意的形状。在 numpy 中,我会将它实现为
import numpy as np
# Create the array to store data in
arbitrary_shape = (10, 11, 12)
n = 5
target = np.zeros(arbitrary_shape + (n, n))
# Create the source array
source = np.random.normal(0, 1, arbitrary_shape + (n * (n - 1) / 2,))
# Create indices and set values
u, v = np.tril_indices(n, -1)
target[..., u, v] = source
# Check …Run Code Online (Sandbox Code Playgroud) linux 主机上的重叠绑定挂载似乎会在root. 这是故意的吗?下面是一个例子:
# Create a file to mount in the container
touch hostfile
# Create a temporary directory to mount in the container
mkdir tempdir
# Run bash in the container and mount the file and directory
docker run --rm --volume=`pwd`/tempdir:/home --volume=`pwd`/hostfile:/home/hostfile ubuntu bash
Run Code Online (Sandbox Code Playgroud)
运行该命令后,hostfile可以在 中找到tempdir但归root.
注意
hostfile由启动容器的用户拥有,docker run不会改变任何内容。我进行了一些计算以获得一个 numpy 数组列表。随后,我想找到沿第一个轴的最大值。我目前的实施(见下文)非常缓慢,我想找到替代方案。
原来的
pending = [<list of items>]
matrix = [compute(item) for item in pending if <some condition on item>]
dominant = np.max(matrix, axis = 0)
Run Code Online (Sandbox Code Playgroud)
修订版 1:此实现速度更快(~10 倍;大概是因为 numpy 不需要弄清楚数组的形状)
pending = [<list of items>]
matrix = [compute(item) for item in pending if <some condition on item>]
matrix = np.vstack(matrix)
dominant = np.max(matrix, axis = 0)
Run Code Online (Sandbox Code Playgroud)
我运行了几个测试,速度变慢似乎是由于数组列表到 numpy 数组的内部转换
Timer unit: 1e-06 s
Total time: 1.21389 s
Line # Hits Time Per Hit % Time Line Contents …Run Code Online (Sandbox Code Playgroud) 我在一个有多个服务器的环境中工作,并希望.jupyter在服务器之间共享我的配置,这样我就不必手动保持它们的同步.通过将JUPYTER_CONFIG_DIR环境变量设置为共享位置,可以轻松实现此目的.
但是,我想为每个服务器使用不同的CSS样式表,这样很明显我正在处理哪一个.例如,在第一台服务器上,我想要一个红色背景:
#notebook { background: red; }
Run Code Online (Sandbox Code Playgroud)
而在第二,我想有一个蓝色的背景.
#notebook { background: blue; }
Run Code Online (Sandbox Code Playgroud)
我想我可以通过extra_static_paths在jupyter服务器的主机名附加不同的路径来实现这一点.但是,笔记本的HTML查找custom/custom.css并且所指示的文件是以这样的方式extra_static_paths提供的,static/...因此我无法以这种方式替换自定义css文件.
有更好的方法吗?
python ×3
css ×1
docker ×1
indexing ×1
javascript ×1
linux ×1
numpy ×1
pycharm ×1
python-3.x ×1
reactjs ×1
tampermonkey ×1
tensorflow ×1
userscripts ×1
webpack ×1