我一直在比较有趣的不同语言的速度执行以下程序:对于i从1到1000000总和产品i*(sqrt i)
我的一个实现(不是唯一的)是构造一个列表[1..1000000],然后用特定的函数折叠.
该程序在Haskell中工作得很好(即使使用foldl而不是foldl'),但在OCaml和F#中堆栈溢出.
这是Haskell代码:
test = foldl (\ a b -> a + b * (sqrt b)) 0
create 0 = []
create n = n:(create (n-1))
main = print (test (create 1000000))
Run Code Online (Sandbox Code Playgroud)
这是OCaml:
let test = List.fold_left (fun a b -> a +. (float_of_int b) *. (sqrt (float_of_int b))) 0. ;;
let rec create = function
| 0 -> []
| n -> n::(create (n-1)) ;;
print_float (test (create 1000000));;
Run Code Online (Sandbox Code Playgroud)
为什么OCaml/F#实现堆栈溢出?
看来fieldset默认为其容器的100%宽度.有没有什么方法可以让字段设置与字段集中最宽的控件一样大?
我是一个网络系统,无法决定使用什么技术!Struts2和JSF(带jboss接缝)是一个不错的选择,但我无法决定哪个更好.在JSF中有一些我不喜欢的,也许它的"范式"没有动作就好.而Struts2,这里的人们不会使用更多.
该系统是地图协作网站.
我正在尝试将rails应用程序部署到heroku,但不断收到以下错误.我曾经想过,管理postgres宝石将是heroku将要处理的事情.
我已经尝试了所有我能想到的东西,而不是在我的本地机器上安装postgres,如果我想安装postgres gem,我需要这样做.还有没有叫做的宝石activerecord-postgresql-adapter...我猜这是铁轨附带的标准适配器?
有关如何解决此问题的任何想法?
App failed to start
/usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `establish_connection': Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (no such file to load -- pg) (RuntimeError)
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in `establish_connection'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in `establish_connection'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:438:in `initialize_database'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:141:in `process'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `run'
from /disk1/home/slugs/135415_c7f31f0_9f1f/mnt/config/environment.rb:9
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
... 14 levels...
from /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/builder.rb:29:in `instance_eval'
from /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/builder.rb:29:in `initialize'
from /home/heroku_rack/heroku.ru:1:in `new'
from /home/heroku_rack/heroku.ru:1
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用此代码Bitmap直接绘制到PictureBox:
Bitmap bmp = (Bitmap)Bitmap.FromFile(@"C:\Users\Ken\Desktop\Load2.bmp");
Graphics grDest = Graphics.FromHwnd(pictureBox1.Handle);
Graphics grSrc = Graphics.FromImage(bmp);
IntPtr hdcDest = grDest.GetHdc();
IntPtr hdcSrc = grSrc.GetHdc();
BitBlt(hdcDest, 0, 0, pictureBox1.Width, pictureBox1.Height,
hdcSrc, 0, 0, (uint)TernaryRasterOperations.SRCCOPY); // 0x00CC0020
grDest.ReleaseHdc(hdcDest);
grSrc.ReleaseHdc(hdcSrc);
Run Code Online (Sandbox Code Playgroud)
但是不是渲染Bitmap它的内容,而是绘制一个近乎黑色的固体块.我很确定问题出在源hDC上,因为如果我在上面的代码中将SRCCOPY更改为WHITENESS,它会按预期绘制一个纯白色块.
注意:这个下一个片段工作正常,所以位图本身没有任何问题:
Bitmap bmp = (Bitmap)Bitmap.FromFile(@"C:\Users\Ken\Desktop\Load2.bmp");
pictureBox1.Image = bmp;
Run Code Online (Sandbox Code Playgroud) 我目前正将SVN服务器从家用服务器移动到远程服务器,以便我可以更轻松地从其他位置访问它.我的远程服务器没有备份,所以我想定期备份到我的家庭服务器.
远程服务器是Windows 2003服务器.家庭服务器是Windows Home Server.
做这个的最好方式是什么?我可以让我的家庭服务器每晚都能获得远程服务器的转储吗?带宽不是一个重要的考虑因素,但如果我可以将任何新的签到复制到我的家庭服务器上的SVN服务器那么没问题.
欢迎任何建议.
我目前正在实时服务器和本地运行带有PostgreSQL 8.4.2的Django 1.1.1站点.当我尝试从本地服务器上的实时服务器恢复其中一个备份时,在本地访问我的站点时出现以下错误(http:// localhost:8000):
Exception Type: ProgrammingError at /
Exception Value: permission denied for relation django_session
Run Code Online (Sandbox Code Playgroud)
访问我的某个模型的所有内容时,我也遇到类似的错误:
$ python manage.py shell
Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from myapp.models import MyModel
>>> MyModel.objects.all()
...
ProgrammingError: permission denied for relation myapp_mymodel
Run Code Online (Sandbox Code Playgroud)
我pg_dump在实时服务器上用于备份并删除我的本地数据库,然后psql dbname < infile进行恢复.有谁知道什么是错的?
是否可以隐藏*.php文件的名称
$(document).ready(function(){
$.getJSON("getdata.php", function(returned_data) {
if(returned_data === "1") {
$("div#wall").html('user has no subscription');
$("#message_wall").attr("disabled", "disabled");
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
});
因为该jquery代码将在页面的源代码中可见,我不希望某些恶意访问者尝试使用它.
首先我了解(或者我认为我了解)堆栈未对齐的问题。
但我知道(就像定义一样)将 16 位值推入 32 位宽堆栈可能会导致堆栈未对齐。
但我不明白的是,这是如何发生的......因为PUSH并POP检查段描述符处的 D 标志(因此 1 递增/递减 32 位,0 是 16 位)。
假设D flag=1,应该PUSH AX做32bits减1吗?所以这就像我“错过”堆栈中的 16 位?
我不确定我是否理解这个问题