instruction
stringlengths
0
30k
Function call is actually a copy of parameters onto the stack (multiple memory access), register save, the actual code execution, and finally result copy and and registers restore (the registers save/restore depend on the system). So.. speaking relatively: - Function call > Simple memory access. - Function c...
Your code is valid - it should work fine. Go in to the property pages of your project and make sure that the "Target Framework" is .NET 3.0 or 3.5.
I think David and Cervo combined have hit on the problem here. I'm pretty sure part of what was happening was that we were using #newMatches in multiple triggers. When one trigger changed some rows, it would fire another trigger, which would attempt to use the connection scoped #newMatches. As a result, it would ...
When I have this scenario I create a structure for my fields that I stuff into Viewstate. I'm okay with having a small structure added into the page size and lifecycle considering the entire page's controls set is there already :) Furthermore it cleans up after itself after you're done with the page, so there's no ...
GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment() .getScreenDevices(); for (int i = 0; i < devices.length; i++) { GraphicsDevice dev = devices[i]; System.out.println("device " + i); DisplayMode[] modes = dev.getDisplayModes(); for (int j = 0; j < modes.length; j++) { ...
GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment() .getScreenDevices(); for (int i = 0; i < devices.length; i++) { GraphicsDevice dev = devices[i]; System.out.println("device " + i); DisplayMode[] modes = dev.getDisplayModes(); for (int j = 0; j < modes.length; j++) { ...
Sounds like a good approach to me (sorry don't know mysql, but in oracle you could set a trigger so that when your main column is updated the "length" column gets automatically updated)
I once learned that a table loads at once, in other words when a connection is slow, the space where the table comes remains blank until the entire table is loaded, a div on the other hand loads top to bottom as fast as the data comes and regardless if it is allready complete or not.
how about: drop table if not exists fubar; create table fubar; Or did you mean you just want to do it with a single query?
classes are great when you want to apply similar styles to many different divs or elements. ids are good when you want to address a specific element for formatting or for updating with javascript.
Your users have lots of needs that aren't taken care of. They are suffering. They need attention, and they need *you*. I think feature creep is something that happens when you don't implement *the right features* already. - Cultivate a close relationship with your users. Let them know you are always interested i...
jQuery attribute selectors: How to query for an attribute with a custom namespace
|javascript|jquery|
Suppose I have a simple XHTML document that uses a custom namespace for attributes: <html xmlns="..." custom:xmlns="http://www.example.com/ns"> ... <div class="foo" custom:attr="bla"/> ... </html> How do I select that custom attribute using jQuery? Using $("div[custom:at...
Suppose I have a simple XHTML document that uses a custom namespace for attributes: <html xmlns="..." custom:xmlns="http://www.example.com/ns"> ... <div class="foo" custom:attr="bla"/> ... </html> How do I match each element that has a certain custom attribute using jQuery? Usi...
Background color of a ListBox item (winforms)
|c#|winforms|listbox|colors|
How can I set the background color of a specific item in a System.Windows.Forms.ListBox? I would like to be able to set multiple ones if possible.
Clustered indexes physically order the data on the disk. This means no extra data is needed for the index, but there can be only one clustered index (obviously). Accessing data using a clustered index is fastest. All other indexes must be non-clustered. A non-clustered index has a duplicate of the data from the inde...
**Php** doesn't do much forward checking of things at parse time. The best you can do is crank up the warning level to report your mistakes and by then its usually too late anyhow. This gem turned up on the php-dev mailing-list this week and I think its just the tool you want. Its more a lint-checker, but it add...
**Php** doesn't do much forward checking of things at parse time. The best you can do is crank up the warning level to report your mistakes, but by the time you get an E\_NOTICE, its too late, and its not possible to force E_NOTICES to occur in advance yet. A lot of people are toting the "error\_reporting E_STRI...
When I want the operator == and Foo.Equals(object obj) to return the same answer, I usually implement the != operator like this: public static bool operator ==(Foo foo1, Foo foo2) { return object.Equals(foo1, foo2); } public static bool operator !=(Foo foo1, Foo foo2) { return !object.Equals(foo1, foo2); } ...
Two small additional points. First, `self.__class__.l.append(1)` isn't really sensible. Just say `self.l.append(1)`. Python searches the instance before it searches the class for the reference. More importantly, class-level variables are rarely useful. Class-level constants are sometimes sensible, but even t...
Assign the new Thread to a local field? class YourClass { Thread thread; void Start() { thread = new Thread(Foo); thread.Start(); GC.Collect(); } } Garbage Collection collects everyting that is not references, so in your code there is no f...
Interesting idea; the closest thing I have heard of is [todo.txt][1]. Alternatively, you could roll your own by just using a database (e.g. sqllite) and SQL. Optionally, write a wrapper script that parses your plain-text file and command-line options, and generates the corresponding SQL. [1]: http://todotxt.c...
If you're on linux then you can grab the guest processes with ps axuw | grep vmware-vmx Not sure how you go from here to work out which pid relates to you errant guest.
You have a lovely property on the Type class called IsSerializable.
The runtime keeps a reference to the thread as long as ist ist running. The GC wont collect it as long as anyone still keeps that reference.
@Thevs I think you were on the right track. What I did was override the initList method of Combobox. Ext.override(Ext.form.ComboBox, { initList : function(){ If you look at the code you can see the bit where it renders the list of suggestions to a dataview. So just set the apply to the dom...
You'll have to figure out what level of error you're willing to accept. Not all decimal fractions will reduce to a simple fraction. I'd probably pick an easily-divisible number, like 60, and figure out how many 60ths is closest to the value, then simplify the fraction.
The key thing here is this: javax.servlet.jsp.jstl.sql.Result That's what JSTL uses as the result of a SQL Query. If you look at the interface, it has this method: public java.util.SortedMap[] getRows() c:forEach "knows" about javax.servlet.jsp.jstl.sql.Result, since Result isn't anything else that forEach kn...
Often, dynamc languages (especially python and lua) are embedded in programs to add a more plugin-like functionality and because they are high-level languages that make it easy to add certain behavior, where a low/mid-level language is not needed. Lua specificially lacks all the low-level system calls because it was...
IDs should be unique. CLASSes should be shared. So, if you have some CSS formatting that will be applied to multiple DIV, use a class. If just one (as a requirement, not as happenstance), use an ID.
Tools that use table layouts can become extraordinarily heavy due to the amount of code required to create the layout. SAP's Netweaver Portal by default uses TABLE to layout their pages. The current production SAP portal at my current gig's HTML weighs over 60K and goes seven tables deep, three times within the page...
Tools that use table layouts can become extraordinarily heavy due to the amount of code required to create the layout. SAP's Netweaver Portal by default uses TABLE to layout their pages. The production SAP portal at my current gig has a home page whose HTML weighs over 60K and goes seven tables deep, three times wit...
While(this.Opacity !=0) { this.Opacity -= 5; Thread.Sleep(50);//This is for the speed of the opacity... and will let the form redraw }
While(this.Opacity !=0) { this.Opacity -= 0.5; Thread.Sleep(50);//This is for the speed of the opacity... and will let the form redraw }
With thanks to Zárate, it looks like JSFL is the answer, or at least part of it. I can't get flash to run external scripts, but I *can* get external scripts to run flash; so I have two scripts now; build.bat and build.jsfl build.bat: subwcrev . Version.svn.as Version.as IF ERRORLEVEL 1 EXIT /B $ErrLev ...
With thanks to Zárate, it looks like JSFL is the answer, or at least part of it. I can't get flash to run external scripts, but I *can* get external scripts to run flash; so I have two scripts now; build.bat and build.jsfl build.bat: subwcrev . Version.svn.as Version.as IF ERRORLEVEL 1 EXIT /B $ErrLev ...
How about first getting rid of that global variable $account. You are basically setting yourself up for some serious bugs by using a global. Just use an instance variable instead @ or better yet create a method on ApplicationController called current_account which access the @current_account instance variable.
Append Subject Header in Outlook (VBA)
|outlook|vba|subject|append|change|
Basically, we have a rule setup to run a script when a code word is detected in the body of an incoming message. The script will append the current subject header with a word in front. For example, Before: "Test Message", After: "Dept - Test Message". Any ideas?
|outlook|vba|mail-header|
|vba|outlook|
I was quite surprised to learn that you could use the bisect module to do a very fast binary search in a sequence. It's documentation doesn't say anything about it: > This module provides support for maintaining a list in sorted order without having to sort the list after each insertion. The usage is very simple:...
A non-JIT compiler takes source code and transforms it into machine specific byte code at compile time. A JIT compiler takes machine agnostic byte code that was generated at compile time and transforms it into machine specific byte code at run time. The JIT compiler that Java uses is what allows a single binary to run ...
While this is a very complicated question to answer, I have a few quick-bite things I think about when considering implementing state. * Query string state is only useful for the most basic tasks -- e.g., maintaining the position of a user within a wizard, perhaps, or providing a path to redirect the user to after t...
Clustered Index - Only one per table - Faster to read than non clustered as data is physically stored in index order Non Clustered Index - Can be used many times per table - Quicker for insert and update operations than a clustered index Both types of index will improve performance when select dat...
Clustered Index - Only one per table - Faster to read than non clustered as data is physically stored in index order Non Clustered Index - Can be used many times per table - Quicker for insert and update operations than a clustered index Both types of index will improve performance when select dat...
As mentioned, if you want a “per-branch stash,” you really want a new branch forking off from the existing branch. Also, besides the already mentioned fact that the stash allows you to pull into a branch that you’re working on, it also allows you to *switch* branches before you have committed everything. This is use...
Karl Seguin has a [good blog][1] post about sharding. From the post: > Sharding is the separation of your > data across multiple servers. How you > separate your data is up to you, but > generally it’s done on some > fundamental identifier. [1]: http://codebetter.com/blogs/karlseguin/archive/2008/06/30...
This is how I would do it: ExternalInterface.call("document.title = 'Hello World'"); Or more generalized: function setPageTitle( newTitle : String ) : void { var jsCode : String = "function( title ) { document.title = title; }"; ExternalInterface.call(jsCode, newTitle); }
Rene, please [read my answer][1] to "Best Practices for Architecting Large Systems in a Dynamic Language" question here on StackOverflow. I discuss some benefits of giving away the freedom of dynamic languages to save development effort and to ease introducing new programmers to the project. Interfaces, when used prope...
If you want to de-normalize the table, simply add the LeadSource (Varchar) column to your SalesLead table, instead of using a FK or an ID. On the other hand, if your language has support for ENUM structures, the "magic numbers" should be safely stored in an enum, so you could: SELECT * FROM SALESLEAD WHERE L...
If you want to de-normalize the table, simply add the LeadSource (Varchar) column to your SalesLead table, instead of using a FK or an ID. On the other hand, if your language has support for ENUM structures, the "magic numbers" should be safely stored in an enum, so you could: SELECT * FROM SALESLEAD WHERE L...
I'd use Apache Collections Lazy Map (to initialize values to 0) and use MutableIntegers from Apache Lang as values in that map. Biggest cost is having to serach the map twice in your method. In mine you have to do it just once. Just get the value (it will get initialized if absent) and increment it.
SELECT * FROM Items WHERE col LIKE '%foo%' OR col LIKE '%bar%' ORDER BY CASE WHEN col LIKE '%foo%' THEN 1 WHEN col LIKE '%bar%' THEN 2 END
There is no such folder. But you can create one. There is CSIDL_COMMON_APPDATA which in Vista maps to %ProgramData% (c:\ProgramData) and in XP maps to c:\Documents and Settings\AllUsers\Application Data Feel free to create a folder there in your installer and set the ACL so that everyone can write to that fold...
If it's a style you want to use in multiple places on a page, use a class. If you want a lot of customization for a single object, say a nav bar on the side of the page, then an id is best, because you're not likely to need that combination of styles anywhere else.
When I first learned Python, I worked for a Java shop. Occasionally I'd have to do serious text-processing tasks which were much easier to do with quick Python scripts than Java programs. For example, if I had to parse a complex CSV file and figure out which of its rows corresponded to rows in our Oracle database, th...
IDs must be unique but in CSS they also take priority when figuring out which of two conflicting instructions to follow. <div id="section" class="section">Text</div> #section {font-color:#fff} .section {font-color:#000} The text would be white.
**iTextSharp** is the best bet. Used it to make a spider for lucene.Net so that it could crawl PDF. using System; using System.IO; using iTextSharp.text.pdf; using System.Text.RegularExpressions; namespace Spider.Utils { /// <summary> /// Parses a PDF file and ext...
id is supposed to be the element unique identifier on the page, which helps to manipulate it. Any externally CSS defined style that is supposed to be used in more than one element should go on the class attribute <div class="code-formatting-style-name" id="myfirstDivForCode"> </div>
Use an id for a unique element on the page which you want to do something very specific with, and a class for something which you could reuse on other parts of the page.
check out the answers to this thead: http://stackoverflow.com/questions/76364/what-is-the-single-most-effective-thing-you-did-to-improve-your-programming-ski#84112 Learning new languages is about keeping an open mind and learning new ways of doing things.
Use `id` to identify elements that there will only be a single instance of on a page. For instance, if you have a single navigation bar that you are placing in a specific location, use `id="navigation"`. Use `class` to group elements that all behave a certain way. For instance, if you want your company name to appe...
perldoc perltoc is a bit more verbose about the various documentation files. If you want a list of core modules, try perldoc perlmodlib
It is possible to do as you request see the code below. // Construct an array containing ints that has a length of 10 and a lower bound of 1 Array lowerBoundArray = Array.CreateInstance(typeof(int), new int[1] { 10 }, new int[1] { 1 }); // insert 1 into position 1 lowerBoundArray.SetValue(1, 1); //insert 2...
I would recommend looking into [Apache Velocity][1]. It is quite simple and lightweight. We are currently using it for our e-mail templates, and it works very well. [1]: http://velocity.apache.org/
In brief, imagine seperating your users_tbl across several servers. So Users 1-5000 and on Server 1, Users 5000-10000 on Server 2; etc. If your data model is sufficiently abstract in code, it's often not a huge change in code. Of course this approach becomes difficult if all your queries are similar to "SELECT C...
Probably the only way to accomplish that is to draw the items yourself. Set the `DrawMode` to `OwnerDrawFixed` and code something like this on the DrawItem event: private void listBox_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); Graphics g = e.Graphics; ...
<xsl:template match="row"> <row A="{@A}" X="{@X}" /> <row A="{@A}" Y="{@Y}" /> <row A="{@A}" Z="{@Z}" /> </xsl:template> Plus obvious boilerplate.
<xsl:template match="row"> <row A="{$A}" X="{$X}" /> <row A="{$A}" Y="{$Y}" /> <row A="{$A}" Z="{$Z}" /> </xsl:template> Plus obvious boilerplate.
You'll probably need to use strcmp to see if the string is already stored: for (int index=0; index<=lastIndex; index++) { if (strcmp(registeredNames[index], name) == 0) { return; // Already registered } } Then if you really need to store a copy of the string, then you'l...
Avoid hanging when closing a Yahoo map with lots of markers
|yui|maps|javascript|yahoo-maps|yahoo|
I have a Yahoo map with lots of markers (~500). The map performs well enough until I close the page, at which point it pauses (in Firefox) and brings up a "Stop running this script?" dialog (in IE7). If given long enough the script does complete its work. Is there anything I can do to reduce this delay? This stri...
It's not some much a question of what to use & what to avoid, but when to use which. Each has a particular circumstances when it is the best, and a different circumstance when it's the worst. The deciding factor is generally lifetime of the data. Session state lives longer than form fields, and so on.
Sub AppendSubject(MyMail As MailItem) Dim strID As String Dim mailNS As Outlook.NameSpace Dim mailItem As Outlook.MailItem strID = MyMail.EntryID Set mailNS = Application.GetNamespace("MAPI") Set mailItem = mailNS.GetItemFromID(strID) mailItem.Sub...
Only memory access is faster than a function call. But the call can be avoided if compiler with inline optimization (for GCC compiler(s) and not only it is activated when using level 3 of optimization (-O3) ).
Write the GUI output to a file that the console app checks when loading. This way your console app can do the repair operations and the normal operations in one scheduled operation.
You may want to look at the new ASP.NET MVC framework. The level of flexibility is amazing and the coding style is slightly more akin to the ASP classic approach, albeit with much better separation of church and state.
"Let's say we have 0.33, we need to output "1/3". " What precision do you expect the "solution" to have? 0.33 is not equal to 1/3. How do you recognize a "good" (easy to read) answer? No matter what, a possible algorithm could be: If you expect to find a nearest fraction in a form X/Y where Y is less then 10, ...
What is best practice for large file transfer - SFTP or assymetric file encryption?
|ftp|security|sftp|data-transfer|
Which is generally considered "best practice" when wanting to securely transmit flat files over the wire? Asymmetric encryption seems to be a pain in that you have to manage keysets at endpoints and make sure that the same algorithm is used by all clients, where as SFTP seems to be a pain because of NAT issues with en...
ditto for wireshark (the artist formerly known as Ethereal). you can sniff at every protocol layer, and stitch together traffic streams.
If you load balance your servers, you ABSOLUTELY have to make sure the machine key is the same on all the servers. Viewstate is supposed to be server agnostic, but it is not, so you'll get viewstate corruption errors if the machine key is not the same across servers. <machineKey validationKey='A130E240DF1C49E...
|javascript|maps|yui|yahoo|yahoo-maps|
I have a Yahoo map with lots of markers (~500). The map performs well enough until I close the page, at which point it pauses (in Firefox) and brings up a "Stop running this script?" dialog (in IE7). If given long enough the script does complete its work. Is there anything I can do to reduce this delay? This stri...
You have a many-to-many relationship between users and groups. This calls for a seperate table to combine users with groups: User: (UserId[PrimaryKey], UserName etc.) Group: (GroupId[PrimaryKey], GroupName etc.) UserInGroup: (UserId[ForeignKey], GroupId[ForeignKey]) To find all users in a given grou...
You have a many-to-many relationship between users and groups. This calls for a seperate table to combine users with groups: User: (UserId[PrimaryKey], UserName etc.) Group: (GroupId[PrimaryKey], GroupName etc.) UserInGroup: (UserId[ForeignKey], GroupId[ForeignKey]) To find all users in a given grou...
You have a many-to-many relationship between users and groups. This calls for a seperate table to combine users with groups: User: (UserId[PrimaryKey], UserName etc.) Group: (GroupId[PrimaryKey], GroupName etc.) UserInGroup: (UserId[ForeignKey], GroupId[ForeignKey]) To find all users in a given grou...
Writing your own parser could be fun! It might be a better option because people are expecting to use the familiar spreadsheet syntax (Excel, etc) and not Python when they're entering formulas. I'm not familiar with safe_eval but I would imagine that anything like this certainly has the potential for exploitation.
[Ross has the right idea](http://stackoverflow.com/questions/28395/passing-post-values-with-curl#28411) for POSTing the usual parameter/value format to a url. I recently ran into a situation where I needed to POST some XML as Content-Type "text/xml" without any parameter pairs so here's how you do that: $...
Should work fine. $data = array('name' => 'Ross', 'php_master' => true); $handle = curl_init($url); curl_setopt($handle, CURLOPT_POST, true); curl_setopt($handle, CURLOPT_POSTFIELDS, $data); curl_exec($handle); We have two options here, `CURLOPT_POST` which turns HTTP POST on, and `C...
Should work fine. $data = array('name' => 'Ross', 'php_master' => true); // You can POST a file by prefixing with an @ (for <input type="file"> fields) $data['file'] = '@/home/user/world.jpg'; $handle = curl_init($url); curl_setopt($handle, CURLOPT_POST, true); curl_setopt($h...
You should probably raise an exception if it gets to that last `return 0` line --when a hash collision happens. I do have a question though: you are doing a total ordering on the hash's, which I guess is fine, but shouldn't some function be passed to it to define a Lexicographical order? int h1 = System.iden...
.NET library for processing HTML e-mails & stripping