instruction
stringlengths
0
30k
Our gracious host wrote a good blog post on this topic: [Coding Horror: Stylesheets for Print and Handheld][1] [1]: http://www.codinghorror.com/blog/archives/000782.html
Unless your child process also understands how to work with SecureString I don't think there is a way to pass it directly. For example, the Process.Start() method has two overloads that take a SecureString so the risk of the actual string value being sniffed is minimized (it's still possible since somewhere along the t...
Tools like [AutomatedQA AQTime][1] can help you diagnose GDI usage. A much simpler, but free tool one can be found [here][2]. [1]: http://www.automatedqa.com/products/aqtime/index.asp [2]: http://msdn.microsoft.com/en-us/magazine/cc188782.aspx
To the best of my knowledge, ORM frameworks are going to want to generate the CRUD code for you, so they would have to be explicitly designed to implement a MVCC option; I don't know of any that do so out of the box. From an Entity framework standpoint, CSLA doesn't implement persistence for you at all -- it just de...
I would think it's worth it to take the extra time to make it human readable just to make it easier to debug.
I would say that it is imperative that the code is human readable, unless your code-gen tool has an excellent debugger you (or unfortunate co-worker) will probably by the one waist deep in the code trying to track that oh so elusive bug in the system. My own excursion into 'code from UML' left a bitter tast in my mouth...
In terms of power, any current Mac is fine for iPhone development. You might want to consider other factors that depend on how you like to work. Do you like to sometimes grab the machine and just get in a different work environment (or show your stuff to people)? The MacBooks are comparable power-wise, but give you...
Generated code should be readable, (format etc can usually be handled by a half decent IDE). At some stage in the codes lifetime it is going to be viewed by someone and they will want to make sense of it.
I think for data containers or objects with very straightforward workings, human readability is not very important. However, as soon as a developer may have to read the code to understand how something happens, it needs to be readable. What if the logic has a bug? How will anybody ever discover it if no one is able...
Your approach is not too bad, but you should use a StringBuffer instead of using the + sign. The + has the big disadvantage that a new String instance is being created for each single operation. The longer your string gets, the bigger the overhead. So using a StringBuffer should be the fastest way: public String...
Surrogate keys are quite handy if you plan to use an ORM tool to handle/generate your data classes. While you can use composite keys with some of the more advanced mappers (read: hibernate), it adds some complexity to your code. (Of course, database purists will argue that even the notion of a surrogate key is an a...
In Microsoft C++, I did an experiment with inline functions. I wanted to know what would happen if I defined incompatible versions of a function in different sources. I got different results depending on whether I was using a Debug build or a Release build. In Debug, the compiler refuses to inline anything, and the ...
Ruby - Get a Variable's Name
|ruby|variables|
I'm not entirely sure if this is possible in Ruby, but hopefully there's an easy way to do this. I want to declare a variable and later find out the name of the variable. That is, for this simple snippet: foo = ["goo", "baz"] How can I get the name of the array (here, "foo") back? If it is indeed possible, does...
I'm not entirely sure if this is possible in Ruby, but hopefully there's an easy way to do this. I want to declare a variable and later find out the name of the variable. That is, for this simple snippet: foo = ["goo", "baz"] How can I get the name of the array (here, "foo") back? If it is indeed possible, does...
- How do I check the permissions for writing to an excel file for my application (I'm using excel 2007)? - The file is not read only, or protected (to my knowledge). - My connection String is: > "Provider=Microsoft.Jet.OLEDB.4.0;Data > Source=fifa_ng_db.xls;Mode=ReadWrite;Extended > Properties=\"Excel >...
**Alt-Shift-R** stands for *rename*, not refactor. Refactoring is a [more general term](http://en.wikipedia.org/wiki/Refactoring) (as defined by [the book](http://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Technology/dp/0201485672)). Nevertheless, it is one of my favorite refactorings. Others inclu...
The 2.0 framework introduced the nullable value type. Even though the literal constant "1" can never be null, its underlying type (int) can now be cast to a Nullable<int> int type. My guess is that the compiler can no longer assume that int types are not nullable, even when it is a literal constant. I do get a warni...
Logic should always be readable. If someone else is going to read the code, try to put yourself in their place and see if you would fully understand the code in high (and low?) level without reading that particular piece of code. I wouldn't spend too much time with code that never would be read, but if it's not too...
If you are using ASP.NET 2.0 or higher, after you compile with the resource file, you can reference it through the Resources namespace: text = Resources.YourResourceFilename.YourProperty; You even get Intellisense on the filenames and properties.
If this code is likely to be debugged, then you should seriously consider to generate it in a human readable format.
Use an approach based on [java.lang.StringBuilder][1]! ("A mutable sequence of characters. ") Like you mentioned, all those string contcatinations are creating Strings all over. StringBuilder won't do that. [1]: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuilder.html
Use an approach based on **[java.lang.StringBuilder][1]**! ("A mutable sequence of characters. ") Like you mentioned, all those string contcatinations are creating Strings all over. StringBuilder won't do that. EDIT: Why **[java.lang.StringBuilder][2]** instead of **[StringBuffer][3]**? From the StringBuilder ...
One reason to just store the link or an ID that can be used to build the link is that the storage that you usually use for Oracle DB's is rather expensive. If you have lots of large files, it is usually much more cost-effective to put them on a less expensive array of disks.
[A List Apart][1] is a great reference for using semantic HTML, the [Holy Grail article][2] is probably one of the best examples. Also, check out [CSS Zen Garden][3] for some inspiration on the topic or read Dave Shea's excellent book "The Zen of CSS Design." [1]: http://www.alistapart.com/ [2]: http://www.a...
Yes it does. Firstly, you might need to debug it -- you will be making it easy on yourself. Secondly it should adhere to any coding conventions you use in your shop because someday the code might need to be changed by hand and thus become human code. This scenario typically ensues when your code generation tool does...
Ah, looks like you have to go to File->Open and click the down arrow next to the Open button to "Open With" the xml editor. If someone wants to copy and paste this, free accepted answer :P
I'm surprised no one got this one yet. There's a refactornig specifically for this type of problem: <http://www.refactoring.com/catalog/decomposeConditional.html>
If you happen to be programming in Python, it's a cinch with the built-in `all()` function applied over the list of your variables (I'll just use Boolean literals here): >>> L = [True, True, True, False, True] >>> all(L) # True, only if all elements of L are True. False >>> any(L) # True, if any e...
Protocol buffers are intended to optimize communications between machines. They are really not intended for human interaction. Also, the format is binary, so it could not replace XML in that use case. I would also recommend [JSON][1] as being the most compact text-based format. [1]: http://en.wikipedia.org/w...
I hate to say this but as soon as you put something on a client machine, security for that data goes out the window. If your program is going to decrypt that string, you need to assume that an attacker can do the same. Attaching a debugger to your program would be one way. Storing the connection string on a serve...
There are two issues to address here: readability and understandability The "readability" solution is a style issue and as such is open to interpretation. My preference is this: if (var1 == true && // Explanation of the check var2 == true && // Explanation of the check var3 == true && // Exp...
Wow, I wouldn't have thought it, but there seems to be.. Good ole DB2. I find the publib db2 docs view very very handy by the way: http://publib.boulder.ibm.com/infocenter/db2luw/v8//index.jsp I just found the "SYSCAT.TABDEP" catalog view in it, which seems to contain more or less what you asked for. I suspect...
Do you have the source? In many cases the difference between a stand alone application and a service are minimal. Most of the changes are related to hooking the code into the service manager properly. Once done, you'll know that any problems that occur are a result of your programming and not any other program.
For visualization our group had some success with [prefuse][1]. We extended it to handle architectural floorplates and bubble diagraming, and it didn't complain too much. They have a new Flex toolkit out too called Flare that uses a very similar API. [1]: http://prefuse.org/
For visualization our group had some success with [prefuse][1]. We extended it to handle architectural floorplates and bubble diagraming, and it didn't complain too much. They have a new Flex toolkit out too called Flare that uses a very similar API. UPDATE: I'd have to agree with the comment, we ended up writing...
Just store all the necessary data from the POST in the session until after the login process is completed. Or have some sort of temp table in the db to store in and then retrieve it. Obviously this is pseudo-code but: if ( !loggedIn ) { StorePostInSession(); ShowLoginForm(); } if ( ...
How could I get my SVN-only host to pull from a git repository?
|svn|git|build-automation|capistrano|
I'd really like to get our host to pull from our Git repository instead of uploading files manually, but it doesn't have Git installed. So is there a way to trick Subversion (which they do have) into checking out a Git repository? I think I already know the answer, namely bug my host to add Git and live with it u...
How to Track Queries on a Linq-to-sql DataContext
|asp.net|linq-to-sql|
In the [herding code](http://herdingcode.com/) podcast 14 someone mentions that stackoverflow displayed the queries that were executed during a request at the bottom of the page. It sounds like an excellent idea to me. Every time a page loads I want to know what sql statements are executed and also a count of the t...
Search Engines don't support JavaScript. They're also blind and don't support CSS. So my suggestion to you is to make sure that the part of your product that needs to be indexable by search engines works without JavaScript and CSS. After that, it really depends on the needs of your users. If you have a very limited ...
**Perl** in 10 chars sub x{&x}x Eventually uses up all available memory.
There are different types of generated code, but the most simple types would be: 1. Generated code that is not meant to be seen by the developer. e.g., xml-ish code that defines layouts (think .frm files, or the horrible files generated by SSIS) 2. Generated code that is meant to be a basis for a class that wil...
Control Panel -> Internet Options
> I'm currently using NotePad++. Is > there maybe an IDE that would take > care of the tabs and indenting? I liked [pydev][1] extensions of eclipse for that. [1]: http://pydev.sourceforge.net/
Does this help? http://docs.sun.com/source/816-5691-10/essearch.htm#25618 ----- To map a URL, perform the following steps: Open the Class Manager and select the server instance from the drop-down list. Choose the Content Mgmt tab. Click the Additional Document Directories link. The web server displays ...
[Typecasting][1] and the [ctype_*][2] functions become important to ensure clean data. I have made extensive use of [exceptions][3] lately, which has greatly simplified my error handling code. I wouldn't say the language has lots of killer features. (At least, I don't find much occasion to seek them out.) I like tha...
|c#|winforms|registry|printing|webbrowser|
I am using the webbrowser control in winforms and discovered now that background images which I apply with css are not included in the printouts. Is there a way to make the webbrowser print the background of the displayed document too? Edit: Since I wanted to do this programatically, I opted for this solution: ...
How come a 32 bit kernel can run a 64 bit binary?
|c|64-bit|32-bit|macosx|
On my OS X box, the kernel is a 32 bit binary and yet it can run a 64 bit binary. How does this work? <pre> cristi:~ diciu$ file ./a.out ./a.out: Mach-O 64-bit executable x86_64 cristi:~ diciu$ file /mach_kernel /mach_kernel: Mach-O universal binary with 2 architectures /mach_kernel (for architecture i386): Ma...
|c|macos|64-bit|32-bit|
How to show a spinner while loading an image via JavaScript
|javascript|jquery|dom|
I'm currently working on a web application which has a page which displays a single chart (a .png image). On another part of this page there are a set of links which, when clicked, the entire page reloads and looks exactly the same as before except for the chart in the middle of the page. What I want to do is when ...
Your .htaccess does nothing useful, as Apache is probably configured with DirectoryIndex index.php. Well, it does move domain.com/a to domain.com/index.php, but I doubt that is what you want. Your wildcard virtualhost works because you probably have ServerAlias *.domain.com in your configuration, or a single virtua...
Your .htaccess does nothing useful, as Apache is probably configured with DirectoryIndex index.php. Well, it does move domain.com/a to domain.com/index.php, but I doubt that is what you want. Your wildcard virtualhost works because you probably have ServerAlias *.domain.com in your configuration, or a single virtua...
It is **an error** to have a specialization for a template which is not visible at the point of call. Unfortunately, compilers are not required to diagnose this error, and can then do what they like with your code (in standardese it is "ill formed, no diagnostic required"). Technically, you need to define the specia...
you should mock the transaction and make it return true fo IsSaved, if you can mock the transaction of course. ITransaction transaction = _Mocker.dynamicMock<ITransaction>; Expect.Call(transaction.IsSaved).IgnoreArguments.Return(true); _mocker.ReplayAll(); dao.Save(transaction);
Is a bool read/write atomic in C#
|c#|.net|concurrency|locking|boolean|
Is accessing a **bool** field atomic in C#? In particular, do I need to put a lock around: class Foo { private bool _bar; //... in some function on any thread (or many threads) _bar = true; //... same for a read if (_bar) { ... } }
I have a link icon next to each link. How do I exclude the link icon from images?
|css|
I've got the following in my .css file creating a little image next to each link on my site: div.post .text a[href^="http:"] { background: url(../../pics/remote.gif) right top no-repeat; padding-right: 10px; white-space: nowrap; } How do I modify this snippet (or add something new)...
Tools for converting non-Java into Java source
|java|compiler-construction|
Are there any good tools out there for automatically converting non-Java source code into Java source? I'm not expecting something perfect, just to get the worst of the grunt work out of the way. I guess there is a sliding scale of difficulty. C# should be relatively easy (so long as you ignore all the libraries)...
If you're running on an AS/400 (or iSeries, or whatever the heck IBM is calling it these days), you'll probably want to get it from JTOpen (http://jt400.sourceforge.net/). Their toolbox replaces the old Java Toolbox and includes the JDBC drivers.
The ACM Queue has some hardcore content, dense, but good. I haven't read it in a while though.
Can you fill in the code inside {} to add the bold tag, and encode the text? I'm confused as to how to apply the changes to the entire text block AND replace the section in the text variable at the end.
[SmartInspect][1] is a profiler and logger. Not specific to memory, but you might want to take a look. It works with a variety of languages too, including Delphi, Java and .NET. Includes other more advanced features. ![SmartInspect architecture][2] [1]: http://www.gurock.com/products/smartinspect/ [2]: ...
Reference counting is particularly difficult to do efficiently in a multi-threaded environment. I don't know how you'd even start to do it without getting into hardware assisted transactions or similar (currently) unusual atomic instructions. Reference counting is easy to implement. JVMs have had a lot of money sunk...
I might consider implementing the MVCC tier purely in the DB, using stored procs and views to handle my data operations. Then you could present a reasonable API to any ORM that was capable of mapping to and from stored procs, and you could let the DB deal with the data integrity issues (since it's pretty much build for...
Heres an implementation of this I've used to pick out special replace strings from content and localize them. protected string FindAndTranslateIn(string content) { return Regex.Replace(content, @"\{\^(.+?);(.+?)?}", new MatchEvaluator(TranslateHandler), RegexOptions.IgnoreCa...
Looking at the registry, the start page seems to be stored in HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Start Page
boolean IsPalindrome(string s) { return s = s.Reverse(); }
You could do it through the control panel, but you could also supply a url as a parameter to iexplore.exe. start » run » iexplore about:blank
If, IIf and If
|vb|if-statement|iif-function|if-function|
I recently asked a question about [IIf vs. If][1] and found out that there is another function in VB called **If** which basically does the same thing as **IIf** but is a short-circuit. Does this **If** function perform better than the **IIf** function? Does the **If** statement trump the **If** and **IIf** functio...
If, IIf and If()
If, IIf() and If()
The whole point of generated code is to do something "complex" that is easier defined in some higher level language. Due to it being generated, the actual maintenance of this generated code should be within the subroutine that generates the code, not the generated code. Therefor, human readability should have a lowe...
The whole point is that I need the line-drawn graphics behind the image to be visible. I did try filling the rectangle first the with RGBA color of (255, 255, 255, 0) but this does not help. Pixels with an alpha value of zero do get printed as fully transparent but partially transparent pixels are drawn fully opaque.
You might need to clarify a bit. What are you really trying to accomplish? If you really want to find out the column names that only contain null values, then you will have to loop through the scheama and do a dynamic query based on that. I don't know which DBMS you are using, so I'll put some pseudo-code here. ...
The RTL uses reintroduce to hide inherited constructors. For example, TComponent has a constructor which takes one argument. But, TObject has a parameterless constructor. The RTL would like you to use only TComponent's one-argument constructor, and not the parameterless constructor inherited from TObject when insta...
In MS SQL Server (7.0 and up), varchar data is represented internally with up to three values: - The actual string of characters, which will be from 0 to something over 8000 bytes (it’s based on page size, the other columns stored for the row, and a few other factors) - Two bytes used to indicate how long the dat...
The browser history can't be directly accessed, but you can compare a list of sites with the user's history. This can be done because the browser attributes a different CSS style to a link that hasn't been visited and one that has. Using this style difference you can change the content of you pages using pure CSS, ...
Detecting Client Disconnects in Web Services
|java|web-services|cxf|
I'm using the [Apache CXF][1] Web Services stack. When a client times out or disconnects from the server before the operation is complete, the server keeps running the operation until it is complete. I would like to have the server detect when the client disconnects and handle that accordingly. Is there a way to det...
What is this Icarus thing that comes with MbUnit?
|tdd|mbunit|
I've had to install MbUnit multiple times now and it keeps coming with something called the Gallilo Icarus GUI Test Runner. I have tried using it thinking it was just an update to the MbUnit GUI but it won't detect my MbUnit tests and sometimes won't even open the assemblies properly. Perhaps I'm just overlooking it ...