小编you*_*t13的帖子

apache2 - https 重定向到给定页面的 http

我有一个关于将几个页面的 HTTPS 重定向到 HTTP 的特定问题。

我在 Zope 前面有 Apache2。

这是我的 VirtualHost 在端口 80 上的配置:

<VirtualHost *:80>
    ServerAdmin root@website.com
    ServerName website.com
    ServerAlias www.website.com

<IfModule mod_rewrite.c>
RewriteEngine On

# www to non www
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^/(.*) http://website.com/$1 [R=301,L]

# HTTP TO HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^/(.*) https://%{HTTP_HOST}%{REQUEST_URI}

</IfModule>

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

之后,当 Zope 侦听 SSL 8443 端口时,我应用以下 iptables 规则:

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8443
Run Code Online (Sandbox Code Playgroud)

所以我的重写规则将 80 重定向到 443,而 iptables 将 …

apache .htaccess mod-rewrite url-rewriting url-redirection

5
推荐指数
0
解决办法
623
查看次数

在 Firefox 上使用 popState 平滑滚动并返回按钮 - 需要单击两次

我正在尝试实现一个小代码,当我点击锚点(动画后出现锚点名称)时,我可以使用它平滑滚动,如果我按下浏览器的后退按钮,我想返回到页面顶部并更新 URL(没有 #anchor 名称)。

这是代码:

$(function() {
  // Smooth scrolling when clicking on anchor
  $('a[href*=#]:not([href=#])').click(function(event) {
    event.preventDefault();
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        var hash = this.hash; 
        $('html,body').animate({ scrollTop: target.offset().top - 55}, 300, function() {
          location.hash = hash;
          href = window.location.href;
          history.pushState({page:href}, null, href);
        });
        return false;
      }
    }
  });
  // Get smooth scrolling to the top whith back button …
Run Code Online (Sandbox Code Playgroud)

javascript firefox jquery

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

尼斯拖放画布HTML5

我尝试在代表3个磁盘的画布上实现一个很好的拖放.

我想用鼠标改变每个质量的位置.我的主要问题是我受这3个球体中每个球体的长度约束.

目前,当鼠标在画布内移动时,我已经实现了以下功能(indexMass的值表示移动了哪个质量:1, 2 or 3t1, t2, t3分别表示the angle of mass 1, 2, 3):

// Happens when the mouse is moving inside the canvas
function myMove(event) {

   if (isDrag) {
     var x = event.offsetX;
     var y = event.offsetY;

     if (indexMass == 1)
       { // Update theta1 value
         t1 = t1 + 0.1*Math.atan(y/x);
       }
     else if (indexMass == 2)
       { // Update theta2 value
         t2 = t2 + 0.1*Math.atan(y/x);
       }
     else if (indexMass == 3) …
Run Code Online (Sandbox Code Playgroud)

javascript html5 drag-and-drop canvas

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

使用pstricks和latex2html5绘制弧

我得到一个关于使用MathJax和latex2html5绘制弧的问题(来自http://latex2html5.com/).

我想用上面的这两个库绘制这个模式:

模式重现

我的问题是我无法绘制左边的2个弧链接EVDE状态.

在上面的链接上,我做了:

<script type="tex/latex">

\begin{center}
\begin{pspicture}(-4,-4)(4,4)

 \pscircle(-3.3,2.5){0.4}
 \pscircle(-3.3,-2.5){0.4}
 \pscircle(3.3,-2.5){0.4}
 \pscircle(3.3,2.5){0.4}

\psline{->}(-2.9,2.5)(2.9,2.5)
\rput(0,2.8){00}

\psline{->}(3.3,2.1)(3.3,-2.1)
\rput(3.6,0){00}

\psline{->}(2.9,-2.5)(-2.9,-2.5)
\rput(0,-2.8){01,11}

\psarc[fillcolor=white]{->}(-3.7,0){2}{-90}{90}

\end{pspicture}
\end{center}

  </script>

  <script type="text/javascript">
  $('body').latex();
  </script>
Run Code Online (Sandbox Code Playgroud)

这条线:

\psarc[fillcolor=white]{->}(-3.7,0){2}{-90}{90}
Run Code Online (Sandbox Code Playgroud)

关注这一部分但结果并不好:首先,fillcolor是蓝色的,之后,角度的间隔也不好(我希望2个弧是垂直的).

更一般地说,我想获得使用latex2html5库绘制模式(这里有不同的弧)的信息.如果这是不可能的,有没有人知道一个Javascript库(理想情况下使用像MathJax或没有的Latex渲染)可以允许这样做?谢谢你的建议.

谢谢

javascript geometry mathjax

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

使用bootstrap/jquery加载图像上的进度条

我尝试使用bootstrap css在图像加载上创建一个进度条.为此,我使用以下脚本:

<html>
<head>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet"/>
<script type="text/javascript">

var n=0;
var c=0;

$('img').each(function() {
    n++; 
    var tmpImg = new Image() ;
    tmpImg.src = $(this).attr('src') ;
    tmpImg.onload = function() {
    c++;
    };
    });

var interval = setInterval(function() {
    percent = n/100;
    loaded = c/percent;

    // for displaying purposes
    setBar(getBar()+50)
    // feed loaded var to the progressbar
    if (loaded == 100) {
    clearInterval(interval);
    }

    }, 1);

function setBar(n) {
  var bar = document.getElementById('fabbar');
  bar.style.width = n+'%';
}
function getBar() {
  var …
Run Code Online (Sandbox Code Playgroud)

javascript jquery progress-bar

4
推荐指数
1
解决办法
7707
查看次数

了解SSE指令的矢量化

我试着理解SSE指令的矢量化是如何工作的.

这里是一个实现矢量化的代码片段:

#include <stdlib.h>
#include <stdio.h>

#define SIZE 10000

void test1(double * restrict a, double * restrict b)
{
  int i;

  double *x = __builtin_assume_aligned(a, 16);
  double *y = __builtin_assume_aligned(b, 16);

  for (i = 0; i < SIZE; i++)
  {
    x[i] += y[i];
  }
}
Run Code Online (Sandbox Code Playgroud)

和我的编译命令:

gcc -std=c99 -c example1.c -O3 -S -o example1.s
Run Code Online (Sandbox Code Playgroud)

这里是汇编程序代码的输出:

 .file "example1.c"
  .text
  .p2align 4,,15
  .globl  test1
  .type test1, @function
test1:
.LFB7:
  .cfi_startproc
  xorl  %eax, %eax
  .p2align 4,,10
  .p2align 3
.L3:
  movapd  (%rdi,%rax), %xmm0
  addpd …
Run Code Online (Sandbox Code Playgroud)

c x86 assembly vectorization auto-vectorization

4
推荐指数
1
解决办法
239
查看次数

在 DAT.GUI 中显示带有起始值的浮点数

我有一个用dat.guiJavaScript 库制作的小菜单。我使用不同的行显示一些初始值(这些初始值在代码执行过程中被修改)。

我的问题是,例如,15我想显示“15.0000”而不是显示值“ ”。我尝试使用toFixed(4)功能但没有成功。

这是原始(没有“ toFixed(4)”函数)代码片段:

var componentThetaInit = 15;
var componentPhiInit = 15;

var gui = new dat.GUI({
 autoplace: false, 
    width: 350, 
    height: 9 * 32 - 1
});

var params = {
StartingVector : '',
 ComponentVectorTheta : componentThetaInit,
 ComponentVectorPhi : componentPhiInit
};

gui.add(params, 'StartingVector').name('Starting Vector :');
controllerComponentVectorTheta = gui.add(params, 'ComponentVectorTheta', minComponentTheta, maxComponentTheta, 0.0001).name('Component &theta; ');
controllerComponentVectorPhi = gui.add(params, 'ComponentVectorPhi', minComponentPhi, maxComponentPhi, 0.0001).name('Component &phi; ');
Run Code Online (Sandbox Code Playgroud)

现在我试过:

 var params = {
    StartingVector : …
Run Code Online (Sandbox Code Playgroud)

javascript tofixed dat.gui

4
推荐指数
1
解决办法
1913
查看次数

THREE.JS 和按钮开始和暂停动画

我尝试从我的THREE.jsGUI启动动画。

我有两个按钮,分别是“ Start”和“ Reset”动画。首先,当我点击“开始”按钮时,动画必须启动(动画是一个球体的旋转)并且这个按钮的文本设置为“ Pause”。动画启动后,我可以再次单击以暂停和停止动画。

我的问题是,我不知道要处理的动画渲染这些点击的和render()THREE.JS

这是我目前所做的:

// Boolean for start and restart
var initAnim = true;
var runAnim = false;

// Buttons startButton and resetButton
var startButton = document.getElementById( 'startButtonId' );
var resetButton = document.getElementById( 'resetButtonId' );

// Start Button
startButton.onclick = function StartAnimation() {
  if (initAnim) {
    initAnim = false;
    runAnim = true;
    theta = 0;
  }
  // Start and Pause 
  if (runAnim) {
    startButton.innerHTML = 'Pause';
    runAnim = …
Run Code Online (Sandbox Code Playgroud)

javascript animation three.js

3
推荐指数
1
解决办法
1万
查看次数

dat.GUI-寻找一种方法来锁定滑块并防止使用鼠标将值更新到dat.GUI菜单中

我尝试实现一种防止用鼠标更新值的方法(实际上是在three.js动画开始时,通过单击按钮启动)。

目前,我有以下dat.GUI菜单:

在此处输入图片说明

单击“开始”按钮后,我想防止用户用鼠标修改参数“ Rotation x”和“ Rotation y”。

这是此菜单的代码相关部分:

// Create GUI
var gui = new dat.GUI({
      autoplace: false, 
      width: 350,
          height: 9 * 32 - 1
});

var params = {
      GreatCircle : '',
      Rotationx : torusRotationInitX,
      Rotationy : torusRotationInitY,
      StartingVector : '',
      ComponentVectorTheta : 15.0,
      ComponentVectorPhi : 15.0,
      CovariantDerivativeVector : '',
      ComponentCovariantDerivativeTheta : 15.0,
      ComponentCovariantDerivativePhi : 15.0
};

// Set parameters for GUI
gui.add(params, 'GreatCircle').name('Great Circle ');
controllerRotationx = gui.add(params, 'Rotationx', 0, 2*Math.PI, …
Run Code Online (Sandbox Code Playgroud)

javascript three.js dat.gui

3
推荐指数
1
解决办法
2117
查看次数

Qt OpenGL - 鼠标拖动旋转 - 负增量

我有一个 QGLWidget 的 GLWdiget 子类,我想在其中沿 Ox 和 Oy 轴旋转 3D 对象。

为此,我以这种方式重新实现mousePressEventmouseMoveEvent运行:

void GLWidget::mousePressEvent(QMouseEvent *event)
{
 lastPos = event->pos();
}

void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
  float dx = (event->x() - lastPos.x()) / 10.0f;
  float dy = (event->y() - lastPos.y())/ 10.0f;

 if (event->buttons() & Qt::LeftButton) 
   {
   glRotatef(dy*0.1, 1.0f, 0.0f, 0.0f);
   glRotatef(dx*0.1, 0.0f, 1.0f, 0.0f);
   }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是dx,并dy永远不会否定所以无论我用鼠标做的方向,它总是在同一方向旋转。

例如,如果我水平向右拖动,我希望对象沿 0y 轴旋转,角度为正,如果我水平向左拖动,角度为负。

这与垂直拖动相同,但旋转将沿 Ox 轴。

这个问题来自全球坐标吗?但是,event->xevent->y给出相对于 GLWidget 的位置。

opengl qt rotation qglwidget

2
推荐指数
1
解决办法
7108
查看次数

vim 替换 : # 对于单个 $,如果 $$ 无事可做

我想做以下替换:用符号 #替换$位于 2 之间的单词$,如果这些单词在 2 之间,则不执行任何操作$$

例如,在本文中:

Currently, we are able to make cross correlations (understand "combine" to have better constraints on cosmological parameters) between weak lensing (WL) and photometric Galaxy clustering (GCph). When I say combine, as in the case where I have 2 sets of different measures ($\tau_1, \sigma_1$) and ($\tau_2, \sigma_2$), well, if I consider the Gaussian errors, it is shown quite easily (by Maximum Likelihood Estimation) that the estimator $\sigma_{\hat …
Run Code Online (Sandbox Code Playgroud)

regex vim replace pattern-matching

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

如何以与numpy linalg“ inv”或“ pinv”函数相同的精度执行PyCUDA 4x4矩阵求逆

我的代码执行4x4矩阵求反(128、256、512)数时,遇到了精度问题。当我使用原始版本(即numpy函数np.linalg.inv或)时np.linalg.pinv,一切正常。

不幸的是,使用下面的CUDA代码,我将naninf值转换为倒置矩阵。

更明确地说,我将此矩阵求反:

2.120771107884677649e+09 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 3.557266600921528288e+27 3.557266600921528041e+07 3.557266600921528320e+17
0.000000000000000000e+00 3.557266600921528041e+07 3.557266600921528288e+27 3.557266600921528041e+07
0.000000000000000000e+00 3.557266600921528320e+17 3.557266600921528041e+07 1.778633300460764144e+27
Run Code Online (Sandbox Code Playgroud)

如果使用经典的numpy“ inv”,则会得到以下3x3倒置矩阵:

4.715266047722758306e-10 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 2.811147187396482366e-28 -2.811147186834252285e-48 -5.622294374792964645e-38
0.000000000000000000e+00 -2.811147186834252285e-48 2.811147187396482366e-28 -5.622294374230735768e-48
0.000000000000000000e+00 -5.622294374792964645e-38 -5.622294374230735768e-48 5.622294374792964732e-28
Run Code Online (Sandbox Code Playgroud)

为了检查该逆矩阵的有效性,我将其乘以原始矩阵,结果是单位矩阵。

但是使用CUDA GPU反转后,我得到了以下矩阵:

0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00
-inf -inf -9.373764907941219970e-01 -inf
inf nan -inf nan
Run Code Online (Sandbox Code Playgroud)

所以,我想竟被以提高精度到我的CUDA内核或Python代码,以避免这些naninf值。

这是CUDA内核代码,并调用了我的主要代码的一部分(我已经用numpy inv函数注释了经典方法:

    # Create arrayFullCross_vec array
    arrayFullCross_vec = np.zeros((dimBlocks,dimBlocks,integ_prec,integ_prec)) …
Run Code Online (Sandbox Code Playgroud)

python cuda matrix matrix-inverse pycuda

-2
推荐指数
1
解决办法
210
查看次数