小编Mak*_*iev的帖子

从Node.JS中的两个网站请求RSS提要

我有一个Node.JS服务器,它从两个Web服务器请求数据:bbc.co.uksky.com.然后解析RSS提要,并且用户看到两个列表:来自BBC和来自天空.

这是代码.

var feed = require('feed-read');
var http = require('http');
var async = require('async');
var request = require('request');

var LIMIT = 10;
var UNABLE_TO_CONNECT = "Unable to connect.";
var BBC_URL = 'http://feeds.bbci.co.uk/news/rss.xml';
var SKY_URL = 'http://news.sky.com/feeds/rss/home.xml';

var server = http.createServer(onRequest);
server.listen(9000);

function onRequest(req, res) {
    res.writeHead(200, {
        'Content-Type' : 'text/html; charset=utf-8'
    });

    async.parallel([ function(callback) {
        feed(BBC_URL, onRssFetched);
        // TODO: where to call callback()?
    }, function(callback) {
        feed(SKY_URL, onRssFetched);
        // TODO: where to call callback()?
    } ], …
Run Code Online (Sandbox Code Playgroud)

javascript rss request node.js

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

Java如何处理表达式x = x - (x = x - 1)?

我刚刚测试了以下代码:

int x = 90;

x = x - (x = x - 1);
System.out.print(x);
Run Code Online (Sandbox Code Playgroud)

它打印1.

据我了解,事情按以下顺序排列:

  1. x - 1 计算并存储到内存中的临时变量.
  2. x 从项目1的临时变量中分配结果.
  3. 然后x - the new value of x计算.
  4. 结果分配给x;

我不明白为什么x我们减去项目2的结果仍然有第2项后的初始值.我错过了什么?

java operator-precedence

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

即使我使用ContentProvider,也可以在没有事先close()消息的情况下获取Cursor

我使用ContentProvider但有时我得到标题中写的消息.是什么原因?我读到如果在关闭游标之前关闭数据库,则会出现此消息.我还读到如果我使用的话我不应该关闭光标ContentProvider

链接:关闭ContentProvider中的数据库

database cursor android-contentprovider

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

线程状态在Eclipse DDMS中是"本机"

我注意到ExecutorService我创建的对象中的某些线程具有"本机"状态."原生"是什么意思? 在此输入图像描述

eclipse android ddms

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

为什么他们在Java中使用>,<和==(float float1,float float2)?

我知道比较浮点数的典型方法,其中解决方案是检查数字是否完全相同,但它们的差异是否非常小:

float a = 0.15 + 0.15;
float b = 0.1 + 0.2;
if( Math.abs(a - b) < 0.00001)
    // The numbers are considered equal
Run Code Online (Sandbox Code Playgroud)

从这里复制了上面的例子.

而现在我不明白为什么以这种方式比较两个浮点变量是正确的:

public static int compare(float float1, float float2) {
    // Non-zero, non-NaN checking.
    if (float1 > float2) {
        return 1;
    }
    if (float2 > float1) {
        return -1;
    }
    if (float1 == float2 && 0.0f != float1) {
        return 0;
    }

    // NaNs are equal to other NaNs and larger than …
Run Code Online (Sandbox Code Playgroud)

java floating-point compare

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

在Java中比较float和int是否安全?

比较浮点数和这样的整数是否安全?

private static void foo(float n) {
    if (n >= 1 || n <= 0) {
      // code 
    } 
}
Run Code Online (Sandbox Code Playgroud)

根据JLS(5.6.2.二进制数字促销),如果其中一个参数是float,则另一个float在比较之前转换为.但据我所知,如果转换后的浮点数与原始浮点数相同,则此类比较将返回true.我们怎样才能确保呢?

java floating-point

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

类型中的方法从未在本地使用非私有方法的警告

对于私有方法,我多次收到此警告。如何让 Eclipse 为公共、默认和受保护的方法显示相同(或相似)的警告?

eclipse settings warnings

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

在父级的requestLayout之后,不会调用onMeasure和onLayout子视图

我正在尝试了解Android如何衡量和展示观点.我创建了一个包含自定义视图和视图组的示例应用.

CustomViewGroup

public class CustomViewGroup extends ViewGroup {

    private static final String LOG_TAG = "CustomViewGroup";

    public CustomViewGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        Log.d(LOG_TAG, String.format(Locale.ENGLISH,
                getTag() + " " +
                        "onMeasure(widthMeasureSpec=%d, heightMeasureSpec%d)",
                widthMeasureSpec, heightMeasureSpec
        ));

        final int count = getChildCount();
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() != View.GONE) {
                // Make or work out measurements for children here …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view onmeasure

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

Kotlin 协程。Kotlin Flow 和共享首选项。waitClose 从未被调用

我很乐意观察共同偏好的变化。以下是我使用 Kotlin Flow 执行此操作的方法:

数据源。

interface DataSource {

    fun bestTime(): Flow<Long>

    fun setBestTime(time: Long)
}

class LocalDataSource @Inject constructor(
    @ActivityContext context: Context
) : DataSource {

    private val preferences = context.getSharedPreferences(PREFS_FILE_NAME, Context.MODE_PRIVATE)

    @ExperimentalCoroutinesApi
    override fun bestTime() = callbackFlow {
        trySendBlocking(preferences, PREF_KEY_BEST_TIME)
        val listener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
            if (key == PREF_KEY_BEST_TIME) {
                trySendBlocking(sharedPreferences, key)
            }
        }
        preferences.registerOnSharedPreferenceChangeListener(listener)
        awaitClose { // NEVER CALLED
            preferences.unregisterOnSharedPreferenceChangeListener(listener)
        }
    }

    @ExperimentalCoroutinesApi
    private fun ProducerScope<Long>.trySendBlocking(
        sharedPreferences: SharedPreferences,
        key: String?
    ) {
        trySendBlocking(sharedPreferences.getLong(key, 0L))
            .onSuccess …
Run Code Online (Sandbox Code Playgroud)

android callback kotlin kotlin-coroutines kotlin-flow

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

Git,HEAD指向一个错误的分支

git branch -av命令的输出.现在我在dev分公司.

***dev** 3f126e0 Comment...
master 7a47db8 Another comment...
remotes/origin/HEAD   -> origin/master
remotes/origin/dev 3f126e0 Comment...
remotes/origin/master 7a47db8 Another comment...
Run Code Online (Sandbox Code Playgroud)

来自Scott Checkon的Pro Git一书.

How does Git know what branch you’re currently on? It keeps a special pointer called HEAD.

为什么在我上场时HEAD指向?origin/masterdev

git branch pointers

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

Java中未排序的HashSet

码.

Set<String> set = new HashSet<String>(3);
set.add("3 Lorem");
set.add("1 Lorem");
set.add("2 Lorem");
Iterator<String> iterator = set.iterator();
while (iterator.hasNext()) {
    String type = (String) iterator.next();
    System.out.println(type);
}
Run Code Online (Sandbox Code Playgroud)

输出.

2 Lorem
3 Lorem
1 Lorem
Run Code Online (Sandbox Code Playgroud)

这个命令对我来说很奇怪.我添加3 Lorem,1 Lorem然后2 Lorem.为什么它们在输出中的顺序不同?

java hashset

0
推荐指数
2
解决办法
3416
查看次数