我正在使用Rails 3.0.3并且已经在数据库中拥有我的"类别"表的数据,但是想要从中创建种子文件.是否有任何rake任务将从此表中为我生成seeds.rb格式?
我正在尝试编译我的代码并在不同的服务器上运行它.问题是我的JRE版本是Java版本"1.6.0_13",服务器上的版本是Java版本"1.4.2".
当我尝试在服务器上运行jar时,这给了我"无法识别的类文件版本"异常.我无法在服务器上编译我的代码,因为我将不得不设置各种依赖项.
所以我需要知道是否有办法"使用Eclipse"[这比命令行更容易,因为它负责依赖]并使用1.4.2而不是1.6.0_13编译我的东西.我是否必须从我的机器上卸载我的JRE,然后重新安装以前的版本然后编译或者是否有一种优雅和清洁的方式?
我有两节课,Foo和Bar.每个Bar都包含很多Foos.Foos可以是多个Bars但每个Foo只能在给定的Bar一次.我有以下表结构:
CREATE TABLE `bar_foos` (
`bar_id` INT UNSIGNED NOT NULL,
`foo_id` INT UNSIGNED NOT NULL,
PRIMARY KEY ( `bar_id` , `foo_id` )
);
Run Code Online (Sandbox Code Playgroud)
这应该适用于我的多对多关系.我的问题是,如果我希望我的代码能够检查是否有Foo任何Bars 正在使用,IE告诉用户"这个Foo不能被删除,因为它正被5条棒使用",是PRIMARY KEY吗? index帮我查询一下
SELECT * FROM `bar_foos` WHERE `foo_id`=2
Run Code Online (Sandbox Code Playgroud)
要么
SELECT COUNT(*) FROM `bar_foos` WHERE `foo_id`=2
Run Code Online (Sandbox Code Playgroud)
或者,我是否需要单独使用单独的索引foo_id?
在阅读其他代码时,我看到写的函数都以分号结尾而不是以分号结尾.
有:
var testFunction = function() {
// magic happens here
};
Run Code Online (Sandbox Code Playgroud)
无:
var testFunction = function() {
// magic happens here
}
Run Code Online (Sandbox Code Playgroud)
更新:我还发现这非常有用=> https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope
我有这个代码,它找到字符串中特定字符的最大索引,但是我希望它ValueError在字符串中没有出现指定字符时引发.
所以像这样:
contains('bababa', 'k')
Run Code Online (Sandbox Code Playgroud)
会导致:
→ ValueError: could not find k in bababa
我怎样才能做到这一点?
这是我的函数的当前代码:
def contains(string,char):
list = []
for i in range(0,len(string)):
if string[i] == char:
list = list + [i]
return list[-1]
Run Code Online (Sandbox Code Playgroud) 我目前正在研究套接字编程,并遇到了一个我需要帮助的问题.我试图做的是编写一个Java类,它将连接到Web主机,下载默认页面,然后断开与主机的连接.我知道使用URLConnection来做这件事比较简单,但我正在尝试学习套接字类.我已成功连接到Web服务器,但我在浏览页面时遇到了困难.到目前为止,这是我工作(而不是工作)的原因:
import java.io.*;
import java.net.*;
import java.lang.IllegalArgumentException;
public class SocketsFun{
public static void main(String[] myArgs){
// Set some variables
String theServer = null;
String theLine = null;
int thePort = 0;
Socket theSocket = null;
boolean exit = false;
boolean socketCheck = false;
BufferedReader theInput = null;
// Grab the server and port number
try{
theServer = myArgs[0];
thePort = Integer.parseInt(myArgs[1]);
System.out.println("Opening a connection to " + theServer + " on port " + thePort);
} catch(ArrayIndexOutOfBoundsException aioobe){
System.out.println("usage: SocketsFun …Run Code Online (Sandbox Code Playgroud) 我有一个显示图像的html页面.它应该延迟,更改为视频,然后在视频播放后,更改回图像.这是我正在使用的JavaScript:
<script type="text/javascript">
function playVideo(){
var str='**html of the video object**';
document.open();
document.write(str);
document.close();
}
function backToImage(){
var str='**html of the image**';
document.open();
document.write(str);
document.close();
}
setTimeout("playVideo()",1000);
setTimeout("backToImage()",3000);
</script>
Run Code Online (Sandbox Code Playgroud)
此JavaScript可在Chrome和Safari中使用.它主要在IE中工作(第二次超时不起作用,但我刚刚发现了这一点).它在Firefox中根本不起作用.没有延迟,视频只是开始播放,我从来没有看到图像; 之前或之后.
对此的任何想法都会很棒.
编辑:所以似乎应该责备document.write.改变标题以反映这一点.
如果我的原始问题不清楚,我要找的是用视频替换图像,然后用图像替换视频.这都是在iframe中加载的,所以我需要使用document.write(或类似的东西)来实际更改 html.
我正在使用Google的webapp框架.
我在下面尝试做的只是将query.fetch的结果发送到一个函数,该函数将获取结果并使用它们创建一个表.
class Utilities():
def create_table(results):
#Create a table for the results....
Run Code Online (Sandbox Code Playgroud)
变量results从query.fetch返回两个结果
results = query.fetch(10) #This returns two results
util = Utilities()
util.create_table(results)
Run Code Online (Sandbox Code Playgroud)
然后我得到了错误
util.create_table(results)TypeError:create_table()只取1个参数(给定2个)
我以为results会自动通过引用传递.我错了吗?
我一直在环顾四周,似乎答案是否定的,但帖子已过时,所以我想知道这是否已经改变.是否可以将状态栏设置为半透明?我试图在多点触控水龙头上做淡入/淡出效果,但状态栏不断变成坚固的黑色.
谢谢!
- 编辑 - 我用于事件转换的代码如下.我已经在-info.plist中将状态栏设置为半透明,但我注意到IB中没有黑色半透明设置(这可能是我的答案:没有半透明状态栏,除非你是Apple.)
-(IBAction)showOptions:(id)sender
{
if ([UIApplication sharedApplication].statusBarHidden == YES) {
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
[UIView beginAnimations:@"fadeIn" context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
optionsView_portrait.alpha = 0.5;
[UIView commitAnimations];
}
else
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
[UIView beginAnimations:@"fadeOut" context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
optionsView_portrait.alpha = 0.0;
[UIView commitAnimations];
}
}
Run Code Online (Sandbox Code Playgroud) python ×3
java ×2
javascript ×2
activerecord ×1
coding-style ×1
eclipse ×1
firefox ×1
indexing ×1
ios ×1
ios-4.2 ×1
javac ×1
many-to-many ×1
mysql ×1
optimization ×1
printing ×1
rake ×1
sockets ×1
statusbar ×1
string ×1
translucency ×1