coding-style

setTimeout() with string or (anonymous) function reference? speedwise

落花浮王杯 提交于 2019-12-28 02:55:13
问题 Which one of these two ways is faster and why? window.setTimeout("func()", 100); Or window.setTimeout(function(){func();}, 100); I'm guessing the second way is faster if for no other reason other than John Resig and all the ninjas use it, I'm guessing because it already parsed as opposed to the first way which it would have to create a new parsing "thingie". I vaguely recall this being one of the reasons people don't like eval(). Also while I have you here, in the second code snipplet, is the

When to use each method of launching a subprocess in Ruby

ε祈祈猫儿з 提交于 2019-12-28 02:26:09
问题 1. `` The Backtick defined in Kernel 1. a) %x{} Percent X < alternate syntax for The Backtick defined in parse.y, see discussion 2. system() Kernel#system 3. fork() Kernel#fork, Process#fork 4. open() open a pipe Kernel#open 4.a. IO.popen() < behaves the same as open() open a pipe IO#popen 4.b. open("|-") fork to a pipe 4.c. IO.popen("-") < behaves the same as open("|-") fork to a pipe see discussion 5. Open3.popen3() require 'open3' stdlib Open3 6. PTY.spawn() require 'pty' stdlib PTY 7.

Javascript document write overwriting page?

雨燕双飞 提交于 2019-12-28 01:34:31
问题 I'm very new with javascript. I'm trying to create a tag using document.write (with Wordpress) to add a style that hides images before they are preloaded. I've had to resort to writing a Javascript style to hide the images before they are loaded via CSS. I don't want to actually write it into the CSS file incase the user has Javascript disabled and then the images would never show. I'm trying to get this code to work: jQuery(function($) { document.write('<style type="text/css"> .preload img {

Opaque C structs: how should they be declared?

吃可爱长大的小学妹 提交于 2019-12-27 11:42:26
问题 I've seen both of the following two styles of declaring opaque types in C APIs. Is there any clear advantage to using one style over the other? Option 1 // foo.h typedef struct foo * fooRef; void doStuff(fooRef f); // foo.c struct foo { int x; int y; }; Option 2 // foo.h typedef struct _foo foo; void doStuff(foo *f); // foo.c struct _foo { int x; int y; }; 回答1: My vote is for the third option that mouviciel posted then deleted: I have seen a third way: // foo.h struct foo; void doStuff(struct

How can I set multiple CSS styles in JavaScript?

早过忘川 提交于 2019-12-27 10:50:44
问题 I have the following JavaScript variables: var fontsize = "12px" var left= "200px" var top= "100px" I know that I can set them to my element iteratively like this: document.getElementById("myElement").style.top=top document.getElementById("myElement").style.left=left Is it possible to set them all together at once, something like this? document.getElementById("myElement").style = allMyStyle 回答1: If you have the CSS values as string and there is no other CSS already set for the element (or you

Where are detailed the rules, concepts and usages behind each pylint's warnings?

北城余情 提交于 2019-12-25 18:19:51
问题 I am still discovering Pylint and I understand why many Pythonists deactivate some (or many) warnings to lower Pylint 's voice, but for the moment, as a Python newbie I want to use pylint to improve my Pythonic comprehension and my code quality , in order to help me to: learning more from a statement/instruction deepen some concepts evaluate the benefits / drawback of a refactoring etc. So is there a place where all the warning are discussed, justified, explained or they simply came from the

Android SeekBar [ProgressBar] style - how to set custom background drawable

你离开我真会死。 提交于 2019-12-25 11:48:08
问题 I want to make seekbar like this: http://img687.imageshack.us/img687/2371/volumec.png The thing is, that I ve already found customizing seekbars over here http://groups.google.com/group/android-developers/browse _thread/thread/be3fed0b4f766cc?pli=1 but the problem is, that I need **those gaps** between in my drawable and I don t know how to manage that. Would you be so kind some of you, I`ll appreciate it very much. Thanks in advance, wishing all the best! this is my resources style.xml file

Silverlight Datagrid: Highlight an entire Column?

天大地大妈咪最大 提交于 2019-12-25 04:49:06
问题 I have a DataGrid in my Silverlight application, and would like to "highlight" an entire column when any cell in that column is selected. E.g., given this grid (where " [ ] " represents a cell): [ ][ ][ ] [ ][ ][ ] [ ][ ][ ] If I select a cell, like this [ ][ selected ][ ] [ ][ ][ ] [ ][ ][ ] I would like all the cells in that column, including the selected cell, to be "highlighted" (can be as simple as just changing the background color): [ ][ selected ][ ] [ ][ highlighted ][ ] [ ][

standard Xhtml- div vs li

我与影子孤独终老i 提交于 2019-12-25 00:34:42
问题 I need ur suggestion in the following scenario. Lets say I have an UI something like Col1 Col2 A D B E C F Now to get this right now in my HTML I am using ..like <div class="col1"> <div>A</div> <div>B</div> .......... </div> <div class="col2"> <div>D</div> <div>E</div> .......... </div> But here I am using too much div..is it OK as per standard XHTML or should I use <li> ? Can somebody suggest with proper explanation, or maybe something else? Note: No use of Table Thanks. 回答1: It looks to me

Simplifying PHP forms that pre-populate with dabase data and error check, so actively overwrite with $_POST data

不问归期 提交于 2019-12-24 12:56:27
问题 Ok, so this is a common scenario. You have an html form that involves editing information. The original information comes from the database. When you post the form, it may not save the information immediately, because something may need fixing when the data-checking is done, maybe one of the required fields is left blank. As a result, you want to redisplay the form field, but if there was post data, display the post data, if not, display the original data from the database. So I created a