灯角

文章 0 评论 0 浏览 23

灯角 2024-10-27 23:39:25

我不确定您所显示的代码中发生了什么,但会使用 Richfaces 的 < rich:ajaxValidator > 不会让生活变得更轻松吗?文档页面位于此处

I'm not sure what's happening in the code you're showing, but would using something like Richfaces' < rich:ajaxValidator > not make life easier? The doc page is here

无需持久化的 Ajax 验证

灯角 2024-10-27 18:13:37
  1. 您使用的是哪种 DOCType - 您处于“怪异模式”还是“标准模式”?
  2. 您是否使用 CSS 重置?
  3. 您使用的是 IE7 兼容性标签吗?

有多种方法可以修复“错误”的问题,但如果不查看代码,就很难确定问题所在。

IEMode

在 IE8 中按 F-12 并查看您所处的浏览器模式。如果您处于“怪异模式”,则有麻烦了。

  1. Which DOCType are you using - are you in "quirks mode" or "standards mode"?
  2. Are you using a CSS reset?
  3. Are you using the IE7 compatibility tag?

There are ways to fix what's "wrong" but without seeing your code, determining what's wrong is difficult.

IEMode

Press F-12 in IE8 and see what browser mode you are in. If you're in "quirks mode" you're in trouble.

已部署的应用程序在 IE8 中显示不同

灯角 2024-10-27 17:22:36

尝试:

text = 'abcdefa'
pattern = re.compile('a|c')
[(m.group(), m.start()) for m in pattern.finditer(text)]

Try:

text = 'abcdefa'
pattern = re.compile('a|c')
[(m.group(), m.start()) for m in pattern.finditer(text)]

如何获取Python中的字符位置列表?

灯角 2024-10-27 17:20:17

您可以使用 PHP 获取当月的第一天:

$this_month = mktime(0, 0, 0, date("m"), 1, date("Y"));
$previous_month = mktime(0, 0, 0, date("m")-1, 1, date("Y"));

然后您只需将此日期作为查询的参数传递即可:

SELECT * FROM mytable WHERE date >= ? AND date < ? and client_id = 1

在哪里替换 ?分别按 '$previous_month' 和 '$this_month'

You can get the first day of the current month using PHP:

$this_month = mktime(0, 0, 0, date("m"), 1, date("Y"));
$previous_month = mktime(0, 0, 0, date("m")-1, 1, date("Y"));

Then you simply pass this date as a parameter of your query:

SELECT * FROM mytable WHERE date >= ? AND date < ? and client_id = 1

where you replace the ? respectively by '$previous_month' and '$this_month'

在Zend Framework中选择上个月的所有记录?

灯角 2024-10-27 14:40:01

如果是从 stdin 读取并将结果写入 stdout 的问题,而无需进一步干预用户输入 - 正如您提到的 getContents建议——然后是古老的 interact :: (String -> String) -> IO(),或者其他几个版本,例如Data.ByteString.interact :: (ByteString -> ByteString) -> IO()Data.Text.interact::(Text -> Text) -> IO() 就是所需要的全部。 interact 基本上是“用这个函数制作一个小unix工具”函数——它将正确类型的函数映射到可执行操作(即类型的值) code>IO()。)所有 Haskell 教程都应该在第三页或第四页提到它,并附有编译说明。

因此,如果您

main = interact arthur

arthur :: String -> String
arthur = reverse

使用 ghc --make -O2 Reverse.hs -overse 编写和编译,那么您通过管道传输到 ./reverse 的任何内容都将被理解为字符列表,并且出现逆转。同样,无论您通过管道

main = interact (unlines . meredith  . lines)

meredith :: [String] -> [String]
meredith = filter (not.null)

传输到什么,都会出现省略空行的情况。更有趣的是,

main = interact ( unlines . map show . luther . map read . lines)

luther :: [Int] -> [Int]
luther = filter even 

将获取由换行符分隔的字符流,将它们读取为 Int,删除奇数字符,并生成适当过滤的流。

main = interact ( unlines . map show . emma . map read . lines)

emma :: [Int] -> Int
emma = sum . map square 
  where square x = x * x

将打印换行符分隔的数字的平方和。

