我有一个表定义如下:
CREATE TABLE bar_table (
_id INTEGER NOT NULL PRIMARY KEY,
index INTEGER NOT NULL DEFAULT '65535',
_date DATE
)
Run Code Online (Sandbox Code Playgroud)
我的基本选择陈述是:
SELECT * FROM bar_table ORDER BY <your-clause-here>
Run Code Online (Sandbox Code Playgroud)
如何通过索引升序和日期降序来命令我的选择?即小指数在大指数之前出现.如果两个索引相同,则较晚的日期将首先出现.
文档指向我的COLLATion,但我不确定那是什么.
是否可以将项目添加到应用程序停靠菜单?
编辑:我想我错过了这个问题,我不是想找到一个方法来添加一个图标到码头.我正在寻找的是,当你右键单击itunes图标时你会在菜单上获得itunes控件(播放暂停等)我想知道如何在该菜单中添加自定义项目.
我试图让这个工作有困难.我有一个Item模型,每个Item可以有其他项目或什么也没有.
这是可能的,还是我需要做一些魔术?
我已经开始研究一些能够支持桌面客户端接口和Web界面的更大的服务器应用程序框架,并且对两个明显的服务器应用程序框架实际上没有做什么:J2EE和.NET.从语言的角度来看,从功能的角度,可移植性的角度来看......我对这两种产品的理解非常满意.我会简单地说,在大多数情况下,根据我的初步分析,要么足够满足需要.
虽然事情是痛苦的,但要找到一个很好的比较工程师,他们在这十年的大部分时间里都在与一个,另一个或两者兼而有之.您从Sun,Microsoft或一本书中获得的无证挫折.
谷歌搜索结果很多,但大多数都来自2002-04.可以说,自那以后,情况发生了很大变化.J2EE已经变得更加简单了,而且.NET应该会有更多的功能丰富.
是否有人知道可能值得一读的更多当前比较(在过去两年)?
我正在尝试使用ThreadLocal为预先存在的非线程安全类提供线程安全性,但遇到问题.似乎没有执行隔离 - 线程仍然共享静态,而不是每个线程的本地.
我相信我的用法几乎与此StackOverflow问题中SimpleDateFormatter描述的示例本地化完全平行,但它并没有按照我希望的方式运行.
我所希望的是,那些使用过它的人会指出我必须做出的令人震惊的无知错误......所以我想我的问题是:你能发现我在这里做错了什么吗?
这是我的简单课程:
public class SimpleClassWithStaticMembers {
private static String theStaticString =
"StaticStringInClassWithStaticMember";
public void setTheStaticString (String val) {
SimpleClassWithStaticMembers.theStaticString = val;
}
public String getTheStaticString () {
return SimpleClassWithStaticMembers.theStaticString;
}
}
Run Code Online (Sandbox Code Playgroud)
这是创建threadlocal实例的线程类SimpleClassWithStaticMembers:
public class SimpleTesterThread extends Thread {
private void showMsg (String msg) {
System.out.println (msg);
System.out.flush();
}
public SimpleTesterThread (String threadId) {
super(threadId);
}
public void run() {
try { Thread.sleep(2000); } catch (InterruptedException ex) { } …Run Code Online (Sandbox Code Playgroud) 现在我在我的-viewDidLoad方法中使用它:
UIToolbar *toolbar = [[UIToolbar alloc] init];
UIBarButtonItem *flexibleSpace = [UIBarButtonItem alloc];
flexibleSpace = [flexibleSpace initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
// Add a back button to allow user to close the modal view
NSString *back = NSLocalizedString(@"Back", nil);
UIBarButtonItem *backButton = [UIBarButtonItem alloc];
backButton = [backButton initWithTitle:back
style:UIBarButtonItemStyleDone
target:self
action:@selector(dismissModalViewControllerAnimated:)];
// Add a centered title to the toolbar
// I doubt this is the "correct" way to do this, but it seems to work.
// The "width" property of a …Run Code Online (Sandbox Code Playgroud) 我在网上找不到任何pthread_cond_wait在Mac OS X上出现奇怪的证据,但似乎对我来说似乎没有最简单的测试.
功能
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t * );
Run Code Online (Sandbox Code Playgroud)
应该解锁互斥参数#2,然后等待条件参数#1发送信号.我写了一个简单的程序来测试它,并测试虚假的唤醒:
#include <stdio.h>
#include <pthread.h>
pthread_t spin_thread;
pthread_mutex_t spin_mutex;
pthread_cond_t spin_cond;
int actual = 0;
void *condspin( void *v ) {
int expected = 0;
for ( ;; ) {
if ( actual != expected ) printf( "unexpected %d\n", actual );
else printf( "expected %d\n", actual );
pthread_mutex_lock( &spin_mutex );
printf( "locked\n" );
expected = actual + 1;
pthread_cond_wait( &spin_cond, &spin_mutex );
}
return NULL;
}
int main( …Run Code Online (Sandbox Code Playgroud) 我DllImport在我的解决方案中使用.
我的问题是我有两个版本的相同的DLL一个为32位而另一个为64位.
它们都使用相同的名称和相同的签名来公开相同的功能.我的问题是我必须使用两个静态方法来暴露这些,然后在运行时使用IntPtr大小来确定要调用的正确方法.
private static class Ccf_32
{
[DllImport(myDllName32)]
public static extern int func1();
}
private static class Ccf_64
{
[DllImport(myDllName64)]
public static extern int func1();
}
Run Code Online (Sandbox Code Playgroud)
我必须这样做,因为myDllName32并且myDllName64必须保持不变,我还没有找到在运行时设置它的方法.
有没有人有一个优雅的解决方案,所以我可以摆脱代码重复和不断的IntPtr大小检查.
如果我可以设置文件名,我只需要检查一次,我就可以摆脱大量重复的代码.
因此,基本上我们必须创建一个双重链接列表,这个列表一般是模板化的,而不是锁定到单个数据类型.我已经尝试使用gcc和msvc进行编译,两个编译器都给了我大致相同的错误,所以我假设它只是我的错误编码,而不是一个编译器或另一个编译器的古怪.
目前,我收到错误,说我的课程linkList.h不是模板
../linkList.h:34:错误:'llist'不是模板类型
../linkList.h:143:错误:'iter'不是模板类型
../josephus.cpp:14:错误:' llist'不是模板
../josephus.cpp:14:错误:聚合'llist ppl'的类型不完整,无法定义
../josephus.cpp:15:错误:'iter'不是模板
linkList.h
template<typename T>
class iter
{
public:
iter()
{
position = sentin;
container = sentin->payload;
}
T get() const
{
assert(position != sentin);
return position->payload;
}
void next()
{
position = position->next;
}
void previous()
{
position = position->prev;
}
bool equals(iter itr) const
{
return position == itr.position;
}
private:
node *position;
llist *container;
};
Run Code Online (Sandbox Code Playgroud)
josephus.cpp
llist<int> ppl;
iter<int> pos;
int start = static_cast<int>(argv[1]) - 1;
int end …Run Code Online (Sandbox Code Playgroud) 本周末,我决定尝试一些Scala和Clojure.我精通面向对象的编程,因此Scala很容易学习语言,但想尝试函数式编程.这是它变得艰难的地方.
我似乎无法进入编写函数的模式.作为一名专业的功能程序员,您如何解决问题?
给定一个值列表和一个定义的求和周期,您将如何生成列表中简单移动平均值的新列表?
例如:给定列表values(2.0,4.0,7.0,6.0,3.0,8.0,12.0,9.0,4.0,1.0)和period4,函数应该返回:(0.0,0.0,0.0,4.75,5.0,6.0, 7.25,8.0,8.25,6.5)
在花了一天时间考虑它之后,我在Scala中想出的最好的是:
def simpleMovingAverage(values: List[Double], period: Int): List[Double] = {
(for (i <- 1 to values.length)
yield
if (i < period) 0.00
else values.slice(i - period, i).reduceLeft(_ + _) / period).toList
}
Run Code Online (Sandbox Code Playgroud)
我知道这是非常低效的,我宁愿做类似的事情:
where n < period: ma(n) = 0
where n = period: ma(n) = sum(value(1) to value(n)) / period
where n > period: man(n) = ma(n -1) - (value(n-period) / period) + (value(n) / period)
Run Code Online (Sandbox Code Playgroud)
现在,这将很容易以一种命令式的方式完成,但我不能为我的生活弄清楚如何在功能上表达.