小编Abr*_*m P的帖子

角度注射器上下划线的含义

我一直在为一些Angular组件编写测试,使用我刚才在google上找到的语法:

 describe('Directive: myDir', function () {
     beforeEach(module('myApp'));
     beforeEach(module('app/views/my_template.html'));
     beforeEach(inject(function ($rootScope, _$compile_, $templateCache) {
         $templateCache.put('views/my_template.html', $templateCache.get('app/views/my_template.html'));

         var scope, $compile;
         scope = $rootScope;
         $compile = _$compile_;
         element = angular.element("<div my-dir class='my-dir'></div>");
     }));

     it('does things', function () {
         $compile(element)(scope);
         scope.$digest();
     });
 });
Run Code Online (Sandbox Code Playgroud)

我的问题是关于注射的_$compile_.它与众不同之处$compile.我为什么要这样做呢?为什么$ compile被重新定义,为什么我不能简单地编译我注入的$ compile?

dependency-injection jasmine angularjs angularjs-scope angular-template

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

如何从Integer转换为Fractional

假设我有以下Haskell类型描述:

divide_by_hundred :: Integer -> IO()
divide_by_hundred n = print(n/100)
Run Code Online (Sandbox Code Playgroud)

为什么当我尝试通过ghc运行时,我得到:

