虽然requirejs
能够使用安装了npm的模块,但requirejs
如果通过它自己安装,我该如何在第一时间使用npm install requirejs
?
我已经阅读了示例部分中requirejs
列出的使用示例.他们似乎都假设require.js
已下载到特定位置.由于文件具体说
不要做像需要的东西("./ node_modules/foo/foo").
我想这样做是不对的index.html
:
<html>
<head>
<script data-main="scripts" src="node_modules/requirejs/require.js"></script>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果是npm-installed,建议使用requirejs的方法是什么?如果我遗漏了文档中的内容,请告诉我.谢谢
首先,我理解一般来说装饰工作是如何工作的.而且我知道@staticmethod
在签名中剥离实例参数
class C(object):
@staticmethod
def foo():
print 'foo'
C.foo //<function foo at 0x10efd4050>
C().foo //<function foo at 0x10efd4050>
Run Code Online (Sandbox Code Playgroud)
有效.
但是,我不明白如何staticmethod
实现这一点的源代码.
在我看来,该包装方法时foo
的staticmethod
,实例staticmethod
被实例化,那么一些神奇的发生,使C.foo()
合法的.
那么......那些魔法会发生什么?做了staticmethod
什么?
我知道关于SO的巨大话题,staticmethods
但没有一个能解决我的疑虑.但也许我没有点击魔术关键词.如果是的话,请告诉我.
对于寻找staticmethod
源代码的人,请参阅https://hg.python.org/cpython/file/c6880edaf6f3/Objects/funcobject.c
python static-methods decorator python-internals python-decorators
这里有很多关于This class should be static or leaks might occur
java android的问题.
此Handler类应该是静态的,否则可能会发生泄漏:IncomingHandler
此Handler类应该是静态的,否则可能会发生泄漏:AsyncQueryHandler
这个AsyncTask类应该是静态的,否则可能会发生泄漏(匿名android.os.AsyncTask)
警告是由于内部类保存了对外部类的隐式引用,因此阻止了外部类的GC'd.解决方案在于警告本身应该将类声明为静态.
但是,该解决方案是特定于Java的.鉴于kotlin没有static
修饰符,最接近的是伴随对象,伴随对象确实引用了它的"外部类".
以下是我的[失败]尝试的评论
class MyActivity : AppCompatActivity(), MyListener {
companion object {
class Attempt3Task(val callback: MyListener) : AsyncTask<Unit, Unit, Unit>() {
override fun doInBackground(vararg params: Unit?) {
TODO("")
}
override fun onPostExecute(result: Unit?) {
callback.updateUi()
}
}
}
inner class Attempt2Task : AsyncTask<Unit, Unit, Unit> () {
override fun doInBackground(vararg params: Unit?) {
TODO("
}
}
// Gives warning "This AsyncTask …
Run Code Online (Sandbox Code Playgroud) 我有一个运行的火花丛
spark://host1:7077
spark://host2:7077
spark://host3:7077
Run Code Online (Sandbox Code Playgroud)
和连接/bin/spark-shell --master spark://host1:7077
当尝试读取文件时:
val textFile = sc.textFile("README.md")
textFile.count()
Run Code Online (Sandbox Code Playgroud)
提示说
WARN TaskSchedulerImpl: Initial job has not accepted any resources; check your cluster UI to ensure that workers are registered and have sufficient resources
通过Web ui检查时host1:8080
,显示:
Workers: 0
Cores: 0 Total, 0 Used
Memory: 0.0 B Total, 0.0 B Used
Applications: 0 Running, 2 Completed
Drivers: 0 Running, 0 Completed
Status: ALIVE
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在spark-shell集群模式下运行时指定内核和内存?或者我必须通过将我的scala代码打包到.jar
文件中然后将作业提交给spark?
谢谢
铯现在在npm.之后npm install cesium
-ing到我的项目,所有的代码进入node_modules
.
在铯hello世界中,它包括cesium
类似的东西<script src="your/path/to/Cesium.js"></script>
我的问题是,为了从html中使用cesium,还需要做些什么?
我正在读这个问题并看到:
scalac包括一个全武装和可操作战斗站的8位模拟器,可在GenICode编译阶段使用魔法组合键CTRL-ALT-F12进行查看.
为了显示编译阶段scalac
,我用过scalac -Xshow-phases
.
phase name id description
---------- -- -----------
< ... >
icode 23 generate portable intermediate code
Run Code Online (Sandbox Code Playgroud)
似乎是相关阶段.
我编译了一个Hello-world程序
object Hello {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
Run Code Online (Sandbox Code Playgroud)
通过scalac Hello.scala
并按下CTRL-ALT-F12一路.没啥事儿.尝试scalac -Xprint:icode Hello.scala
使用CTRL-ALT-F12,没什么特别的.
如何触发模拟器?这有什么作用?
在scala 2.11.8和OS X 10.11.5上
python scipy中有一些信号生成辅助函数,但是这些仅用于一维信号。
我想生成一个2D理想带通滤波器,它是一个全零的矩阵,并带有一个1的圆,以消除图像中的某些周期性噪声。
我现在正在处理:
def unit_circle(r):
def distance(x1, y1, x2, y2):
return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
d = 2*r + 1
mat = np.zeros((d, d))
rx , ry = d/2, d/2
for row in range(d):
for col in range(d):
dist = distance(rx, ry, row, col)
if abs(dist - r) < 0.5:
mat[row, col] = 1
return mat
Run Code Online (Sandbox Code Playgroud)
结果:
In [18]: unit_circle(6)
Out[18]:
array([[ 0., 0., 0., 0., 1., 1., 1., 1., 1., …
Run Code Online (Sandbox Code Playgroud) 我正在尝试关注Thrift的Node.JS教程,但得到了Cannot read property 'tls' of undefined
以下是一些背景信息:
操作系统:Windows 7
Node.JS版本:v0.10.34
Thrift编译器版本:0.9.2
这是我的步骤:
ProjRoot
thrift.0.9.2 -r --gen js:node tutorial.thrift
和step获得的exe生成.js文件shared.thrift
创建package.json
以下内容:
{
"name": "thrifttest",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"thrift": "~0.9.2"
}
}
Run Code Online (Sandbox Code Playgroud)npm install
然后运行node NodeServer.js
我收到以下错误:
...\ProjRoot\node_modules\thrift\lib\thrift\server.js:89
if (options.tls) {
^
TypeError: Cannot read property 'tls' of undefined
at Object.exports.createMultiplexServer (...\ProjRoot\node_modules\thrift\lib\thrift\s
erver.js:89:14)
at Object.exports.createServer (...\ProjRoot\node_modules\thrift\lib\thrift\server.js:106:18)
at …
Run Code Online (Sandbox Code Playgroud) 在这篇文章之后,我可以将tail -f
日志文件发送到网页:
from gevent import sleep
from gevent.wsgi import WSGIServer
import flask
import subprocess
app = flask.Flask(__name__)
@app.route('/yield')
def index():
def inner():
proc = subprocess.Popen(
['tail -f ./log'],
shell=True,
stdout=subprocess.PIPE
)
for line in iter(proc.stdout.readline,''):
sleep(0.1)
yield line.rstrip() + '<br/>\n'
return flask.Response(inner(), mimetype='text/html')
http_server = WSGIServer(('', 5000), app)
http_server.serve_forever()
Run Code Online (Sandbox Code Playgroud)
这种方法有两个问题。
tail -f log
关闭网页后,该过程将持续存在。访问http://localhost:5000/yield n 次后会有 n 个 tail 进程我的问题是,是否可以让flask在有人访问页面时执行shell命令,并在客户端关闭页面时终止该命令?就像Ctrl+C之后tail -f log
。如果没有,还有哪些替代方案?为什么我一次只能有 1 个客户端访问该页面?
注意:我正在研究启动/停止任意 shell 命令的一般方法,而不是特别尾随文件
在我的另一个问题之后,我有一个 UDP 服务器角色,如下所示:
class Listener(addr: InetSocketAddress) extends Actor {
import context.system
IO(Udp) ! Udp.Bind(self, addr)
def spawnChild(remote): ActorRef = {
//Check if child already exist
context.actorOf(Props[Worker])
}
def receive = {
case Udp.Bound(local) =>
context.become(ready(sender()))
}
def ready(socket: ActorRef): Receive = {
case Udp.Received(data, remote) =>
val worker = spawnChild(remote)
worker ! data // forward data directly to child
case Udp.Unbind => socket ! Udp.Unbind
case Udp.Unbound => context.stop(self)
}
}
Run Code Online (Sandbox Code Playgroud)
我正在根据数据发送的位置创建子演员。这样做的原因是为了保持子actor的一些内部状态。内部状态包括上次连接时间、发送的数据包总数等
我想设置 TestProbes 来测试
在python中,我可以创建一个Class,在实例化时,可以接收任意方法调用吗?我已经读过这篇文章,但无法将这些文章放在一起
我想这与它有关attribute lookup
.对于一个类Foo
:
class Foo(object):
def bar(self, a):
print a
Run Code Online (Sandbox Code Playgroud)
class属性可以通过print Foo.__dict__
给出来获得
{'__dict__': <attribute '__dict__' of 'Foo' objects>, '__weakref__': <attribute '__weakref__' of 'Foo' objects>, '__module__': '__main__', 'bar': <function bar at 0x7facd91dac80>, '__doc__': None}
Run Code Online (Sandbox Code Playgroud)
所以这段代码是有效的
foo = Foo()
foo.bar("xxx")
Run Code Online (Sandbox Code Playgroud)
如果我打电话foo.someRandomMethod()
,AttributeError: 'Foo' object has no attribute 'someRandomMethod'
就会结果.
我希望foo
对象接收任何随机调用,默认为no-op,即.
def func():
pass
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?我希望这种行为模拟一个对象进行测试.
python ×4
scala ×3
javascript ×2
npm ×2
akka ×1
android ×1
android-lint ×1
apache-spark ×1
cesium ×1
decorator ×1
flask ×1
kotlin ×1
linux ×1
memory-leaks ×1
node.js ×1
numpy ×1
python-2.x ×1
requirejs ×1
scalac ×1
scipy ×1
subprocess ×1
testing ×1
thrift ×1