当我在RubyMine中启动我的应用程序时,我希望能够使用独角兽和我的独角兽配置.有没有办法告诉它不要使用webrick但使用别的东西,如独角兽或瘦?
我正在寻找一种在Django中组织样式表和脚本的简单方法.我对python的框架和语言比较陌生.我来自PHP背景.
在PHP/Zend的世界中,有一些用view/layout对象实现的函数.通过在head标签中为脚本和样式表添加一行,您可以在视图 - >方法级别轻松添加样式表/脚本.我已阅读Django表单媒体文档,但这仅适用于需要特定样式和脚本的表单.
任何方向?
我想知道是否可以从页面中抛出404错误(代码隐藏)?或者甚至可能抛出任何其他类型的错误页面,如408(超时)或401(需要验证)?
注意:我不只是想让页面返回404的状态代码,我希望它使用ASP.Net(或我的CustomErrors)404错误页面.
在后面的代码中有类似的东西:
if(id>10){ //if id is greater than 10, then it doesn't exist here
throw 404Error();
}
Run Code Online (Sandbox Code Playgroud) 好吧,所以开始这是严格的Windows,我更喜欢使用C++而不是.NET,但我不反对,boost::filesystem虽然如果可以避免支持直接的Windows API我更喜欢.
现在,该场景是另一台机器上的应用程序,我无法更改将在机器上的特定目录中创建文件,我需要备份并执行一些额外的处理.目前我已经制作了一个小应用程序,它将使用FindFirstChangeNotification和FindNextChangeNotificationWindows API 在目标目录中查找和监听更改通知.
问题是,虽然我可以在目录中创建新文件,修改,大小更改等时收到通知,但它只通知一次,并没有具体告诉我哪些文件.我也看了一下ReadDirectoryChangesW,但除了我可以获得更具体的信息外,它的故事也是如此.
现在我可以扫描目录并尝试获取锁定或打开文件以确定上次通知中的具体更改以及它们是否可供进一步使用但是在复制大文件的情况下我发现这不是很好足够的文件将无法被操作,我不会在第一次之后得到任何其他通知,所以没有办法告诉它何时实际完成复制,除非在第一次通知后我不断尝试获取锁,直到它成功.
我能想到的另一件事就是不那么强硬就是拥有某种终结令牌文件,但由于我无法控制创建文件的应用程序,所以我不知道我是怎么做的要做到这一点,它仍然不理想.
有什么建议?
我在Mac上,从终端开始进行Android开发.我已经成功创建了HelloWorld项目,现在我正在尝试从Android模拟器中的命令行运行它.哪个命令为我的HelloWorld项目运行模拟器?
我的PATH中已经有了Android工具和平台工具.
编辑:
如何告诉模拟器从命令行运行我的HelloWorld项目?我已经用ant构建了这个项目.
console command-line android console-application android-emulator
我正在尝试将我从HttpPost获取的XML HttpResponse解析为服务器(last.fm),用于last.fm android应用程序.如果我简单地将其解析为字符串,我可以看到它是一个普通的xml字符串,包含所有需要的信息.但我只是无法解析单个NameValuePairs.这是我的HttpResponse对象:
HttpResponse response = client.execute(post);
HttpEntity r_entity = response.getEntity();
Run Code Online (Sandbox Code Playgroud)
我尝试了两种不同的东西,而不是它们都有效.首先,我试图检索NameValuePairs:
List<NameValuePair> answer = URLEncodedUtils.parse(r_entity);
String name = "empty";
String playcount = "empty";
for (int i = 0; i < answer.size(); i++){
if (answer.get(i).getName().equals("name")){
name = answer.get(i).getValue();
} else if (answer.get(i).getName().equals("playcount")){
playcount = answer.get(i).getValue();
}
}
Run Code Online (Sandbox Code Playgroud)
在此代码之后,name和playcount保持"空".所以我尝试使用XML Parser:
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document answer = db.parse(new DataInputStream(r_entity.getContent()));
NodeList nl = answer.getElementsByTagName("playcount");
String playcount = "empty";
for (int i = 0; i < nl.getLength(); i++) {
Node n = nl.item(i); …Run Code Online (Sandbox Code Playgroud) 当我尝试在我的用户模型中覆盖to_param以使用电子邮件地址作为id时,我的路由出错了.它似乎试图在尝试匹配路由时匹配id的整个对象.任何人都可以帮我弄清楚我错过了什么吗?
这是错误:
No route matches {:controller=>"users", :action=>"show", :id=>#<User id: 1, email: ....>}
Run Code Online (Sandbox Code Playgroud)
这是我如何设置代码.
车型/ user.rb:
attr_accessible :email
def to_param
email
end
Run Code Online (Sandbox Code Playgroud)
控制器/ users_controller.rb:
before_filter :get_user, :only=>[:show,:update,:edit,:destroy]
...
def get_user
@user = User.find_by_email params[:id]
end
Run Code Online (Sandbox Code Playgroud)
配置/ routes.rb中
resources :users
Run Code Online (Sandbox Code Playgroud)
这是rake路线的输出:
user GET /users(.:format) {:controller=>"users", :action=>"index"}
POST /users(.:format) {:controller=>"users", :action=>"create"}
new_user GET /users/new(.:format) {:controller=>"users", :action=>"new"}
edit_user GET /users/:id/edit(.:format) {:controller=>"users", :action=>"edit"}
user GET /users/:id(.:format) {:controller=>"users", :action=>"show"}
PUT /users/:id(.:format) {:controller=>"users", :action=>"update"}
DELETE /users/:id(.:format) {:controller=>"users", :action=>"destroy"}
Run Code Online (Sandbox Code Playgroud) 试图从数字中删除单引号.我正在处理第三个没有很好输入的paty数据.
lst = [ ('text','2','3','4'), ('text2','4','5','6') ]
y= [map(int,i) for i in zip(*lst)[1:]]
d = zip(*list)[0]
print d
c= zip(*y)
print c
dd = zip(d,c)
print dd
Run Code Online (Sandbox Code Playgroud)
这就是出路:
('text', 'text2')
[(2, 3, 4), (4, 5, 6)]
[('text', (2, 3, 4)), ('text2', (4, 5, 6))]
Run Code Online (Sandbox Code Playgroud)
如何得到:
dd = [ ('text',2,3,4), ('text2',4,5,6) ]
Run Code Online (Sandbox Code Playgroud)
编辑:如果列表有时是这样的话[ ['text','2','3','4'], ['text2','4','5','6'] ],那我该怎么办?另一个问题是整数为'3,400'.
新的Lst示例:
lst = [ ('text','2','3','4'), ('text2','4','5,000','6,500') ]
Run Code Online (Sandbox Code Playgroud)
需要:
[ ('text',2,3,4), ('text2',4,5000,6500) ]
Run Code Online (Sandbox Code Playgroud) 当使用依赖注入(DI)和控制反转(IoC)时,对象通常会有一个构造函数,它接受对象正常运行所需的依赖集.
例如,如果我有一个需要服务来填充组合框的表单,您可能会看到如下所示的内容:
// my files
public interface IDataService {
IList<MyData> GetData();
}
public interface IComboDataService {
IList<MyComboData> GetComboData();
}
public partial class PopulatedForm : BaseForm {
private IDataService service;
public PopulatedForm(IDataService service) {
//...
InitializeComponent();
}
}
Run Code Online (Sandbox Code Playgroud)
这在顶级工作正常,我只是使用我的IoC容器来解决依赖关系:
var form = ioc.Resolve<PopulatedForm>();
Run Code Online (Sandbox Code Playgroud)
但面对生成的代码,这会变得更难.在winforms中,生成组成其余部分类的第二个文件.此文件引用其他组件(如自定义控件),并使用no-args构造函数来创建此类控件:
// generated file: PopulatedForm.Designer.cs
public partial class PopulatedForm {
private void InitializeComponent() {
this.customComboBox = new UserCreatedComboBox();
// customComboBox has an IComboDataService dependency
}
}
Run Code Online (Sandbox Code Playgroud)
由于这是生成的代码,我无法传递依赖项,并且没有简单的方法让我的IoC容器自动注入所有依赖项.
一种解决方案是传递每个子组件的依赖关系,PopulatedForm即使它可能不需要它们直接,例如使用IComboDataService所需的UserCreatedComboBox.然后,我有责任确保通过各种属性或setter方法提供依赖项.然后,我的PopulatedForm构造函数可能如下所示:
public PopulatedForm(IDataService …Run Code Online (Sandbox Code Playgroud) c# code-generation dependency-injection inversion-of-control winforms
android ×2
python ×2
asp.net ×1
c# ×1
c++ ×1
command-line ×1
console ×1
django ×1
exception ×1
file ×1
filesystems ×1
http ×1
http-post ×1
httpresponse ×1
list ×1
multiplying ×1
parsing ×1
routing ×1
ruby ×1
rubymine ×1
string ×1
stylesheet ×1
unicorn ×1
webrick ×1
windows ×1
winforms ×1
xml ×1