在最后两种情况下,lutheremma 内部“数据结构”是 [Int],这非常乏味,并且应用于它的函数非常简单,课程。要点是让一种interact 形式来处理所有 IO,从而让“填充结构”和“处理它”之类的图像从您的脑海中消失。要使用interact,您需要使用组合来使整体产生某种String ->字符串函数。但即使在这里,正如第一个例子中的那样 arthur:: String -> String 您正在定义一个更像数学意义上的真正函数。 StringByteString 类型中的值与 BoolInt 中的值一样纯粹。

在这种基本交互类型的更复杂的情况下,您的任务首先是考虑如何将您将关注的函数的所需值映射到String 值(这里,对于 Int 来说只是 show ,或者对于 [Int] 来说是 unlines .map show ) 。 interact 知道如何处理字符串。 -- 然后弄清楚如何定义从字符串或 ByteString(将包含“原始”数据)到主函数作为参数的一个或多个类型中的值的纯映射。在这里我只是使用 map read 。行 产生[Int]。如果您正在处理一些更复杂的树结构,您需要一个从 [Int]MyTree Int 的函数。当然,放置在这个位置的更复杂的函数是解析器。

然后你就可以进城了,在这种情况下:根本没有理由认为自己是“编程”、“填充”和“处理”。这就是 LYAH 的所有炫酷功能发挥作用的地方。您的职责是在特定的定义规则内定义映射。在最后两种情况下,它们是从 [Int][Int] 以及从 [Int]Int >,但这里有一个类似的示例,源自 优秀但仍不完整的教程 超级优秀的 Vector,其中处理初始数字结构是 Vector Int

