instruction
stringlengths
0
30k
|sockets|multithreading|udp|tcp|
I am looking for any strategies people use when implementing server applications that service client TCP (or UDP) requests: design patterns, implementation techniques, best practices, etc. Let's assume for the purposes of this question that the requests are relatively long-lived (several minutes) and that the traffi...
|sockets|multithreading|tcp|udp|
Developers don't **need** to know Expression at all. What you **do** need to know is XAML and not hide behind some tool, which would be the worst thing you could do as a WPF developer. Your tool of choice is yours to decide on. I used to use the XML editor in Visual Studio. The only persons who **need** to know B...
Enhancing the web user experience for the vision impaired
|accessibility|section508|
I was listening to a [recent episode of Hanselminutes][1] where Scott Hanselman was discussing accessibility in web applications and it got me thinking about accessibility in my own applications. We all understand the importance of semantic markup in our web applications as it relates to accessibility but what about...
Reuse shouldn't be a goal of OOP - or any other paradigm for that matter. Reuse is a side-effect of an good design and proper level of abstraction. Code achieves reuse by doing something useful, but not doing so much as to make it inflexible. It does not matter whether the code is OO or not - we reuse what works a...
Here's a Gutmann erasing implementation I put together. It uses the cryptographic random number generator to produce a strong block of random data. private static void DeleteGuttman(string fileName) { FileInfo fi = new FileInfo(fileName); if (fi.Exists) { byte[][] ...
you could do something basic like this. $safe_variable = mysql_real_escape_string($_POST["user-input"]); mysql_query("INSERT INTO table (column) VALUES ('" . $safe_variable . "')"); this won't solve every problem but its a very good stepping stone. i left out obvious items such as checking the vari...
"cut and paste with minor tweaks here and there" is the kind of code repetition I usually solve with an entirely non-exotic approach- Take the similar chunk of code, extract it out to a seperate method. The little bit that is different in every instance of that block of code, change that to a parameter. There's al...
Depending on the functionality of the command line program you want to run, it might be possible to duplicate the functionality in PowerShell, where you can embed the PowerShell runtime in your .NET application.
See this: [Guttman's paper][1] [1]: http://www.cs.auckland.ac.nz/~pgut001/pubs/secure_del.html
Xdebug profile is definitely the way to go. Another tip - WincacheGrind is good, but not been updated recently. http://code.google.com/p/webgrind/ - in a browser may be an easy and quick alternative. Chances are though, it's still the database anyway. Check for relevant indexes - and that it has sufficient memory...
Simple caching of pages, or parts of pages - the Pear::CacheLite class. I also use APC and memcache for different things, but the other answers I've seen so far are more for more complete, and complex systems. If you just need to save some effort rebuilding a part of a page - Cache_lite with a file-backed store is en...
Multiple permission types (roles) stored in database as single decimal
You have to write applications in a different way: one which makes them testable. You'd be surprised how difficult this is at first. Some people find the concept of thinking about what they're going to write before they write it too hard. Concepts such as mocking can be difficult for some too. TDD in legacy apps ...
I assume by emacs you are meaning Emacs under X (ie not inside a terminal window). There are two ways: 1. (Applies to unix OS's only) Highlight the desired text with your mouse (this copies it to the X clipboard) and then middle click to paste. 2. Highlight the desired text and then "M-x cl...
In this situation, you generally have two options: optimize the code or rewrite the compiler. I can't see where breaking the link between source and op is ever going to be the correct solution.
leaving a time delay in python
|python|timedelay|
is there any way to leave a time delay between the execution of two lines of code?
Game programming in Java?
|java|
What are the best practices for programming commerical games in Java? What libraries should be used? Are there any succesfull commercial games projects in Java?
I am looking into game programming in Java to see if it is feasible. When googling for it I find several old references to Java2D, Project Darkstar (Sun's MMO-server) and some books on Java game programming. But alot of the information seems to be several years old. So the question I am asking, is anyone creating an...
[Pyro][1] (Python Remote Objects) is fairly clever if all your server/clients are going to be in Python. I use [XMPP][2] alot though since I'm communicating with hosts that are not always Python. XMPP lends itself to being extended fairly easily too. There is an excellent XMPP library for python called [PyXMPP][3] w...
Write webservice in Java and access it in .net
OK, if you're under X11 and you want to get the kbd, you need to do a grab. If you're not, my only good answer is ncurses from a terminal. Here's how you grab everything from the keyboard and release again: <pre> /* Demo code, needs more error checking, compile * with "gcc nameofthisfile.c -lX11". /* weird f...
OK, if you're under X11 and you want to get the kbd, you need to do a grab. If you're not, my only good answer is ncurses from a terminal. Here's how you grab everything from the keyboard and release again: <pre> /* Demo code, needs more error checking, compile * with "gcc nameofthisfile.c -lX11". /* weird f...
This may not be the best solution but you could set a global boolean variable that would be accessible to both methods that would just specify if the last action was HoverIn or HoverOut. You could use this boolean variable to determine if the code should run or not. if (bWasHoverIn){ ... }
[Sourcegear Vault][1] is free for a single user and you can run both the client and the server on your own machine. [1]: http://sourcegear.com/vault/index.html
I don't think that exists any efective offline antipiracy method. The videogame industry has tried to found that many times and they programs has allways been cracked. The only solution is the program must be runned online connected with your servers, so that you can verify the lincense key, and that there is only one ...
Part of the point of being "test infected" is that you've used TDD enough and seen the successes enough that **you don't want to code without it**. Once you've gone through a cycle of writing tests first, then coding and refactoring and seeing your bug counts go down and your code get better as a result, not only does ...
Part of the point of being "test infected" is that you've used TDD enough and seen the successes enough that **you don't want to code without it**. Once you've gone through a cycle of writing tests first, then coding and refactoring and seeing your bug counts go down and your code get better as a result, not only does ...
What we've done that really improves our efficiency and quality is to multi target our mobile application. That is to say with a very little bit of creativity and a few conditional compile tags and custom project configurations it is possible to build a version of your mobile application that also runs on the desktop....
Prototype 1.6 provides the ["dom:loaded"](http://prototypejs.org/api/document/observe) event on document: document.observe("dom:loaded", function() { $$('a').each(function(elem) { elem.observe("click", function() { alert("Hello World"); }); }); }); I also use the [each](htt...
C and C++ arrays are not first class objects; you cannot pass arrays to functions, they always decay to pointers. You can, however, pass pointers and references to arrays. This prevents the array bounds from decaying. So this is legal: template<typename T, size_t N> void foo(const T(&arr)[N]) { ...
C++ Exception code lookup
|c++|exception|visual-c++|crash|memory-dump|
Knowing an exception code, is there a way to find out more about what the actual exception that was thrown means? My exception in question: 0x64487347 Exception address: 0x1 The call stack shows no information. I'm reviewing a .dmp of a crash and not actually debugging in Visual Studio.
Biggest problem with screen readers is usually tables to position things on your page. Screenreaders can't really handle those. Put stuff in div's in your html and put them in a sensible order. Then position the div's on your page with css. Use tables to display content that should be in a table.
How do I make a subproject with Qt?
|project-management|qt|
I'm about to start on a large Qt application, which is made up of smaller components (groups of classes that work together). For example, there might be a dialog that is used in the project, but should be developed on its own before being integrated into the project. Instead of working on it in another folder somewhere...
In general, I think it's more important to for developers to understand XAML, as Blend is just a view on top of it. XAMLPad may be more useful for learning XAML in the first instance. More specifically to this question though, I think if developers are working alongside designers using Blend, it could be very useful...
CSS may not be a religion, but it is how browsers interpret HTML for layout. Like it or not, all modern browsers use (some version) of the W3C box model. To continue to rely on tables is continue to rely on a methodology that is just plain wrong in the eyes of the people who design web rendering technology. I know C...
|database|permissions|roles|user|
|database|permissions|user|roles|
I was going to ask a question here about whether or not my design for some users/roles database tables was acceptable, but after some research I came across this question: [What is the best way to handle multiple permission types?][1] [1]: /questions/1451/what-is-the-best-way-to-handle-multiple-permission-types...
I was going to ask a question here about whether or not my design for some users/roles database tables was acceptable, but after some research I came across this question: [What is the best way to handle multiple permission types?][1] [1]: /questions/1451/what-is-the-best-way-to-handle-multiple-permission-types...
Once you know the sql statements involved, a code analysis will surely help. Some thumb rules are checking for the order in which the rows are accessed and checking for the isolation level used for the SQL statements. A profiler trace can help a lot. Most of the time, it is because of a reader trying to get a shared...
Best tool for synchronizing MySQL databases
|mysql|synchronization|
I'm on a little quest of merging the structure of two MySql databases. Is there a tool for this with the might of Red-Gate's SQL Compare? Are there any free alternatives?
Jason's advise is right on. The best speedups you are going to get come from 'discovering' that you let an O(n^2) algorithm slip into an inner loop somewhere, or that you can cache certain computations outside of expensive functions. Compared to the micro-optimizations that PGO can trigger, these are the big winner...
The only place I've seen it being useful is when you write a funky loop where you want to do multiple things in one of the expressions (probably the init expression or loop expression. Something like: bool arraysAreMirrored(int a1[], int a2[], size_t size) { size_t i1, i2; for(i1 = 0, i1 = siz...
ASP.Net word count with a custom validator
|asp.net|vb.net|.net-2.0|validation|
A requirement for an ASP.Net 2.0 project I'm working on limits a certain field to a max of 10 words (not characters). I'm currently using a CustomValidator control with the following ServerValidate method: Protected Sub TenWordsTextBoxValidator_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.W...
I'm trying to get more feedback on my own projects, so I'll suggest my take on ORM: [ORMer][1] Usage examples are [here][2] You can phase it in, it doesn't require you to adopt MVC, and it requires very little setup. [1]: http://greaterscope.net/projects/ORMer [2]: http://greaterscope.net/projects/ORMer/...
Scaffolding is the normal way to create an admin backend BUT there is a project called [ActiveScaffold][1] which may solve your problem. [1]: http://www.activescaffold.com/
1. **Don't write ginormous tests.** As the 'unit' in 'unit test' suggests, make each one as *atomic* and *isolated* as possible. If you must, create preconditions using mock objects, rather than recreating too much of the typical user environment manually. 2. **Don't test things that obviously work.** Avoid testing th...
@Wayne Kao - IE6 has no problem reading more than one class name on an element, and applying styles that belong to each class. What the article is referring to is creating new styles based on the combination of class names. <div class="bold italic">content</div> .bold { font-weight: 800; }...
What you're after is delineation of the behaviours of the class under test. 1. Verification of expected behaviours. 2. Verification of error cases. 3. Coverage of all code paths within the class. 4. Exercising all member functions within the class. The basic intent is increase your confidence in the behavi...
Test should originally fail. Then you should write the code that makes them pass, otherwise you run the risk of writing a test that is bugged and always passes.
- Unit Testing just tests the external API of your Unit, you shouldn't test internal behaviour. - Each test of a TestCase should test one (and only one) method inside this API. - Aditional Test Cases should be included for failure cases. - Test the coverage of your tests: Once a unit it's tested, the 100% o...
Yes... I think some components wont work with that code. Some of them require to live in a thread that has an Application.Run in it to effectively pick up their messages.
I've started with solving your problem literally, (defun search-maker (s) `(lambda () (interactive) (let ((regexp-search-ring (cons ,s regexp-search-ring)) ;add regexp to history (isearch-mode-map (copy-keymap isearch-mode-map))) (define-key isearch-mode-map...
Replacements for switch statement in python?
|python|switch-statement|
I want to write a function in python that returns different fixed values based on the value of an input index. In other languages I would use a switch or case statement, but python does not appear to have a switch statement. What are the recommended python solutions in this scenario?
Two gross options, but they don't requiring copying the whole set: for e in s: break # e is now an element from s Or... e = s.__iter__().next() But in general, sets don't support indexing or slicing.
Two gross options, but they don't requiring copying the whole set: for e in s: break # e is now an element from s Or... e = iter(s).next() # was s.__iter__(s).next() # - thanks to J.F. Sebastian for better syntax! But in general, sets don't support indexing or ...
You could use a dictionary: def f(x): return { 'a': 1, 'b': 2, }[x]
Why won't my local Apache open html pages?
|apache|
so, I'm running Apache on my laptop. If I go to "localhost", I get the page that says, > If you can see this, it means that the installation of the Apache web server software on this system was successful. You may now add content to this directory and replace this page. except, I can't add content and replace...
I like to use [Google Code][1], even for my one man projects, as it provides a Subversion repository already set up. Also, the server is offsite, which protects against hard drive failures and other disasters. [1]: http://code.google.com/
I'm very much in agreement with Jeff Atwood on the "Stored Procedures vs. Inline SQL/LINQ" issue: [Who Needs Stored Procedures, Anyways?][1]. I'm confused as to why you'd even want to perform a JOIN if you're in the SPROCs-for-everything crowd; shouldn't you wrap that JOIN up into another SPROC? As Will said, LI...
I know the original question specified HTML + CSS, but it didn't specifically say *no javascript* ;) Trying to keep the css and markup as clean as possible, and as semantically meaningful as possible to (using a UL for the menu) I came up with this suggestion. Probably not ideal, but it may be a good starting point:...
@gorgapor: Doesn't the Google Code TOS specify an open source license? It's not a generally applicable solution in that case.
I'm doing something similar to you. My solution was to route all calls through an STA thread queue. I used a threadsafe collection from the new [parallel framework][1] to queue up Actions I wanted to run on a STA thread. I then had X number of STA threads that continually checked the queue for new actions to execu...
I'll assume you know the difference between a List, Set and Map. Why you would choose between their implementing classes is another thing. For example: **ArrayList** is quick on retrieving, but slow on inserting. It's good for an implementation that reads a lot but doesn't insert a lot. It keeps its data in one cont...
Inserting at the very end in FCKeditor
|fckeditor|plugins|
FCKeditor has InsertHtml ([JavaScript API document](http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/JavaScript_API)) that inserts HTML in the current cursor position. How do I insert at the very end of the document? Do I need to start browser sniffing with something like this if ( element.insertAdjac...
|javascript|plugins|dom|fckeditor|
|javascript|dom|plugins|fckeditor|
FCKeditor has InsertHtml API ([JavaScript API document](http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/JavaScript_API)) that inserts HTML in the current cursor position. How do I insert at the very end of the document? Do I need to start browser sniffing with something like this if ( element.insertA...
How do I make a ListBox refresh its item text?
|.net|winforms|user-interface|
I'm making an example for someone who hasn't yet realized that controls like <code>ListBox</code> don't have to contain strings; he had been storing formatted strings and jumping through complicated parsing hoops to get the data back out of the <code>ListBox</code> and I'd like to show him there's a better way. I no...
Arrays. Judging from the answers to this question I don't think people fully appreciate just how easy and useful Arrays in PHP are. PHP Arrays act as lists, maps, stacks and generic data structures all at the same time. Arrays are implemented in the language core and are used all over the place which results in good CP...
You may be looking for an automated tool that will automatically generate a lot of stuff for you. But here's a free, generally powerful diagramming tool useful not only for UML but for all kinds of diagramming tasks. It accepts as input and outputs to a wide variety of commonly used file formats. It's called yEd, and i...
A .NET dll can be best called from any other programming language by exposing it as a COM object. Take a look at this example: http://support.microsoft.com/kb/828736. This shows how to call a ".NET dll" from "unmanaged C++". You can replace the "unamanged C++" by any other programming language, that can be used as a CO...
If your tests are not very thorough you might fall into a false sense of "everything works" just because you tests pass. Theoretically if your tests pass, the code is working; but if we could write code perfectly the first time we wouldn't need tests. The moral here is to make sure to do a sanity check on your own befo...
Personally, I prefer [WinUnit][1] since it doesn't require me to [write anything except for my tests][2] (I build a .dll as the test, not an exe). I just build a project, and point WinUnit.exe to my test output directory and it runs everything it finds. You can [download the WinUnit project here][3]. (MSDN now requir...
Using a standard type of web service (e.g. SOAP or XML-RPC) is best because not only is it easy to produce/consume, it's easy in other languages as well.
You can use the sleep() function in the time module. It can take a float argument for sub second resolution. from time import sleep sleep(0.1) # Time in seconds.