我想在外部网站上添加一些广告,为此,我使用iframe:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body style="background:#ddd">
<center>My ad</center>
<iframe src="http://www.google.com" style="position:fixed; top:50px; left:0; width: 100%; bottom: 0; border: 0 ">
<p>Your browser does not support iframes.</p>
</iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
iframe位于正确的位置,但'bottom:0'不起作用:为什么?我希望iFrame跟随窗口大小调整:如何继续?
我是非常新的PHP,我发现了一个画廊脚本,从文件夹中取出所有照片并显示它们.我正在尝试让数组忽略名为'app_thumbnails'的'photos'文件夹中的所有文件夹.
创建数组的代码是:
//READ FILES AND FOLDERS
$files = array();
$dirs = array();
if ($handle = opendir($currentdir))
{
while (false !== ($file = readdir($handle)))
{
// Change filename to display date
$displaydate= date('jS M Y', strtotime($file));
// Load folders into array
if (is_directory($currentdir . "/" . $file))
{
if ($file != "." && $file != ".." )
{
// Set thumbnail to folder.jpg if found:
if (file_exists(GALLERY_ROOT . "photos/" . $file . "/folder.jpg"))
{
$dirs[] = array(
"name" => $file,
"date" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Valum的Ajax Upload在我正在制作的基于Django的网站上进行文件上传.目前我正在避免表单只是因为AU在ajax请求中将上传作为整个POST数据发送.现在我有一个非常天真的方法来做到这一点:
upload = SimpleUploadedFile( filename, request.raw_post_data )
...then I loop through the chunks to write to disk...
Run Code Online (Sandbox Code Playgroud)
这适用于小文件.我已经测试了PDF,各种其他文件,以及大约20MB的Google Chrome deb软件包,它们都很棒.但是,如果我升级到类似CD或DVD的东西,它会发生可怕的轰炸.Django通常会发回Out of Memory响应.从表面上看,这是有道理的,因为SimpleUploadedFile是上传类的内存中版本.我看不到如何使用TemporaryUploadedFile,因为它没有在其构造函数中获取实际内容.作为旁注:我认为在耗尽可用的RAM后,它会转到虚拟内存,但无论如何.
所以,我的问题是,我如何让它工作?有更好的方法来读取文件吗?我尝试通过Python的IO直接读取raw_post_data(系统使用2.6.5),但是当使用二进制文件时,FileIO的ascii编码器/解码器显然会抱怨非ascii字符.我无法找到有关更改编码器/解码器的信息.
我不介意将数据传递到表单中并让Django完成选择正确的上传类的工作等等,但我无法弄清楚如何传递它,因为像
upload_form = UploadForm( request.POST, request.FILES )
Run Code Online (Sandbox Code Playgroud)
将无法工作,因为POST包含文件而不是正常的Django信息,并且FILES不存在.
正如我所说,我并不担心解决方案的方法,只是我得到了一些有用的东西!谢谢!
我有以下测试脚本:
<?php
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Floppy Jalopy\n";
fwrite($fh, $stringData);
$stringData = "Pointy Pinto\n";
fwrite($fh, $stringData);
fclose($fh);
?>
Run Code Online (Sandbox Code Playgroud)
然而,当运行并打开usign记事本时,数据将在一行中返回而不会中断:
软盘Jalopy(疯狂的盒子)Pointy Pinto(疯狂的盒子)
我无法找到"疯狂的盒子"的合适角色,但它是一个非常疯狂的盒子.是什么赋予了!
我有一个Swing应用程序,它使用Java Thread来不断执行某些操作.此操作的结果更新UI中图形的内容:
class ExampleThread {
...
public void run() {
while (running) {
// extract some information
...
// show results in UI
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// use information to update a graph
}
});
// sleep some seconds
...
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是当EDT在其他操作中膨胀时.在这种情况下,ExampleThread可以注册Runnable更新图形的各种实例.对于我的应用程序,由于图表将在显示结果之前多次更新,因此将浪费时间.我想要的是//update a graph每个EDT周期最多运行一次代码.
我的问题是:确保a Runnable只运行一次的正确方法是什么?
在Python中我可以这样做:
animals = ['dog', 'cat', 'bird']
for i, animal in enumerate(animals):
print i, animal
Run Code Online (Sandbox Code Playgroud)
哪个输出:
0 dog
1 cat
2 bird
Run Code Online (Sandbox Code Playgroud)
我如何在Clojure中完成同样的事情?我考虑使用这样的列表理解:
(println
(let [animals ["dog" "cat" "bird"]]
(for [i (range (count animals))
animal animals]
(format "%d %d\n" i animal))))
Run Code Online (Sandbox Code Playgroud)
但这会打印出数字和动物的每一个组合.我猜有一种简单而优雅的方法可以做到这一点,但我没有看到它.
我正在为我的.NET应用程序编写密码salt/hash过程,主要遵循本文的指南:http: //www.aspheute.com/english/20040105.asp
基本上,计算盐渍哈希的代码是这样的:
public string ComputeSaltedHash(string password, byte[] salt) {
// Get password ASCII text as bytes:
byte[] passwordBytes = System.Text.Encoding.ASCII.GetBytes(password);
// Append the two arrays
byte[] toHash = new byte[passwordBytes.Length + salt.Length];
Array.Copy(passwordBytes, 0, toHash, 0, passwordBytes.Length);
Array.Copy(salt, 0, toHash, passwordBytes.Length, salt.Length);
byte[] computedHash = SHA1.Create().ComputeHash(toHash);
// Return as an ASCII string
return System.Text.Encoding.ASCII.GetString(computedHash);
}
Run Code Online (Sandbox Code Playgroud)
但是,我想允许允许用户在他们的密码中使用Unicode字符,如果他们喜欢的话.(这似乎是一个好主意;任何人都可以想到它不是的原因吗?)
不过,我不知道一吨关于Unicode是如何工作的,我很担心,如果我只是改变的两个引用System.Text.Encoding.ASCII到System.Text.Encoding.Unicode,哈希算法可能会产生一些字节的组合不构成有效的Unicode字符和GetString的调用会发飙出.
这是一个有效的问题,还是可以的?
我有一个国家偏好的应用程序.用户将有两种类型的国家偏好 - 事件和研究.将来可能会有更多.我更倾向于使用2个表来表示使用STI.我在执行此操作时优雅地配置Rails有点麻烦.我可以破解它,但我宁愿通过Rails惯例来做到这一点.我想要的是这样的:
class User < ActiveRecord::Base
has_many event_countries, :through => :event_countries, :class_name => 'Country'
has_many research_countries, :through => :research_countries, :class_name => 'Country'
end
class EventCountry < ActiveRecord::Base
belongs_to :country
belongs_to :user
end
class ResearchCountry < ActiveRecord::Base
belongs_to :country
belongs_to :user
end
class Country < ActiveRecord::Base
...
end
Run Code Online (Sandbox Code Playgroud)
但这不起作用.鉴于这个"伪代码"有没有人知道如何在Rails中实际实现它?
我使用NUnit集成测试.我正在尝试测试以确保用户无法使用现有电子邮件创建帐户.(test@example.com)
我需要在数据库中有测试数据(使用test@example.com电子邮件帐户).
我可以在测试函数或sql脚本中创建此帐户(并在集成测试之前运行它).
创建此测试数据的最佳位置在哪里?
我将一个集合(rss feed)绑定到一个列表框中,如下所示:
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<HyperlinkButton Content={Binding Title} NavigateUri="{Binding Link}" />
<TextBlock Text="{Binding Description}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
这很好用 - 数据显示正确等等.但是现在当我将其更改为使用文本换行时,标题不再显示.
这是有问题的代码.
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<HyperlinkButton NavigateUri="{Binding Link}">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" />
</HyperlinkButton>
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
我不认为这是导致问题的"TextWrapping"属性,因为我试过没有它,但它仍然无法正常工作.所以我的问题是你如何得到这样的东西?我只想显示包装绑定文本的超链接.看起来这是一件相当简单的事情 - 但还是那么难.救命?
php ×2
.net ×1
ajax ×1
arrays ×1
c# ×1
clojure ×1
data-binding ×1
django ×1
enumeration ×1
fopen ×1
fwrite ×1
hash ×1
html ×1
hyperlink ×1
iframe ×1
java ×1
nunit ×1
passwords ×1
silverlight ×1
swing ×1
text-files ×1
unicode ×1
unit-testing ×1