No instance for (Fractional Integer) arising from a use of `/'
Possible fix: add an instance declaration for (Fractional Integer)
In the first argument of `print', namely `(n / 100)'
In the expression: print (n / 100)
In an equation for `divide_by_hundred':
    divide_by_hundred n = print (n / 100)
Run Code Online (Sandbox Code Playgroud)

通过运行:t (/) 我得到:

(/) :: Fractional a => a -> a -> a
Run Code Online (Sandbox Code Playgroud)

对我来说,这表明(/)可以取任何可以表示为小数的Num(我在印象中应该包括整数,但我不确定如何验证这一点),只要两个输入/都是相同类型.

这显然不准确.为什么?我将如何编写一个简单的函数来将整数除以100?

haskell types casting

6
推荐指数
2
解决办法
5540
查看次数

Data.Hashtable的算法复杂性

我正在尝试编写一个利用哈希值的函数(用于实现A*).

经过一些研究,我发现事实上的标准是Data.Map.

但是,在阅读API文档时,我发现: O(log n). Find the value at a key.

https://downloads.haskell.org/~ghc/6.12.2/docs/html/libraries/containers-0.3.0.0/Data-Map.html

实际上,文档通常表明大O时间明显低于标准Hash的O(1).

所以我找到了Data.HashTable. https://hackage.haskell.org/package/base-4.2.0.2/docs/Data-HashTable.html 本文档没有直接提及大O,这让我相信它可能符合我的期望.

我有几个问题:1)这是正确的吗?O(lookupInDataHashTable)= O(1)?2)为什么我会想要使用Data.Map效率低下?3)我的数据结构需求是否有更好的库?

haskell hashtable time-complexity data-structures

6
推荐指数
2
解决办法
194
查看次数

案例中下划线的含义()

所以我已经看到了周围的语法

case () of _
   | someBool ->
   | someOtherBool ->
Run Code Online (Sandbox Code Playgroud)

我理解它的作用,例如,完全独立于案例评估的事物切换案例(这是有道理的,因为在这种情况下,它将是单位,并且它将始终是单位).

我也明白这可以和(应该)独立于用case检查的东西(例如(1 == 1)(someComplexFunction)),但显然单位是最快的.

我不太明白的是,下划线是如何工作的.它清楚地告知案例完全忽略操作数的内容,只检查布尔值.但是这个运营商来自哪里?在其他情况下我可以使用它吗?

haskell switch-statement

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

玩笑无限期挂起,不进行任何测试

每次我开玩笑时,它什么也不会运行。我让柜台任意高。我用--no-cache开玩笑

jest --debug输出如下:

{
  "configs": [
    {
      "automock": false,
      "browser": false,
      "cache": true,
      "cacheDirectory": "/var/folders/7v/64n1tsk11zs2pbwf5bm_c9kc0000gn/T/jest_dx",
      "clearMocks": false,
      "coveragePathIgnorePatterns": [
        "/node_modules/"
      ],
      "detectLeaks": false,
      "forceCoverageMatch": [],
      "globals": {},
      "haste": {
        "defaultPlatform": "ios",
        "platforms": [
          "android",
          "ios",
          "native"
        ],
        "providesModuleNodeModules": [
          "react-native"
        ]
      },
      "moduleDirectories": [
        "node_modules"
      ],
      "moduleFileExtensions": [
        "js",
        "json",
        "jsx",
        "node"
      ],
      "moduleNameMapper": [
        [
          "^React$",
          "/Users/skilurus/github/flock-react-app/node_modules/react"
        ]
      ],
      "modulePathIgnorePatterns": [
        "/Users/skilurus/github/flock-react-app/node_modules/react-native/Libraries/react-native/"
      ],
      "name": "b29a126b130a0be47202d3bc7b00f1b4",
      "resetMocks": false,
      "resetModules": false,
      "restoreMocks": false,
      "rootDir": "/Users/skilurus/github/flock-react-app",
      "roots": [
        "/Users/skilurus/github/flock-react-app"
      ],
      "runner": "jest-runner", …
Run Code Online (Sandbox Code Playgroud)

testing node.js npm jestjs babel-jest

6
推荐指数
6
解决办法
2927
查看次数

当某些标记为destroy时,可以对嵌套属性的唯一性进行rails验证

我有以下(消毒过的)模型:

 class Person < ActiveRecord::Base

      attr_accessible :name, :first_name, :last_name, :age, :job_title, :salary, :ssn, :prison_convictions, :addresses_attributes

      has_many :addresses, inverse_of: :person

      accepts_nested_attributes_for :addresses, allow_destroy: true

 end



 class Address < ActiveRecord::Base

      attr_accessible :zip_code, :street,:house_number,
 :unique_per_person_government_id

      belongs_to :person, inverse_of: :addresses

      validates_uniqueness_of :unique_per_person_government_id, scope: :person_id
 end
Run Code Online (Sandbox Code Playgroud)

问题如下,

让我们说人Joe Shmoe目前有两个地址附在自己身上

666 Foo Street,12345,唯一ID:"ABCDEFG"和777 Lucky Avenue,54321,唯一ID:"GFEDCBA"

并且让我们说以下帖子来自一个表单:

 {:addresses_attributes =>
 { [0] => {:unique_per_person_government_id => “ABCDEFG”, :street=> “Foo Street”, :house_number => 666, :zip_code=>12345, _destroy => 1}
 [1] => {:unique_per_person_government_id => “ABCDEFG”, :street=>”Bar Street”, :house_number => 888, :zip_code => …
Run Code Online (Sandbox Code Playgroud)

ruby validation ruby-on-rails validates-uniqueness-of rails-activerecord

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

以编程方式测试特定的css属性兼容性(调整textarea上的支持)

我正在跨浏览器网站上实现可调整大小的textarea.现在在FF/Chrome/Safari中,以下内容:

  textarea{
     resize: both;
  }
Run Code Online (Sandbox Code Playgroud)

奇迹般有效.一点点嗅闻让我在这里:

http://www.w3schools.com/cssref/css3_pr_resize.asp

我在那里了解到Opera和IE不支持这个属性.

没什么大不了的,下面的javascript可以处理检测,用jquery UI调用resizable()包含在内的功能:

 if ((navigator.userAgent.indexOf('Trident') != -1) || (navigator.userAgent.indexOf('MSIE') != -1) || (navigator.userAgent.indexOf('Opera') != -1)){
Run Code Online (Sandbox Code Playgroud)

但是,我不喜欢明确的浏览器检查.有没有办法以编程方式测试对特定css属性的支持?

javascript jquery jquery-ui cross-browser css3

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

在factorygirl中设置实例变量

说我有一个像这样的模特

class Vehicle < ActiveRecore::Base

  after_initialize :set_ivars

  def set_ivars
    @my_ivar = true
  end
end
Run Code Online (Sandbox Code Playgroud)

我的代码中的其他地方我做的事情就像@ vehicle.instance_variable_set(:@ my_ivar,false)

然后使用此ivar确定运行哪些验证.

如何将这个Ivar传递给FactoryGirl?

 FactoryGirl.define do
   factory :vehicle do
      association1
      association2
   end
 end
Run Code Online (Sandbox Code Playgroud)

在创建之后,如何在保存之前将ivar_set编码到上面?我如何将其传递给FactoryGirl.create()?

ruby mocking ruby-on-rails-3.2 factory-bot

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

分组不分组?

假设我正在尝试构建一个民意调查应用程序,这样我就可以创建一个民意调查模板,给它多个部分/问题,将多个人分配到给定问题的不同副本,创建不同的度量(快乐,成功,绿色)并分配不同的问题不同的权重,以适用于所有这些措施.

像这样的东西:

CREATE TABLE users (
  id SERIAL NOT NULL PRIMARY KEY
);

CREATE TABLE opinion_poll_templates (
  id SERIAL NOT NULL PRIMARY KEY
);

CREATE TABLE opinion_poll_instances (
  id SERIAL NOT NULL PRIMARY KEY,
  template_id INTEGER NOT NULL REFERENCES opinion_poll_templates(id)
);

CREATE TABLE section_templates (
  id SERIAL NOT NULL PRIMARY KEY,
  opinion_poll_id INTEGER NOT NULL REFERENCES opinion_poll_templates(id)
);

CREATE TABLE section_instances (
  id SERIAL NOT NULL PRIMARY KEY,
  opinion_poll_id INTEGER NOT NULL REFERENCES opinion_poll_instances(id),
  template_id INTEGER NOT NULL REFERENCES section_templates(id) …
Run Code Online (Sandbox Code Playgroud)

sql postgresql group-by aggregate-functions postgresql-9.3

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

React Native App的自定义iOS(登台)配置

我已经为我的React Native应用程序创建了一个临时配置,作为我的Release版本的克隆.但是,当我运行时react-native run-ios --configuration Staging,我的构建失败了:

Installing build/Build/Products/Staging-iphonesimulator/flockCover.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist

Command failed: /usr/libexec/PlistBuddy -c Print:CFBundleIdentifier build/Build/Products/Staging-iphonesimulator/myApp.app/Info.plist
Print: Entry, ":CFBundleIdentifier", Does Not Exist
Run Code Online (Sandbox Code Playgroud)

在检查构建之后,似乎出现了一些问题:1)CodeSign正在Release版本上运行,如下所示:

CodeSign build/Build/Products/Release-iphonesimulator

2)从版本构建生成符号:

GenerateDSYMFile build/Build/Products/Release-iphonesimulator/flockCover.app/PlugIns/flockCoverTests.xctest.dSYM build/Build/Products/Release-iphonesimulator

其他各种事情都指向Release.

进一步检查表明这是因为我的(构建)环境变量设置不正确,例如:

export BUILT_PRODUCTS_DIR=/Users/name/github/company/app/ios/build/Build/Products/Release-iphonesimulator
export CODESIGNING_FOLDER_PATH=//Users/name/github/company/app/ios/build/Build/Products/Release-iphonesimulator/flockCover.app
export CONFIGURATION=Staging
export CONFIGURATION_BUILD_DIR=/Users/name/github/company/app/ios/build/Build/Products/Release-iphonesimulator
export CONFIGURATION_TEMP_DIR=/Users/name/github/company/app/ios/build/Build/Intermediates/ReactNativeConfig.build/Staging-iphonesimulator …
Run Code Online (Sandbox Code Playgroud)

xcode development-environment environment-variables ios react-native

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