Option可以隐式转换为Iterable- 但为什么它不只是直接实现Iterable:
def iterator = new Iterator[A] {
var end = !isDefined
def next() = {
val n = if (end) throw new NoSuchElementException() else get
end = true
n
}
def hasNext = !end
}
Run Code Online (Sandbox Code Playgroud)
编辑: 事实上它甚至比那更糟糕,因为在2.8 Option中声明了一个iterator方法:
def iterator: Iterator[A] =
if (isEmpty) Iterator.empty else Iterator.single(this.get)
Run Code Online (Sandbox Code Playgroud) 这两个查询给了我完全相同的结果:
select * from topics where name='Harligt';
select * from topics where name='Härligt';
Run Code Online (Sandbox Code Playgroud)
这怎么可能?看起来像mysql在搜索时将åäö翻译成aao.有什么办法可以解决这个问题吗?
据我所知,我到处都使用utf-8编码.终端和php都会出现同样的问题.
我正在编写我的第一个Android应用程序(我在Android上是一个菜鸟,但在java上不错).该应用程序的第一个屏幕包含一个巨大的列表(大约1.5K项)的漫画对象.我使用的代码如下:
main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/android:list"></ListView>
<TextView android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:text="@string/list_no_items"
android:id="@+id/android:empty"></TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
row.xml:
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:src="@drawable/icon" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/toptext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center_vertical"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/bottomtext"
android:singleLine="true"
android:ellipsize="marquee"
/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后我有一个适配器,它基本上采用一个Manga对象并将其名称放在行toptext中,并且它是最新更新的日期.但是,(这可能是由于单元的虚拟化引起的),结果非常慢.滚动列表需要永远,你只能滚动时间的小和平.如何使列表与contacts-app中的列表一样工作?因此,当你开始滚动时,屏幕右侧弹出一个手柄,当你拖动它时,字母会显示你滚动的距离(列表按字母顺序排序),还有,有一种方法我可以提高名单的表现吗?
对于一个非常简单的分析,我使用microtime()这样:
$now = microtime();
for (...) {
// do something
echo microtime() - $now;
$now = microtime();
}
Run Code Online (Sandbox Code Playgroud)
现在,该echo线的输出似乎是完全随机的,也就是说,我预计波动,但我没想到负数会出现.
但是,典型结果包含〜1/3的负数.我在Solaris(PHP 5.0.x)和WinVista(PHP 5.2.3)上证实了这一点.
到底发生了什么事?我是否意外地发明了一台时间机器?
我想要更少的方法.我想要一个通用的全局TestClass,我可以从中使用它在类中的任何值.
import java.util.*;
import java.io.*;
public class TestClass {
TestClass(String hello){
String hallo = hello;
String halloSecond = "Saluto!";
}
public static void main(String[] args) {
TestClass test = new TestClass("Tjena!");
System.out.println("I want "Tjena!": " + test.hallo);
TestClass testSecond = new TestClass("1");
System.out.println("I want Saluto!:" + test.halloSecond);
System.out.println("I want Saluto!:" + testSecond.halloSecond);
// How can I get glob.vars like the "Saluto!"?
}
}
Run Code Online (Sandbox Code Playgroud)
[澄清需要]我无法理解GLOB.VARS的不使用.请参阅下面的代码,在没有实例的情况下无法访问GLOB.VARS,因此出现错误.如果我保证没有恶意代码可以创建实例,使用GLOB.vars有什么问题吗?
$ javac TestClass.java
TestClass.java:19: non-static variable hallo cannot be referenced from a static context
System.out.println("It …Run Code Online (Sandbox Code Playgroud) 有没有办法找出使用VC6编译的windows静态库中的未定义符号列表?
我知道nm命令会列出linux中的所有符号,标签为"U"的符号可以标识为undefined.但是,Windows如何做到这一点?
我有这个代码的问题:
file = tempfile.TemporaryFile(mode='wrb')
file.write(base64.b64decode(data))
file.flush()
os.fsync(file)
# file.seek(0)
f = gzip.GzipFile(mode='rb', fileobj=file)
print f.read()
Run Code Online (Sandbox Code Playgroud)
我不知道它为什么不打印任何东西.如果我取消注释file.seek,则会发生错误:
File "/usr/lib/python2.5/gzip.py", line 263, in _read
self._read_gzip_header()
File "/usr/lib/python2.5/gzip.py", line 162, in _read_gzip_header
magic = self.fileobj.read(2)
IOError: [Errno 9] Bad file descriptor
Run Code Online (Sandbox Code Playgroud)
仅供参考,此版本可以正常工作:
x = open("test.gzip", 'wb')
x.write(base64.b64decode(data))
x.close()
f = gzip.GzipFile('test.gzip', 'rb')
print f.read()
Run Code Online (Sandbox Code Playgroud)
编辑:对于wrb问题.初始化时它不会给我一个错误.Python 2.5.2.
>>> t = tempfile.TemporaryFile(mode="wrb")
>>> t.write("test")
>>> t.seek(0)
>>> t.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor
Run Code Online (Sandbox Code Playgroud) 是否有更好的方法将集合附加到另一个集合而不是迭代每个元素?
我有 :
set<string> foo ;
set<string> bar ;
.....
for (set<string>::const_iterator p = foo.begin( );p != foo.end( ); ++p)
bar.insert(*p);
Run Code Online (Sandbox Code Playgroud)
有没有更有效的方法来做到这一点?
在像iPhone/iPad/Android这样的触摸设备上,用手指敲击一个小按钮很困难.没有跨浏览器方式来检测我所知道的CSS媒体查询的触摸设备.所以我检查浏览器是否支持javascript触摸事件.到目前为止,其他浏览器还没有支持它们,但是开发者频道上的最新Google Chrome 启用了触摸事件(即使是非触摸设备).而且我怀疑其他浏览器厂商会跟进,因为带触摸屏的笔记本电脑正在上市.更新:这是Chrome中的一个错误,所以现在JavaScript检测再次起作用.
这是我使用的测试:
function isTouchDevice() {
return "ontouchstart" in window;
}
Run Code Online (Sandbox Code Playgroud)
问题是,这只测试浏览器是否支持触摸事件,而不是设备.
有谁知道正确的[tm]方式为触控设备提供更好的用户体验?除了嗅探用户代理.
Mozilla有触摸设备的媒体查询.但我在其他任何浏览器中都没有看到类似的内容:https: //developer.mozilla.org/En/CSS/Media_queries#-moz-touch-enabled
更新:我想避免为移动/触摸设备使用单独的页面/网站.解决方案必须通过JavaScript检测具有对象检测功能的触摸设备,或者包含自定义触摸CSS而无需用户代理嗅探!我问的主要原因是,在我联系css3工作组之前,确保今天不可能.如果你不能按照问题的要求请不要回答;)
我知道10年前,典型的时钟精度等于系统标记,其范围为10-30ms.在过去几年中,精确度分多步增加.如今,有一些方法可以测量实际纳秒的时间间隔.但是,通常的框架仍然会以大约15ms的精度返回时间.
我的问题是,哪些步骤确实提高了精度,如何以纳秒为单位进行测量,以及为什么我们仍然经常获得小于微秒的精度(例如在.NET中).
(免责声明:我之前没有问过这个奇怪的事情,所以我猜我在搜索时错过了这个问题.请关闭并指出我的问题,谢谢.我相信这属于SO而不是任何其他SOFU网站.我理解精度和准确度之间的区别.)