我有一个Node.JS服务器,它从两个Web服务器请求数据:bbc.co.uk和sky.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) 我刚刚测试了以下代码:
int x = 90;
x = x - (x = x - 1);
System.out.print(x);
Run Code Online (Sandbox Code Playgroud)
它打印1.
据我了解,事情按以下顺序排列:
x - 1
计算并存储到内存中的临时变量.x
从项目1的临时变量中分配结果.x - the new value of x
计算.x
;我不明白为什么x
我们减去项目2的结果仍然有第2项后的初始值.我错过了什么?
我使用ContentProvider
但有时我得到标题中写的消息.是什么原因?我读到如果在关闭游标之前关闭数据库,则会出现此消息.我还读到如果我使用的话我不应该关闭光标ContentProvider
我注意到ExecutorService
我创建的对象中的某些线程具有"本机"状态."原生"是什么意思?
我知道比较浮点数的典型方法,其中解决方案是检查数字是否完全相同,但它们的差异是否非常小:
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) 比较浮点数和这样的整数是否安全?
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.我们怎样才能确保呢?
对于私有方法,我多次收到此警告。如何让 Eclipse 为公共、默认和受保护的方法显示相同(或相似)的警告?
我正在尝试了解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) 我很乐意观察共同偏好的变化。以下是我使用 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) 有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/master
dev
码.
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
.为什么它们在输出中的顺序不同?