小编pig*_*ack的帖子

世界城市数据库(Open Street Map?)

我花了一个下午的时间寻找世界上最重要城市的开放数据库,

其中大部分是高级的,花费400美元,但由于我正在开发一个开源项目,我想使用开放数据,是否有可以下载重要城市名称的地方?

我找到了开放的街道地图,但它是16gb的节点关系等东西,但我只需要城市名称和坐标,

非常感谢你,

G

maps openstreetmap opendata

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

在Chrome扩展程序中执行jQuery.ajax请求时更改Cookie

我为facebook写了一个发送数据的插件testing-fb.local.如果用户已登录,则请求将通过.

这是工作流程:

  1. 用户登录 testing-fb.local
  2. 存储Cookie
  3. 何时$.ajax()从Chrome扩展程序中触发
    • Chrome扩展程序可以收听 chrome.webRequest.onBeforeSendHeaders
    • Chrome扩展程序会检查来自的Cookie chrome.cookies.get
    • Chrome会更改Set-Cookies要发送的标头

请求通过.

我写了这部分代码,应该是这样的:

function getCookies (callback) {
  chrome.cookies.get({url:"https://testing-fb.local", name: "connect.sid"}, function(a){
    return callback(a)
  })
}

chrome.webRequest.onBeforeSendHeaders.addListener(
  function(details) {
    getCookies(function(a){

// Here something happens

    })
  },
  {urls: ["https://testing-fb.local/*"]},
  ['blocking']);
Run Code Online (Sandbox Code Playgroud)

这是我的manifest.json:

