instruction
stringlengths
0
30k
I have wondered about the appropriateness of reflection in C# code. For example I have written a function which iterates through the properties of a given source object and creates a new instance of a specified type, then copies the values of properties with the same name from one to the other. I created this to copy d...
What's wrong with (aDataSet.Tables.Count == 0) ?
To be clear, you would first need to look at all the DataTables, and then look at the count of Rows for each DataTable.
Singletons are evil, what do you expect? ;) Perhaps the most comprehensive approach would be to load the bulk of the applet in a different class loader (use java.net.URLClassLoader.newInstance). Then use a WeakHashMap to associate class loader with an applet. If you could split most of the code into a common class l...
Singletons are evil, what do you expect? ;) Perhaps the most comprehensive approach would be to load the bulk of the applet in a different class loader (use java.net.URLClassLoader.newInstance). Then use a WeakHashMap to associate class loader with an applet. If you could split most of the code into a common class l...
Compressing HTML should not hurt you. When you say HTML compressor I assume you mean a tool that removed whitespace etc from your pages to make them smaller, right? This doesn't impact how a crawler will see your html as it likely strips the same things from the HTML when it grabs the page from your site. The 'semantic...
You could also use Javascript to load content from another source file and output that. That may be a bitmpre black box-is than you're looking for though.
You could also use Javascript to load content from another source file and output that. That may be a bit more black box-is than you're looking for though.
G'day, Just wanted to clarify an answer someone gave but I don't have enough points yet. diff will work on binary files but it is only going to say something not really useful like "toto1 and toto2 binary files differ". cheers, Rob
I'm not exactly sure what you're asking for. You can either have a GUI or a command line. What do you need from a graphical command shell that you couldn't get from a straight GUI? Also, if you want graphical information about file sizes there are a few applications that do that. One example is [WinDirStat][1]. ...
Why would getcwd() return a different directory than a local pwd?
|php|directory|
I'm doing some php stuff on an Ubuntu server. The path I'm working in is **/mnt/dev-windows-data/Staging/mbiek/test_list** but the PHP call ***getcwd()*** is returning **/mnt/dev-windows/Staging/mbiek/test_list** (notice how it's dev-windows instead of dev-windows-data). There aren't any symbolic links anywhere. ...
I'm doing some php stuff on an Ubuntu server. The path I'm working in is **/mnt/dev-windows-data/Staging/mbiek/test_list** but the PHP call ***getcwd()*** is returning **/mnt/dev-windows/Staging/mbiek/test_list** (notice how it's dev-windows instead of dev-windows-data). There aren't any symbolic links anywhere. ...
> I can't find that "WebForm_FireDefaultButton" javascript anywhere, is it something asp.net is generating? Yes. That's generated to support the **DefaultButton** functionality of the form and/or Panel containing your controls. This is the source for it: function WebForm_FireDefaultButton(event, target) {...
[@Ross](http://stackoverflow.com/questions/30307/why-would-getcwd-return-a-different-directory-than-a-local-pwd#30363) I figured it out and updated the OP with the solution.
In .NET: datetime.ToString("YYYY-MM-DD'T'HH:mm:ss")
On MacOSX, [TextMate][1] is a godsend. [1]: http://macromates.com/
So you would use recursion. Here is a powershell example that should be easy to convert to C#: function Move-Stuff($folder) { foreach($sub in [System.IO.Directory]::GetDirectories($folder)) { Move-Stuff $sub } $new = $folder.Replace("Shark", "Orca") if(!(Test-Path(...
Another fun way to stub out variadic functions is: `#define function sizeof` MSN
The XML spec has something to say regarding [whitespace][1] and [linefeeds and carriage returns in particular][2]. So if you limit yourself to true linefeeds (x0A) you should be Ok. However, many editing tools will reformat XML for "better presentation" and possibly get rid of the special syntax. A more robust and clea...
If you want a classic setup, I'd go for a 50GB "/" partition, for all your application goodness, and split the rest across users, or a full 950GB for a single user. Endless diskspace galore!
Is your existing application monolithic or tiered in seperate processes/layers? If tiered, you can convert the middle/app-tier to run in an OSGi container. In my team's experience, we've found trying to do web-stuff in OSGi painful. Other pain points are Hibernate and Jakarta Commons Logging. I find the OSGi ...
A web service is almost certainly the way to go. I'm sure you've already thought of this, but since you're doing PHP on both sides, you can shortcut things a little bit by using serialize() to build your response data instead of building a proper XML document. It's less flexible over the long run, but it will probabl...
I have a feeling this will be one of the most popular questions asked over time on Stack Overflow. It boils down to preference. Whatever you think is more readable. I prefer var when the type is defined on the right side because it is more terse. When I'm assigning a variable from a method call, I use the explicit type...
It's of course a matter of style, but I agree with Dare: [C# 3.0 Implicit Type Declarations: To var or not to var?][1]. I think using var instead of an explicit type makes your code less readable.In the following code: var result = GetUserID(); What is result? An int, a string, a GUID? Yes, it matters, and no...
You might consider using custom types. For example, create LogonName and BadgeNumber classes. Then your function declarations look like... public Person(LogonName ln) { this.Load(ln.ToString()); } public Person(BadgeNumber bn) { //load logic here... } Such a ...
How about ... public Person(int personId) { this.Load(personId); } public Person(string logonName) { this.Load(logonName); } public Person(Object badgeNumber) { //load logic here... }
Reflection is what you want. Reflection + TypeConverter. Don't have much more time to explain, but just google those, and you should be well on your way. Or you could just use the xml serializer, but then you have to adhere to a format, but works great.
A 1500-line ASP page? With lots of calls out to include files? Don't tell me -- the functions don't have any naming convention that tells you which include file has their implementation... That brings back memories (shudder)... It sounds to me like you have a pretty solid approach -- I'm not sure if there is any m...
What about using Response.Redirect(String.Format("http://{0}/Login.aspx?ReturnPath={1}", Request.ServerVariables["SERVER_NAME"], Request.Url.ToString()));
Content Type for MHT files
|content-type|
What is the content type for MHT files?
Plenty of metaprogramming facilities. Specifically, you can get a reference to the assembly that holds these classes, then easily get the `Type` of a class from its name. See [Assembly.GetType Method (String)](http://msdn.microsoft.com/en-us/library/y0cd10tb.aspx). From there, you can instantiate the class using ...
Compressing HTML should not hurt you. When you say HTML compressor I assume you mean a tool that removed whitespace etc from your pages to make them smaller, right? This doesn't impact how a crawler will see your html as it likely strips the same things from the HTML when it grabs the page from your site. The 'sema...
Take a look at http://docs.jquery.com/Core/get#index
Haven't used ddbg yet, but according to the documentation at http://ddbg.mainia.de/doc.html there is the > onex <cmd; cmd; ...> on exception execute list of commands command.
$('#MyObject').get(0); I think that's what you want. I think you can also reference it like a regular array with: $('#MyObject')[0]; But I'm not sure if that will always work. Stick with the first syntax.
You should *denormalize* your tables if you find yourself joining 6+ tables in one query to retrieve data for a reporting type web page that will be hit often. Also, if you use ORM libraries like Hibernate or ActiveRecord make sure to spend some time on the default mappings they generate and the sql that ends up gener...
If you're using the UNION ALL pattern you may also want to include the following parts to your query: SELECT COUNT(*) AS C ... GROUP BY ID ORDER BY c DESC While this is a really trivial example it does get you the frequency of the matches for each result and this could be a pseudo rank to start...
How do you create a virtual network interface on Windows?
|windows|networking|
On linux, it's possible to create a tun interface using a tun driver which provides a "network interface psuedo-device" that can be treated as a regular network interface. Is there a way to do this programmatically on windows? Is there a way to do this without writing my own driver?
Refer /select a drive based only on it's LABEL? (i.e., not the drive letter?)
|batch-file|files|
I'm trying to refer to a drive whose letter may change. I'd like to refer to it by its label (e.g., MyLabel (v:) within a Batch File. It can be referred to by V:\ . I'd like to refer to it by MyLabel. (This was posted on Experts Echange for a month with no answer. Let's see how fast SO answers it <g>)
@Ross#30313 I thought that getcwd() was returning a filesystem path rather than a relative url path. Either way, the fact remains that the path /mnt/dev-windows **doesn't** exist while /mnt/dev-windows-data does.
[@Ross](http://stackoverflow.com/questions/30307/why-would-getcwd-return-a-different-directory-than-a-local-pwd#30313) I thought that getcwd() was returning a filesystem path rather than a relative url path. Either way, the fact remains that the path /mnt/dev-windows **doesn't** exist while /mnt/dev-windows-data ...
How do you do version a Web Application?
|versioning|version-control|
What are the strategies for versioning of a web application/ web site? I notice that here in the Beta there is an svn revision number in the footer and thats great for an application that uses svn over one repository. But what if you use externals or a different source control application that versions separate files? ...
|asp.net|versioning|version-control|
What are the strategies for versioning of a web application/ web site? I notice that here in the Beta there is an svn revision number in the footer and thats great for an application that uses svn over one repository. But what if you use externals or a different source control application that versions separate fi...
Strictly speaking never, but it gives the garbage collector a strong hint to clean things up. As a rule: **do it every time you're done with an object that you've created**.
Setting a VB6 reference to Nothing, decreases the refecences count that VB has for that object. If and only if the count is zero, then the object will be destroyed. Don't think that just because you set to Nothing it will be "garbage collected" like in .NET VB6 uses a reference counter. You are encouraged to ...
I had a problem similar to this a while back. I seem to think it would also prevent the app from closing, but it may be applicable here. I pulled up the old code and it looks something like: Dim y As Long For y = 0 To Forms.Count -1 Unload Forms(x) Next It may be safer to Unload the m_f...
CSS Background Color in Javascript
|javascript|css|
How can I set the CSS background color of a HTML element via JavaScript?
var element = document.getElementById('element'); element.style.background = '#ff00aa';
In general, CSS properties are converted to JavaScript by making them camelCase without any dashes. So "background-color" becomes "backgroundColor". function setColor(element, color) { element.style.backgroundColor = color; }
// Generic function that gets all child controls of a certain type, // returned in a List collection private static List<T> GetChildTextBoxes<T>(Control ctrl) where T : Control { List<T> tbs = new List<T>(); foreach (Control c in ctrl.Controls) { // If c is of type T, add it to the col...
Perhaps this might work: *(i'm using c# but could be adapted to vb)* String RelativePath = Server.MapPath(AbsolutePath).Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
Perhaps this might work: String RelativePath = AbsolutePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty); *(i'm using c# but could be adapted to vb)* *(@Tags2k: I have editted the above answer)*
I have same problems in my work (we also use VC6 sometimes). And there is no easy solution for it. I have only some hints: - Try with automatic crash dumps on production machine (see [Process Dumper][1]). My experience says Dr. Watson is **not perfect** for dumping. - Remove all **catch(...)** from your code. T...
If you return IEnumerator<T>, it will be a different enumerator object each time call that method (acting as though you reset the enumerator on each iteration). If you return IEnumerable<T> then a foreach can enumerate based on the method with the yield statement.
> What is the difference between SetForeGroundWindow, SetActiveWindow, and BringWindowToTop? It appears as if they all do the same thing. According to MSDN, SetForeGroundWindow will activate the window and direct keyboard focus to it. This attempts to work even when your process is in the background. SetActiveWindow...
I once wrote this function to perform that exact task: public static string Column(int column) { column--; if (column >= 0 && column < 26) return ((char)('A' + column)).ToString(); else if (column > 25) return Column(column / 26) + Column(column % 26 + 1)...
> There's no point using a beta version in dev if you aren't certain you'll use it in production. That just seems like a wasted exercise Good point, I was also considering the scenario of evaluation of the pre-release version in dev, but I supposed that taints the dev -> test/qa -> prod path. > I'll use the patch...
I currently use this, but I have a feeling that it can be optimized. private String GetNthExcelColName(int n) { String firstLetter = ""; //if number is under 26, it has a single letter name // otherwise, it is 'A' for 27-52, 'B' for 53-78, etc if(n > 26) { ...
import urllib2 mp3file = urllib2.urlopen("http://www.example.com/songs/mp3.mp3") output = open('test.mp3','wb') output.write(mp3file.read()) output.close() the 'wb' in open('test.mp3','wb') opens a (and erases any existing) file, binaraly, so you can save data with it, instead of just text.
While my answer may not contain any concrete steps to help this is always where I start. First thing I would do is try to throw away all of your assumptions about what the trouble is and take steps to install metrics everywhere you can. Let the metrics guide you rather than your intuition. I've chased many, many, ...
I agree with Corey, urllib2 is more complete than [urllib](http://docs.python.org/lib/module-urllib.html) and should likely be the module used if you want to do more complex things, but to make the answers more complete, urllib is a simpler module if you want just the basics: import urllib response = urllib...
Cleanest Way to Invoke Cross-Thread Events
|c#|events|multithreading|
Well, right... But since I need to be able to convert to XML anyway, why hold both my document tree and the DOM tree in memory, when there's nothing preventing me from working right off the DOM tree? Particularly since one unique feature of my program is that everything is always saved as you type, and I don't want ...
message/rfc822 RFC 822 - STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES Here is a hyperlink: [message/rfc822][1] [1]: http://www.faqs.org/rfcs/rfc822.html
If the template is defined in your &lt;Window.Resources&gt; section directly: myTreeViewControl.ItemTemplate = this.Resources["SomeTemplate"] as DataTemplate; If it's somewhere deep within your window, like in a &lt;Grid.Resources&gt; section or something, I think this'll work: myTreeViewControl.ItemTe...
[Reflection][1] allows you to do that. You also may want to look at [XML Serialization][2]. Type type = blah.GetType(); PropertyInfo prop = type.GetProperty("prop1"); prop.SetValue(blah, "foo", null); [1]: http://msdn.microsoft.com/en-us/library/ms173183.aspx [2]: http://msdn.microsoft.com/en-u...
Javascript Browser Quirks - array.Length
|javascript|
Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Unusual Array Lengths!</title> <script type="text/javascript"> var arrayList = new Array(); arrayList = [1, 2, 3, 4, 5, ]; alert(arrayList.length); </script> ...
Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Unusual Array Lengths!</title> <script type="text/javascript"> var arrayList = new Array(); arrayList = [1, 2, 3, 4, 5, ]; alert(arrayList.length); </script> ...
"Best style" is subjective and varies depending on context. Sometimes it is way easier to use 'var' instead of typing out some hugely long class name, or if you're unsure of the return type of a given function. I find I use 'var' more when mucking about with Linq, or in for loop declarations. Other times, using t...
No not **always** but I would go as far as to say a lot of the time. Type declarations aren't much more useful than hungarian notation ever was. You still have the same problem that types are subject to change and as much as refactoring tools are helpful for that it's not ideal compared to not having to change where a ...
My standard strategy for normal "utility" boxes is to give them a swap partition twice the size of their RAM, a 1GB /boot partition and leave the rest as one vast partition. Whilst I see why some people want a separate /var, separate /home, etc., if I only have trusted users and I'm not running some production service...
Once you get past the beginning stages, I would highly recommend reading [Real World Haskell][1]. [1]: http://book.realworldhaskell.org/
string oldPath = "\\shark.exe" string newPath = oldPath.Replace("shark", "orca"); System.IO.File.Move(oldPath, newPath); Fill in with your own full paths
Ok here's some best practises from some one who doesn't unit test as much as he should...cough. 1. Make sure your tests test one thing and thing only. 2. Write unit tests as you go. Preferably before you write the code you are testing against. 3. Do not unit test the GUI. 4. Separate you concerns. 5....
Ok here's some best practices from some one who doesn't unit test as much as he should...cough. 1. Make sure your tests test one thing and thing only. 2. Write unit tests as you go. Preferably before you write the code you are testing against. 3. Do not unit test the GUI. 4. Separate you concerns. 5....
Ok here's some best practices from some one who doesn't unit test as much as he should...cough. 1. Make sure your tests test [one][1] thing and one thing only. 2. Write unit tests as you go. Preferably [before][2] you write the code you are testing against. 3. Do not unit test the GUI. 4. [Separate you ...
MS hotfix delayed delivery.
|microsoft|hotfix|support|email|
I just requested a hotfix from support.microsoft.com and put in my email address, but I haven't received the email yet. The splash page I got after I requested the hotfix said: > **Hotfix Confirmation** > We will send these hotfixes to the following e-mail address: > me@mycompany.com > Usually, our hot...
I just requested a hotfix from support.microsoft.com and put in my email address, but I haven't received the email yet. The splash page I got after I requested the hotfix said: > **Hotfix Confirmation** > We will send these hotfixes to the following e-mail address: > (my correct email address) > Usuall...
|email|microsoft|support|hotfix|
I just requested a hotfix from support.microsoft.com and put in my email address, but I haven't received the email yet. The splash page I got after I requested the hotfix said: > **Hotfix Confirmation** > We will send these hotfixes to the following e-mail address: > (my correct email address) > Usuall...
Refer to/select a drive based only on its label? (i.e., not the drive letter)
|windows|batch-file|