{-# LANGUAGE BangPatterns #-}
import qualified Data.ByteString.Lazy.Char8      as L
import qualified Data.Vector.Unboxed            as U
import System.Environment

main = L.interact (L.pack . (++"\n") . show . roman . parse)
    where 
    parse :: L.ByteString -> U.Vector Int
    parse bytestr = U.unfoldr step bytestr
    step !s = case L.readInt s of
        Nothing       -> Nothing
        Just (!k, !t) -> Just (k, L.tail t)

-- now the IO and stringy nonsense is out of the way 
-- so we can calculate properly:

roman :: U.Vector Int -> Int
roman = U.sum

这里,roman 又是低能的,从 Int 向量到 Int 的任何函数,无论多么复杂,都可以取代它。写一个更好的roman永远不会是“填充”“多行编程”“处理”等问题,尽管我们当然是这样说的;这只是一个通过 Data.Vector 和其他地方的函数组合来定义真正函数的问题。天空是极限,也请查看该教程。

If it is a question of reading from stdin and writing a result to stdout, with no further intevening user input -- as your mention of getContents suggests -- then the ancient interact :: (String -> String) -> IO (), or the several other versions, e.g. Data.ByteString.interact :: (ByteString -> ByteString) -> IO () or Data.Text.interact :: (Text -> Text) -> IO() are all that are needed. interact is basically the 'make a little unix tool out of this function' function -- it maps pure functions of the right type to executable actions (i.e. values of the type IO().) All Haskell tutorials should mention it on the third or fourth page, with instructions on compilation.

So if you write

main = interact arthur

arthur :: String -> String
arthur = reverse

and compile with ghc --make -O2 Reverse.hs -o reverse then whatever you pipe to ./reverse will be understood as a list of characters and emerge reversed. Similarly, whatever you pipe to

main = interact (unlines . meredith  . lines)

meredith :: [String] -> [String]
meredith = filter (not.null)

will emerge with the empty lines omitted. More interestingly,

main = interact ( unlines . map show . luther . map read . lines)

luther :: [Int] -> [Int]
luther = filter even 

will take a stream of characters separated by newlines, read them as Ints, removing the odd ones, and yielding the suitably filtered stream.

main = interact ( unlines . map show . emma . map read . lines)

emma :: [Int] -> Int
emma = sum . map square 
  where square x = x * x

will print the sum of the squares of the newline-separated numerals.

In these last two cases, luther and emma the internal 'data structure' is [Int], which is pretty dull, and the function applied to it is idiot simple, of course. The main point is to let one of the forms of interact take care of all of the IO, and thus get images like 'populating a structure' and 'processing it' out of your head. To use interact you need to use composition to make the whole yield some sort of String -> String function. But even here, as in the runt first example arthur:: String -> String you are defining a genuine function in something more like the mathematical sense. Values in the types String and ByteString are just as pure as those in Bool or Int.

In more complicated cases of this basic interact type, your task is thus, first, to think how the desired pure values of the function you will be focussing on can be mapped to String values (here, it's just show for an Int or unlines . map show for a [Int]). interact knows what to "do" with the string. -- And then to figure out how to define a pure mapping from Strings or ByteString (which will contain your 'raw' data) to values in the type or types your principal function takes as arguments. Here I was just using map read . lines resulting in a [Int]. If you are working on some more complicated, say tree structure you'd need a function from [Int] to MyTree Int. A more elaborate function to put in this position would be a Parser, of course.

Then you can go to town, in this sort of case: there is really no reason to think of yourself as 'programming', 'populating' and 'processing' at all. This is where all the cool devices of LYAH kick in. Your duty is to define a mapping within the specific definitional discipline. In the last two cases, these are from [Int] to [Int] and from [Int] to Int, but here is a similar example derived from the excellent, still incomplete, tutorial on the super-excellent Vector package where the initial numerical structure one is dealing with is Vector Int

{-# LANGUAGE BangPatterns #-}
import qualified Data.ByteString.Lazy.Char8      as L
import qualified Data.Vector.Unboxed            as U
import System.Environment

main = L.interact (L.pack . (++"\n") . show . roman . parse)
    where 
    parse :: L.ByteString -> U.Vector Int
    parse bytestr = U.unfoldr step bytestr
    step !s = case L.readInt s of
        Nothing       -> Nothing
        Just (!k, !t) -> Just (k, L.tail t)

-- now the IO and stringy nonsense is out of the way 
-- so we can calculate properly:

roman :: U.Vector Int -> Int
roman = U.sum

Here again roman is moronic, any function from a Vector of Ints to an Int, however complex, can take its place. Writing a better roman will never be a question of "populating" "multi-line programming" "processing" etc., though of course we speak this way; it is just a question of defining a genuine function by composition of the functions in Data.Vector and elsewhere. The sky is the limit, check out that tutorial too.

如何将IO中的数据读取到数据结构中,然后对数据结构进行处理?

灯角 2024-10-27 11:05:28

刚刚听说:http://www.locomotivecms.com/

我还没有测试过,但看起来有趣的。

我实际上是一名 php 开发人员,经常使用 Joomla,但我很快就会开始学习 Ruby(有些功能看起来很棒!,比如重新定义运算符,...)和 Ruby On Rails,以满足个人兴趣。

Just heard of : http://www.locomotivecms.com/

I've not tested it yet but it looks interesting.

I'm actually a php developer, working lot with Joomla, but I'll soon begin learning Ruby (some features just look awesome!, Like redefining operators,...) and Ruby On Rails for personal interest.

为什么没有非常著名的开源 CMS 或电子商务应用程序用 Ruby 编写?

灯角 2024-10-27 10:56:43

其中要包括的一件事是计算机领域。大多数企业都有一个难以复制的域名。对于您正在开发供内部使用的应用程序,您也可以检查是否存在多个服务器。

One thing to include in the mix is the domain of the computer. Most businesses have a domain that will be harder to reproduce. For an app you are developing for internal use, you could check for presence of a number of servers too.

将 Delphi 7 pgm 限制到公司 LAN

灯角 2024-10-27 07:26:21

尝试将 OR 部分加上括号:

SELECT * FROM ads 
WHERE ad_status='1' 
AND ( ad_region='Location One' OR
      ad_region='Location Two' OR
      ad_region='Location Three' )
AND ad_type='For Rent' 
ORDER BY ad_id 
DESC LIMIT 10 

AND 的优先级高于 OR,如图 此处 因此,您的问题中的内容相当于:

SELECT * FROM ads 
WHERE (ad_status='1' AND ad_region='Location One')
OR ad_region='Location Two'
OR (ad_region='Location Three' AND ad_type='For Rent')
ORDER BY ad_id 
DESC LIMIT 10 

这将为您提供位置 1 的所有内容,广告状态为1,加上位置 2 的所有内容以及位置 3 的所有租赁广告。

Try parenthesizing your OR section:

SELECT * FROM ads 
WHERE ad_status='1' 
AND ( ad_region='Location One' OR
      ad_region='Location Two' OR
      ad_region='Location Three' )
AND ad_type='For Rent' 
ORDER BY ad_id 
DESC LIMIT 10 

AND has a higher precedence than OR as shown here so what you have in your question is equivalent to:

SELECT * FROM ads 
WHERE (ad_status='1' AND ad_region='Location One')
OR ad_region='Location Two'
OR (ad_region='Location Three' AND ad_type='For Rent')
ORDER BY ad_id 
DESC LIMIT 10 

which will give you everything from location 1 with an ad status of 1, plus everything from location 2 plus all rental ads from location 3.

如何修复 MySQL select 语句以获得正确的结果

灯角 2024-10-27 06:59:50

这是通过 Anchor 属性完成的。在所有控件(组合框、树视图和用户控件)上正确设置它,它会按照您喜欢的方式拉伸。

Dock 属性类似,但它也会影响位置,甚至在表单设计器中也会将控件“粘合”到其位置。

This is done by the Anchor property. Set it properly on all controls (combobox, treeview and usercontrol) and it will stretch however way you like.

The Dock property is similar, but it also affects location and kinda "glues" the control to its place even in the form designer.

如何相对于彼此以及表单本身来组织表单上的控件?

灯角 2024-10-27 06:22:44

恕我直言,一个更大的问题是可用性。验证码总是会降低转化率,而且通常会显着降低。如果你的目标是使用 JS 作为阻止机器人的手段,我可​​以告诉你,它为我显着减少了 90% 以上的机器人流量。

只需合并一个由 JS 填充的隐藏字段即可。如果没有填写,他们要么是一个机器人,要么是那些关闭了 JS 的白痴之一,无论如何你都不想迎合他们。

还包含一个在 DOM 中可见的隐藏字段。使用“position:absolute; left:9999px; top:-9999px”等 CSS 让它飞离屏幕。不要使用“显示:无;”如果填写此字段,则它们是机器人。

我用它减少了 90% 以上的垃圾邮件,所以你应该使用它而不是验证码类型,除非你是一家大企业。如果您是一家大企业,那么您唯一真正的解决方案是后端服务器端解决方案。祝你好运,在 StackOverflow 上找到它。他们关闭您的评论的速度会比人们回答它的速度更快。 (而且它的 Google 排名会比其他任何东西都高)

A bigger issue is usability IMHO. Captcha is always going to decrease conversion rates, and often significantly. If your goal is to use JS as a means of deterring bots, I can tell you that it has significantly reduced bot traffic for me by more than 90%.

Just incorporate a hidden field that gets populated by JS. If it isn't filled in, they're either a bot, or one of those idiots with JS turned off, who you don't really want to cater to anyway.

Also incorporate a hidden field that is visible in the DOM. Make it fly off the screen with CSS like "position:absolute; left:9999px; top: -9999px". Don't use "display:none;" If this field is filled in, they're a bot.

I cut down our spam more than 90% with this, so you should use it over Captcha types, unless you're a big business. If you're a big business, your only real solution is a back-end server side solution. Good luck finding that on StackOverflow. They'll close your comment quicker than people can answer it. (and it will have better Google rank than anything out there)

有多少个机器人“启用”了 JS?

灯角 2024-10-27 05:20:18

我正在专门为启用了 R 的 RStudio Server 维护 AMI。详细信息请参见 http://www.louisaslett.com/RStudio_AMI/

希望有所帮助。

I'm maintaining AMIs specifically for RStudio Server which have R on. Details are at http://www.louisaslett.com/RStudio_AMI/

Hope that helps.

预安装 R 的公共 Amazon EC2 AMI

灯角 2024-10-27 01:31:42

您不需要任何 API 来播放系统声音,只需编写如下代码:

// Plays the sound associated with the Asterisk system event.
System.Media.SystemSounds.Asterisk.Play();

SystemSounds 类包含以下预定义的系统声音:

  • Asterisk
  • Beep
  • Exclamation
  • Hand
  • Question

所有其他声音都要求您从注册表中读取所需的声音并使用如下代码播放它:

SoundPlayer simpleSound = new SoundPlayer(@"c:\Path\To\Your\Wave\File.wav");

You do not require any API to play system sounds just write code like this:

// Plays the sound associated with the Asterisk system event.
System.Media.SystemSounds.Asterisk.Play();

The SystemSounds class contains the following predefined system sounds:

  • Asterisk
  • Beep
  • Exclamation
  • Hand
  • Question

All other sounds require you read the desired sound from the registry and play it with code like this:

SoundPlayer simpleSound = new SoundPlayer(@"c:\Path\To\Your\Wave\File.wav");

从 Windows 选择声音并播放它们

灯角 2024-10-26 21:37:37

所有“业务逻辑”都应该放在模型中,而不是控制器中。最近用户和帖子的查询应该在 UserPost 模型中。然后,如果您有站点范围的视图元素,请将其移至部分视图元素并将该部分视图添加到 application.html.erb 中。

# User.rb
model User
  def recent
    # logic and query here
  end
end

 

# Post.rb
(see above)

 

# application_controller.rb
before_filter :get_recent_posts
before_filter :get_recent_users
...
private
def get_recent_posts
  @recent_posts = Post.recent
end

def get_recent_users
  @recent_users = User.recent
end

 

# application.html.erb
...
<%= yield %>
...

<%= render :partial => 'layouts/footer', :locals => { :recent_users => @recent_users, :recent_posts => @recent_posts } %>

 

# layouts/_footer.html.erb
<% recent_users.each do |user| %>
  <%= link_to user.name, user %>
<% end %>

# same for posts

需要注意的一些重要事项:

  1. 不要访问部分中的实例变量(@foo)...将其传递到本地哈希中并将其作为变量访问。这通常是不好的做法

  2. 你也可以使用模块

  3. 查看缓存,因为你可能不想在每次页面加载时两次访问数据库。您可以在页脚上使用片段缓存,并每 15 分钟过期一次(可能是最好的选择)。

All "business logic" should be put in the Model, not the controller. The query for recent Users and Posts should be in the User and Post model. Then, if you have a site-wide view element, move it into a partial and add that partial into the application.html.erb.

# User.rb
model User
  def recent
    # logic and query here
  end
end

 

# Post.rb
(see above)

 

# application_controller.rb
before_filter :get_recent_posts
before_filter :get_recent_users
...
private
def get_recent_posts
  @recent_posts = Post.recent
end

def get_recent_users
  @recent_users = User.recent
end

 

# application.html.erb
...
<%= yield %>
...

<%= render :partial => 'layouts/footer', :locals => { :recent_users => @recent_users, :recent_posts => @recent_posts } %>

 

# layouts/_footer.html.erb
<% recent_users.each do |user| %>
  <%= link_to user.name, user %>
<% end %>

# same for posts

A few important things to note:

  1. don't access the instance variables (the @foo) in the partial... pass it into the locals hash and access it as a variable instead. It's just generally bad practice

  2. you could also use a module

  3. look into caching because you probably don't want to hit your database TWICE on every page load. You could use fragment caching on the footer and expire it every 15 minutes (probably the best option).

Rails 3 应用程序中站点范围的页脚逻辑属于哪里?

灯角 2024-10-26 19:39:17

i) setInterval 将每秒运行 moveElement 函数。如果是setTimeout,则只会在1秒后运行一次。

ii) 看起来这就是它的作用。

iii) 在这种情况下,x 没有在函数 moveElement 中的任何位置声明,因此它会尝试查找在顶部执行的全局变量。所以是的,它将把新值存储在函数外部的 x 中。

i) the setInterval will run the moveElement function every second. if it were setTimeout it would only run it once after 1 second.

ii) seems like thats what it does.

iii) in this case x is not declared anywhere in the function moveElement so then it tries to find a global variable which it does at the top. So yes it will store the new value in the x outside of the function.

JavaScript 设置间隔

灯角 2024-10-26 18:36:58

在 Cygwin 中,您可以尝试 gem list --all -d | grep --before-context=1 --after-context=4 平台。

In Cygwin you could try gem list --all -d | grep --before-context=1 --after-context=4 Platform.

如何获取已安装且具有本机扩展的 gem 列表?

更多

推荐作者

马化腾

文章 0 评论 0

thousandcents

文章 0 评论 0

辰『辰』

文章 0 评论 0

ailin001

文章 0 评论 0

冷情妓

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文