在numpy我有一个类似的数组
[0 + 0.5j, 0.25 + 1.2352444e-24j, 0.25+ 0j, 2.46519033e-32 + 0j]
Run Code Online (Sandbox Code Playgroud)
什么是将超低值设置为零的最快和最简单的方法
[0 + 0.5j, 0.25 + 0j, 0.25+ 0j, 0 + 0j]
Run Code Online (Sandbox Code Playgroud)
效率不是最重要的.
我只使用passport.js进行谷歌,Facebook和Twitter登录.
Node.js v0.8.19 with express.js 3.1.0,passportjs version 0.1.16.(passport-facebook - 0.1.5,twitter - 0.1.4 passport-goolge-oauth - 0.1.5)
在运行一小时左右的应用程序后,一切都运行良好,一段时间后,使用passport.js停止将用户序列化到req.user会话中.
Facebook和谷歌正在接收来自各自api的全部数据
passport.use(new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: "http://localhost:3000/auth/facebook/callback"
},
function(accessToken, refreshToken, profile, done) {
var temp = {}
temp.name = profile.displayName
temp.id = profile.id
console.log(temp)
return done(null, temp);
}));
Run Code Online (Sandbox Code Playgroud)
这里的console.log将成功打印用户ID和名称,但是在调用之后
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
Run Code Online (Sandbox Code Playgroud)
序列化和反序列化取自passport-facebook 示例.
用户不会被附加到req.user.
Twitter从未走得那么远,在回到回调网址后,twitter给出了错误:
Error: failed to find request token in session
[03/11 23:28:24 GMT] at Strategy.OAuthStrategy.authenticate
Run Code Online (Sandbox Code Playgroud)
注意:这些故障只发生一段时间后,工作正常一段时间.这就是为什么我认为它可能是一个内存问题,就像我将会话保存在内存而不是库克.
这是我的快速应用程序配置
app.configure(function(){ …
Run Code Online (Sandbox Code Playgroud) 我正在克隆一个实时降价编辑器dillinger.io,但与dillinger不同,当您将视频嵌入文档中时,但我不希望每次文档更新时都刷新并刷新视频,这种情况非常常见。
DOM的组织方式如下。
<div id='editor'></div>
<div id="viewer">
<h2>title</h2>
<iframe width="560" height="315"
src="http://www.youtube.com/embed/9bZkp7q19f0" frameborder="0" allowfullscreen>
</iframe> <!-- Gangnam style youtube embed-->
<p>What a dull video</p>
</div>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,该编辑器是出色的Ace编辑器,它使我可以通过editor.getValue()
有一种简单的已知方法可以做到这一点吗?我已经用Google搜索,发现没有什么有用的。
这就是我目前所拥有的
function update(){
var mk = editor.getValue();
var updatedHtml = converter.makeHtml(mk);
$('#viewer').html(updatedHtml);
}
editor.getSession().on('change', function(e) {
update();
});
Run Code Online (Sandbox Code Playgroud)
但我想将其更改为这样的内容
function update(){
var before = $('#viewer').html();
var mk = editor.getValue();
var updateHtml = converter.makeHtml(mk);
$('#viewer').replaceWhereDifferent(updateHtml, before);
}
Run Code Online (Sandbox Code Playgroud)
这样做是为了防止嵌入的youtube视频在每次更新时都闪烁。
问题是我没有一个很好的函数形式
replaceWhereDifferent(updateHtml, before)
一些示例html字符串将是
<div id="viewer">
<h2>title</h2>
<iframe width="560" height="315"
src="http://www.youtube.com/embed/9bZkp7q19f0" frameborder="0" …
Run Code Online (Sandbox Code Playgroud) 我试图使用cython和emscripten从python生成javascript.
hello.py
:
print 'Hello world.'
Run Code Online (Sandbox Code Playgroud)
然后我使用cython将其编译为c
>>> cython --embed hello.py -v
Run Code Online (Sandbox Code Playgroud)
这会生成一个hello.c
我编译的文件
>>> gcc hello.c -I/usr/include/python2.7/ -lpython2.7
Run Code Online (Sandbox Code Playgroud)
这适用于gcc或clang.当我执行时,./a.out
我得到预期的输出
>>> ./a.out
>>> Hello world
Run Code Online (Sandbox Code Playgroud)
接下来我想hello.c
使用emscripten 编译为javascript
>>> emcc hello.c -I/usr/include/python2.7/ -lpython2.7
Run Code Online (Sandbox Code Playgroud)
我明白了
>>> WARNING emcc: -I or -L of an absolute path encountered.
>>> If this is to a local system header/library, it may cause problems
>>> (local system files make sense for compiling natively on your system,
>>> but not necessarily to JavaScript) …
Run Code Online (Sandbox Code Playgroud) 我想将lorentzian峰值拟合到一组数据x和y,数据很好.像OriginLab这样的其他程序非常适合它,但我想用python自动化,所以我有以下代码,它基于http://mesa.ac.nz/?page_id=1800
我遇到的问题是scipy.optimize.leastsq返回最适合我传递给它的相同初始猜测参数,基本上什么都不做.这是代码.
#x, y are the arrays with the x,y axes respectively
#defining funcitons
def lorentzian(x,p):
return p[2]*(p[0]**2)/(( x - (p[1]) )**2 + p[0]**2)
def residuals(p,y,x):
err = y - lorentzian(x,p)
return err
p = [0.055, wv[midIdx], y[midIdx-minIdx]]
pbest = leastsq(residuals, p, args=(y, x), full_output=1)
best_parameters = pbest[0]
print p
print pbest
Run Code Online (Sandbox Code Playgroud)
p是初始猜测,best_parameters是来自leastsq的返回"最佳拟合"参数,但它们始终相同.
这是full_output = 1返回的内容(长数字数组已被缩短,但仍然代表)
[0.055, 855.50732, 1327.0]
(array([ 5.50000000e-02, 8.55507324e+02, 1.32700000e+03]),
None, {'qtf':array([ 62.05192947, 69.98033905, 57.90628052]),
'nfev': 4,
'fjac': array([[-0., 0., 0., 0., 0., 0., 0.,],
[ …
Run Code Online (Sandbox Code Playgroud) 我在 Django 模型中有一个 JSONField,如下所示:
from django.db import models
from django.contrib.postgres.fields import JSONField
class File(models.Model):
metadata = JSONField(null=True, blank=True, default={})
Run Code Online (Sandbox Code Playgroud)
元数据可以填充用户喜欢的任何内容。
我希望能够列出所有 File 对象使用的所有唯一元数据键。
有没有办法使用 django 和 postgres 聚合来做到这一点?
我有下面的代码来选择sin或cos来集成,
while( x !=1 || y !=(1||0) ){
printf("Sin (1) or Cos (0)?\n");
x = scanf("%d",&y);
_flushall();
if(y==1){
printf("Sin set\n");
}
else if(y==0){
printf("Cos set\n");
}
}
Run Code Online (Sandbox Code Playgroud)
然而
y!= (1||0)
Run Code Online (Sandbox Code Playgroud)
y == 0永远不会评估为真,有人可以解释这里有什么问题吗?谢谢.
var s= "this is inline $\alpha$, $$not$$";
Run Code Online (Sandbox Code Playgroud)
我怎样才能更换'$'
by '%%'
而不是'$$'
.
这样输出就是
var s= "this is inline %%\alpha%%, $$not$$";
Run Code Online (Sandbox Code Playgroud)
我刚在想
s.split('$').join('%%')
Run Code Online (Sandbox Code Playgroud)
但我需要分成一美元而不是两美元.
以下代码对我不起作用.
class stateClass:
state = 0
states = []
states.append(stateClass)
states.append(stateClass)
def populateStates(states):
for s in states:
if s.state == 0
print 'populating'
s.state = 1
populateStates(states)
Run Code Online (Sandbox Code Playgroud)
输出是
states array length: 2
populating
Run Code Online (Sandbox Code Playgroud)
这是第二次失败
for s in states:
if s.state == 0
Run Code Online (Sandbox Code Playgroud)
如果条件是第二次失败,虽然它是数组中的不同索引,因此s.state应该已经初始化为0.所以我认为循环没有正确迭代.
谁知道什么是错的?
python ×5
javascript ×3
node.js ×2
ace-editor ×1
c ×1
cython ×1
data-fitting ×1
django ×1
dom ×1
emscripten ×1
express ×1
if-statement ×1
jquery ×1
json ×1
loops ×1
numpy ×1
passport.js ×1
postgresql ×1
regex ×1
scipy ×1