小编Eth*_*ent的帖子

Angular 2:ReferenceError:require未定义(...),angular2-polyfills

编辑:

我还没弄清楚为什么它不起作用,但我从头开始并得到一个工作版本.它似乎没有必要把system.src.js对前angular脚本标记,步伐下面的答案之一.查看工作版本和Angular 2 教程.


原始问题:

我正在努力学习Angular 2和Express.我一般都遵循指南.我收到以下错误:

ReferenceError: require is not defined(…) angular2-polyfills.js:1243 
Zone.run @ angular2-polyfills.js:1243
zoneBoundFn @ angular2-polyfills.js:1220
lib$es6$promise$$internal$$tryCatch @ angular2-polyfills.js:468
lib$es6$promise$$internal$$invokeCallback @ angular2-polyfills.js:480
lib$es6$promise$$internal$$publish @ angular2-polyfills.js:451
lib$es6$promise$$internal$$publishRejection @ angular2-polyfills.js:401
(anonymous function) @ angular2-polyfills.js:123
Zone.run @ angular2-polyfills.js:1243
zoneBoundFn @ angular2-polyfills.js:1220
lib$es6$promise$asap$$flush @ angular2-polyfills.js:262
Run Code Online (Sandbox Code Playgroud)

编辑:是GitHub上项目的破碎版本.

我的项目结构如下:

application
|__client
   |__app
      |__main.ts
      |__main.js
      |__tsconfig.json
   |__typings/ (...)
   |__index.html
   |__typings.json
|__server
   |__server.ts
   |__server.js
   |__tsconfig.json
   |__typings.json
|__node_modules/ (...)
Run Code Online (Sandbox Code Playgroud)

该文件server.ts是这样的:

import …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

Ruby:安全导航操作符,未定义方法`call`

我试图比较一个数字文字与可以返回的函数的返回值nil或数字.考虑一下:

def unreliable
  [nil, 42].sample  
end

unreliable > 10
Run Code Online (Sandbox Code Playgroud)

这将占50%的时间NoMethodError: undefined method '>' for nil:NilClass.所以我尝试了这个:

unreliable&.(:>, 10)
Run Code Online (Sandbox Code Playgroud)

这种方法可以保证nil我的预期,但是在unreliable返回时我得到了这个42:

NoMethodError: undefined method `call' for 42:Fixnum
Run Code Online (Sandbox Code Playgroud)

我怀疑这与允许每个只存在一个实例的怪癖有关Numeric,请参见此处.而且我知道我可以这样做:

foo = unreliable
foo && foo > 10
Run Code Online (Sandbox Code Playgroud)

但有使用安全导航运营商,数字和方式:>,:<,:==,:+,:-,:/,:*,等?


编辑:Numeric在我的问题中,重点是红鲱鱼.请参阅@Jörg的回答.我把Rails的try语法与安全导航操作符的语法混淆了.

ruby safe-navigation-operator

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

如何解密Ruby的`symmetric-encryption` gem用另一种语言加密的数据?

我想访问由Rails创建的数据库中的数据,以供非Ruby代码使用.某些字段使用attr_encrypted访问器,正在使用的库是symmetric-encryptiongem.如果我尝试用例如NodeJS crypto库解密数据,我一直得到"错误的最终块长度"错误.

我怀疑这必须使用字符编码或填充,但我无法根据文档弄清楚.

作为一个实验,我尝试从symmetric-encryptionRuby自己的OpenSSL库中解密数据,我得到一个"错误的解密"错误或同样的问题:

SymmetricEncryption.cipher = SymmetricEncryption::Cipher.new(
  key: "1234567890ABCDEF",
  iv:  "1234567890ABCDEF",
  cipher_name: "aes-128-cbc"
)

ciphertext = SymmetricEncryption.encrypt("Hello world")

c = OpenSSL::Cipher.new("aes-128-cbc")
c.iv = c.key = "1234567890ABCDEF"
c.update(ciphertext) + c.final
Run Code Online (Sandbox Code Playgroud)

这给了我一个"糟糕的解密"错误.

有趣的是,数据库中的加密数据可以由symmetric-encryptiongem 解密,但与输出不同SymmetricEncryption.encrypt(并且OpenSSL也不能成功解密它).


编辑:

psql=# SELECT "encrypted_firstName" FROM people LIMIT 1;
                   encrypted_firstName                    
----------------------------------------------------------
 QEVuQwBAEAAuR5vRj/iFbaEsXKtpjubrWgyEhK5Pji2EWPDPoT4CyQ==
(1 row)
Run Code Online (Sandbox Code Playgroud)

然后

irb> SymmetricEncryption.decrypt "QEVuQwBAEAAuR5vRj/iFbaEsXKtpjubrWgyEhK5Pji2EWPDPoT4CyQ=="
=> "Lurline"
irb> SymmetricEncryption.encrypt "Lurline"
=> "QEVuQwAAlRBeYptjK0Fg76jFQkjLtA=="
Run Code Online (Sandbox Code Playgroud)

ruby cryptography

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