{
  "name": "test-fb",
  "version": "1.0",
  "manifest_version": 1,
  "description": "testing",
  "permissions": [
    "cookies",
    "webRequest",
    "tabs",
    "http://*/*",
    "https://*/*"
  ],    
  "background": {
    "scripts": ["background.js"]
  },
  "content_scripts": [
        {
          "matches": ["http://*.facebook.com/*", "https://*.facebook.com/*"],
          "exclude_matches" : [
            "*://*.facebook.com/ajax/*",
            "*://*.channel.facebook.tld/*", …
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-chrome-extension

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

Node中对象数组中的IndexOf

我不确定在对象数组中使用indexOf

不起作用的代码是:

if (res.locals.company.companies.indexOf(req.query.companyId) >= 0) return next()
Run Code Online (Sandbox Code Playgroud)

if条件总是返回false.

我也在控制台测试过它实际上是错误的:

>> var zio = { __v: 1,
  _id: '50bc0238049a1ff10b000001',
  companies: 
   [ { _id: '50bc01938f164ee80b000001', name: 'Test' },
     { _id: '50bc01ac4e860ee90b000001', name: 'zio' } ],
}

>> zio.companies.indexOf("50bc01938f164ee80b000001")
-1
Run Code Online (Sandbox Code Playgroud)

而它应该是真的.

我应该使用任何神秘的下划线实用程序吗?

更新/澄清:我的目的是检查其中一个ID中是否存在50bc01938f164ee80b000001,我不需要知道它实际上在哪里.这非常重要!

Nodejs的解决方案或提示会很棒!

javascript node.js

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

Haskell简化技术和monad

如何减少/简化此代码(或通常,具有多个输入的代码)?

do
  sex    <- askSex
  name   <- askName
  sayHello sex name
Run Code Online (Sandbox Code Playgroud)

在这种情况下已经非常短,但当它达到多个输入时,它看起来很乱.有什么方法可以做以下事情:

sayHello askSex askName
Run Code Online (Sandbox Code Playgroud)

haskell

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

Nodejs提供1个api端点和一个html页面

这是我的问题.我没有在使用express的情况下在节点中写东西,所以我发现很难用基本API创建服务器.

基本上我在互联网上找到的是:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
Run Code Online (Sandbox Code Playgroud)

但是我没有看到如何实现/index.html和/ getData.这段代码将在Raspberry派上运行,这就是我不应该使用库的原因.基本上我没有太多空间.

非常感谢,h

node.js

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

AngularJS,如果未包装到div中,则ng-switch失败:无法设置未定义的属性“ nodeValue”

我有两个指令:

app.directive('uiElement', function () {
  return {
    restrict: 'A',
    replace: true,
    scope: {element: "=uiElement", search: "=search"},
    templateUrl: "/views/uiElement.html",
    link: function (scope, elem, attrs) {
      scope.isImage = function () {
        return (scope.element.type === 'image/png' || scope.element.type === 'image/jpeg');
      };
      scope.isList = function () {
        return (scope.element.type === 'text/list');
      };
      scope.isTodo = function () {
        return (scope.element.type === 'text/todo');
      };
    }
  };
});
Run Code Online (Sandbox Code Playgroud)

以及相关的模板:

<article class="uiElement" ng-class="{typeImage: isImage(), typeList:isList(), typeTodo:isTodo()}" ng-switch on="element.type">
  <div><div class="inside" ng-switch-when="image/png">
    <i ui-image="element"></i>
  </div></div>
  <div><div class="inside" ng-switch-when="image/jpeg">
    <i …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-directive

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

在java 8中从整数数组减少到两倍

这是我的代码:

// assuming HashMap<String, Integer> hashmap
double sum = hashmap.values().stream()
    .reduce(.0, (i, v) -> i + Math.pow(v,2) + 0.5 );
Run Code Online (Sandbox Code Playgroud)

在这种情况下,reduce应该采用(Integer i)和(double v)并将它们相加并将此reduce作为double返回.

相反,我得到这个错误:

- The method reduce(Integer, BinaryOperator<Integer>) in the type Stream<Integer> is not applicable for the arguments (double, (<no type> i, <no type> v) -> {})

- Type mismatch: cannot convert from double to Integer
Run Code Online (Sandbox Code Playgroud)

降低,

但是,这个修复:

// assuming HashMap<String, Integer> hashmap
double sum = hashmap.values().stream()
    .map((t)->(double)t)
    .reduce(.0, (i, v) -> i + Math.pow(v,2) + 0.5 );
Run Code Online (Sandbox Code Playgroud)

这样做有更优雅的方式吗?

java java-8 java-stream

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

如果list只有foldr的偶数,则返回true

我想有一个函数检查列表是否只包含偶数; 如果是这样,它应该返回True,否则 - False.

功能我想用的map/ filter/ foldr,可能没有length.

这是我的尝试:

ListOfeven :: [Integral] -> Bool
ListOfeven xs = 
  | foldr (+) True filter odd xs < 0 = True
  | otherwise = False
Run Code Online (Sandbox Code Playgroud)

我很确定有一种更清洁的方式......不存在吗?:)

haskell list

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

Angular Js:FB登录不会更新我的$ scope值

我无法使用角度js打印fb名称.我不确定出了什么问题.在下面的代码中,"no_name"被打印出来.JSON警报正确显示.

I have this view code trying to print l from the scope 
<div ng-controller="TestCtrl">
{{n}}
</div>

This is the controller code:
function TestCtrl($scope){

$scope.n="no_name";// default value

    FB.login(function(response) {// fb login as soon as the ui loads
        if (response.authResponse) {
            FB.api('/me', function(response) {
                alert(JSON.stringify(response));
                $scope.n=response.name;
            });
        } else {
            //do nothing..
        }
    });

}
Run Code Online (Sandbox Code Playgroud)

facebook angularjs

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

Java - 填充ArrayList会产生空指针错误

在我的班上我定义:

private ArrayList<BlockObject> blocks;
Run Code Online (Sandbox Code Playgroud)

然后:

blocks.add(new BlockObject(x, y));
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个错误

02-22 17:06:52.672: E/AndroidRuntime(479): Caused by: java.lang.NullPointerException
02-22 17:06:52.672: E/AndroidRuntime(479):  at com.comp1008.hhh.uuu.Scenario.blocks(Scenario.java:41)
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

java nullpointerexception

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