我对Haskell很新,但我觉得我对所有人都有一个很好的理解.
我目前正在尝试使用haskell的非官方mongoDB绑定.
如果你看一下这里的代码:http://github.com/srp/mongoDB/blob/master/Database/MongoDB.hs
connect :: HostName -> [ConnectOpt] -> IO Connection
connect = flip connectOnPort (Network.PortNumber 27017)
Run Code Online (Sandbox Code Playgroud)
如您所见,此方法返回/解析为IO连接.
但是,实际上与数据库交互的所有方法都将一个简单的Connection作为参数.例如:
disconnect :: Connection -> IO ()
disconnect = conClose
Run Code Online (Sandbox Code Playgroud)
我认为这里有一些基本的东西我不理解,也许IO与IO Monad的一部分有关?我真的很无能为力,并且想知道是否有人有任何关于此事的光明.
如何在mongoDB绑定中同步到连接的IO连接?
感谢您提供的任何输入.
Common Lisp程序中的哪些操作被认为是足够原始的,以便计算算法分析中的单个"步骤"?现代lisps的实施有多广泛?
当然,使用小整数的算术只算作一个步骤,但更大的数字呢?而关于考虑之间有什么区别reverse
和nreverse
?具体来说,是nreverse
θ reverse
?那么所有的数组和序列操作呢?另外,宏如何计算 - 在分析复杂性时我应该如何考虑宏?
我在apache localhost中运行代码,并在我的主机中尝试过.在这两个方法中,该方法移动了文件,但文件似乎为0kb.
这是代码:
如果(isset($ _ POST [ '上传'])){
if($_FILES['profile_foto']['size']>0&&$_FILES['profile_foto']['size']<102400){
$image_extension=explode("/",$_FILES['profile_foto']['type']);
if($image_extension[1]!="jpeg")
echo "<script type='text/javascript'>alert('The extension of the profile image must be jpeg!!!')</script>";
else{
if($_POST['image_id']==""){
$image_id= md5(uniqid());
$_FILES['profile_foto']['name']="tempo/".$image_id.".jpg";
move_uploaded_file($_FILES['profile_foto']['temp_name'],$_FILES['profile_foto']['name']);
list($width,$height)=getimagesize("tempo/".$image_id.".jpg");
if($width<=0||$width>170||$height<=0||$height>200){
$myFile="tempo/".$image_id.".jpg";
$fh=fopen($myFile,'w') or die("The File could not be opened!!!");
fclose($fh);
unlink($myFile);
echo "<script type='text/javascript'>alert('The width of your profile image must be less than 170 px, the height must be less than 200 px!!!')</script>";
}
else
$_POST['image_id']=$fotograf_id;
}
else{
$image_id= md5(uniqid());
$_FILES['profile_foto']['name']="tempo/".$image_id.".jpg";
move_uploaded_file($_FILES['profile_foto']['temp_name'],$_FILES['profile_foto']['name']);
list($width,$height)=getimagesize("tempo/".$image_id.".jpg");
if($width<=0||$width>170||$height<=0||$height>200){
$myFile="tempo/".$image_id.".jpg";
$fh=fopen($myFile,'w') or die("The File could …
Run Code Online (Sandbox Code Playgroud) 有人分叉了我的项目并进行了一些更改.都好.他的所有更改都在一次提交中.现在他让我合并他的变化.项目托管在github上.
我遵循http://github.com/guides/pull-requests中提到的指导原则,这就是我所做的
git pull git://github.com/defunkt/grit.git master
但是由于这个命令现在gitlog说另一个人做了提交.我见过其他人提交的地方,一个人验证了它.由于这是我的项目,如何将我的名字添加到验证列表中.
问题2:2
他的评论中有一个错字.我还想修复那个应该承担他和我的名字的提交中的拼写错误.
更新:
我正在寻找一种方式来签署像这样的提交. http://github.com/rails/rails/commit/639e044298eed903566086d297ae51a535082e73
假设我们有一些非规范化数据,如下所示:
List<string[]> dataSource = new List<string[]>();
string [] row1 = {"grandParentTitle1", "parentTitle1", "childTitle1"};
string [] row2 = {"grandParentTitle1", "parentTitle1", "childTitle2"};
string [] row3 = {"grandParentTitle1", "parentTitle2", "childTitle3"};
string [] row4 = {"grandParentTitle1", "parentTitle2", "childTitle4"};
dataSource.Add(row1);
Run Code Online (Sandbox Code Playgroud)
我需要对其进行规范化,例如,使用Child.Parent和Child.Parent.GrandParent填充IEnumerable <Child>.
势在必行的方式或多或少都很明确.Linq会缩短吗?
在一个查询中更好,对于更多实体,这应该是可扩展的.
我试过像分别创建IEnumerable <GrandParent>,然后IEnumerable <Parent>分配等.
是否可以通过功能方式实现这一点?
如何在MYSQL中编写以下内容?
SELECT AVG(col1) FROM table WHERE DISTINCT col2
Run Code Online (Sandbox Code Playgroud)
更多信息:
table
col1 | col2
-----------
2 | 555.555.555.555
5 | 555.555.555.555
4 | 444.444.444.444
Run Code Online (Sandbox Code Playgroud)
返回'3'
基本上我正在尝试选择col1的平均值,其中col2中的ip地址是不同的.
我正在开发一个项目,需要一个配置文件,其数据由多个模块使用.
我的问题是:通用方法是什么?我应该从每个模块(文件)中读取配置文件还是有其他方法可以做到这一点?
我想有一个名为config.py的模块,它读取配置文件,每当我需要配置时,我会import config
做一些事情,比如config.data['teamsdir']
获取'teamsdir'
属性(例如).
响应:选择conf.py方法,因为它是模块化的,灵活的和简单的
我可以直接将配置数据放在文件中,后者如果我想从json文件读取一个xml文件或多个源我只需更改conf.py并确保以相同的方式访问数据.
接受答案:选择"Alex Martelli"的回应是因为它是最完整的.投票给其他答案,因为它们也很好,也很有用.
我正在尝试创建一个自定义上下文处理器,它将为登录用户呈现菜单项列表.我做了以下事情:
在我的settings.py中,我有
TEMPLATE_CONTEXT_PROCESSOR = ( 'django.contrib.auth.context_processors.auth', 'mysite.accounts.context_processors.user_menu', )
在帐户子模块context_processors.py
下,我现在有以下内容:
def user_menu(request): return {'user_menu':'Hello World'}
在我的模板页面上,我有以下内容:
{% if user.is_authenticated %} Menu {{user_menu}} {% endif %}
调用视图如下:
def profile(request): return render_to_response('accounts/profile.html',context_instance=RequestContext(request))
但是我无法{{user_menu}}
在页面上呈现任何内容,我知道用户已经过身份验证,因为模板的其他部分具有类似的检查正确呈现.我在这里错过了一些东西.请帮忙谢谢
编辑:谢谢Ben,Daniel,我已修复了(S)TEMPLATE_CONTEXT_PROCESSOR
,但Django现在无法解析模块,我得到以下消息
Error importing request processor module django.contrib.auth.context_processors: "No module named context_processors"
更新:我通过改变路径来修复它,django.core.context_processors.auth
似乎已经移动了模块
我有一个歌曲表和他们的每分钟节拍值,我想建立遵循如下曲线的播放列表:
^ . . .
| . .
b | . .
p | . .
m | . .
x-------------------->
time
Run Code Online (Sandbox Code Playgroud)
我意识到这可能是不可能在一个SQL语句,但我感兴趣的听力解决方案 - 现在,最好的方法,我看到在我的应用程序代码(蟒蛇)是选择超过必要和订购更多曲目.