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 data from one auto-generated LINQ object to another in order to get around the lack of inheritance from multiple tables in LINQ.
However, I can't help but think code like this is really 'cheating', i.e. rather than using using the provided language constructs to achieve a given end it allows you to circumvent them.
To what degree is this sort of code acceptable? What are the risks? What are legitimate uses of this approach? |
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 loader (as a parent of each per-applet class loader) and into the normal applet codebase, that would be faster but more work.
##Other hacks:
If you have access to any component, you can use Component.getParent repeatedly or SwingUtilities.getRoot.
If you are in a per-applet instance thread, then you can set up a ThreadLocal.
From the EDT, you can read the current event from the queue (java.awt.EventQueue.getCurrentEvent()), and possibly find a component from that. Alternatively push an EventQueue with a overridden dispatchEvent method.
|
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 loader (as a parent of each per-applet class loader) and into the normal applet codebase, that would be faster but more work.
Other hacks:
If you have access to any component, you can use Component.getParent repeatedly or SwingUtilities.getRoot.
If you are in a per-applet instance thread, then you can set up a ThreadLocal.
From the EDT, you can read the current event from the queue (java.awt.EventQueue.getCurrentEvent()), and possibly find a component from that. Alternatively push an EventQueue with a overridden dispatchEvent method.
|
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' structure of the HTML exists whether compressed or not.
You might also want to look at:
* Compressing pages with an GZIP compression in the web server
* Reducing size of images, CSS, javascript etc
* Considering how the browser's layout engine loads your pages. |
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].
[1]: http://windirstat.info/ |
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.
Are there any other causes for ***getcwd()*** returning a different path from a local pwd call? |
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.
Are there any other causes for ***getcwd()*** returning a different path from a local pwd call?
***Edit***
I figured it out. The DOCUMENT_ROOT in PHP is set to /mnt/dev-windows which throws everything off. |
> 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) {
if (event.keyCode == 13) {
var src = event.srcElement || event.target;
if (!src || (src.tagName.toLowerCase() != "textarea")) {
var defaultButton;
if (__nonMSDOMBrowser) {
defaultButton = document.getElementById(target);
}
else {
defaultButton = document.all[target];
}
if (defaultButton && typeof (defaultButton.click) != "undefined") {
defaultButton.click();
event.cancelBubble = true;
if (event.stopPropagation) event.stopPropagation();
return false;
}
}
}
return true;
} |
[@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($new)))
{
new-item -path $new -type directory
}
foreach($file in [System.IO.Directory]::GetFiles($folder))
{
$new = $file.Replace("Shark", "Orca")
move-item $file $new
}
}
Move-Stuff "C:\Temp\Test"
|
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 cleaner approach than the "< line>< / line>" idea would be to simply use namespaces and embed XHTML content, e.g.:
<Address xmlns="http://www.w3.org/1999/xhtml">15 Sample St<br />Example Bay<br />Some Country</Address>
No need to reinvent the wheel when it comes to standard vocabularies.
[1]: http://www.w3.org/TR/xml/#sec-white-space
[2]: http://www.w3.org/TR/xml/#sec-line-ends |
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 specs pretty readable and I recommend you print out the flowchart that shows the algorithm for class loading. I'll guarantee you'll have moments of, "why am I getting a NoClassDefFoundError?": the flowchart will tell you why. |
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 probably get you up and running more quickly. |
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 declaration. |
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, I shouldn't have to dig through the code to know. It's especially annoying in code samples.
Jeff wrote a post on this, saying [he favors var][2]. But that guy's crazy!
I'm seeing a pattern for stackoverflow success: dig up old CodingHorror posts and (Jeopardy style) phrase them in terms of a question.
[1]: http://www.25hoursaday.com/weblog/2008/05/21/C30ImplicitTypeDeclarationsToVarOrNotToVar.aspx
[2]: http://www.codinghorror.com/blog/archives/001136.html |
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 solution might give you a good place to keep the business logic that governs the format and usage of these strings. |
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 magical way to mitigate your pain. After your conversion effort, the architecture of your app will still be messy and UI-heavy (i.e. code-behind running workflows), and it will probably still be fairly painful to maintain, but the refactoring you are doing should definitely help.
I hope you have weighed the upgrade you are doing against just rewriting from scratch -- as long as you are not intending to extend the app too much and you are not primarily responsible for maintaining the app, upgrading a complex workflow-based app like you are doing may be cheaper and a better choice than rewriting it from scratch. ASP.NET should give you better opportunities to improve performance and scalability, at least, than Classic ASP. From your question I imagine that it is too late in the process for that discussion anyway.
Good luck! |
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 `Activator` or the constructor of the `Type` itself. See [Activator.CreateInstance Method](http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx).
Once you have an instance, you can set properties by again using the `Type` object. See [Type.GetProperty Method](http://msdn.microsoft.com/en-us/library/system.type.getproperty.aspx) and/or [Type.GetField Method](http://msdn.microsoft.com/en-us/library/system.type.getfield.aspx) along [PropertyInfo.SetValue Method](http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.setvalue.aspx). |
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' structure of the HTML exists whether compressed or not.
You might also want to look at:
* Compressing pages with an GZIP compression in the web server
* Reducing size of images, CSS, javascript etc
* Considering how the browser's layout engine loads your pages.
By jumbled HTML, this SEO person probably means the use of tables for layout and re-purposing of built in HTML elements (eg. `<p class="headerOne">Header 1</`p>). This increases the ratio of HTML tags to page content, or keyword density in SEO terms. It has bigger problems though:
* Longer page load times due to increased content to download, why not use the H1 tag?
* It's difficult for screenreaders to understand and affects site accessibility.
* Browsers may take longer to render the content depending on how they parse and layout pages with styles. |
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 generating. They tend to be very chatty with the database when you could have achieve the same results with one round trip to the database. |
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 with. |
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 does. |
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? It seems easy with a Desktop app but I can't seem to find a suitable way of versioning for an asp.net web application. |
|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 files?
It seems easy with a Desktop app but I can't seem to find a suitable way of versioning for an asp.net web application.
**NB** I'm not sure that I have been totally clear with my question.
1. What I want to know is how build and auto increment a verison number for an asp.net application.
2. I'm not interested in how to link it with svn.
|
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 set to "Nothing" instanciated objects that make referece to C/C++ code and stuff like that. It's been a long time since I touched VB6, but I remember setting files and resources to nothing.
In either case it won't hurt (if it was Nothing already), but that doesn't mean that the object will be destroyed.
VB6 had a "With/End With" statement that worked "like" the Using() statement in C#.NET. And of course, the less global things you have, the better for you.
Remember that, in either case, sometimes creating a large object is more expensive than keeping a reference alive and reusing it.
|
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_frm1. and not just set it to nothing. |
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 collection
if (c is T) {
tbs.Add((T)c);
}
}
return tbs;
}
private static void SetChildTextBoxesHeight(Control ctrl, int height) {
foreach (TextBox t in GetChildTextBoxes<TextBox>(ctrl)) {
t.Height = height;
}
} |
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. They often hide serious memory exceptions.
- Check [Advanced Windows Debugging][2] - there are lots of great tips for problems like yours. I recomend this with all my heart.
- If you use STL try STLPort and checked builds. Invalid iterator are hell.
Good luck. Problems like yours take us months to solve. Be ready for this...
[1]: http://www.microsoft.com/downloads/details.aspx?FamilyID=e089ca41-6a87-40c8-bf69-28ac08570b7e&displaylang=en
[2]: http://www.amazon.com/Advanced-Debugging-Addison-Wesley-Microsoft-Technology/dp/0321374460 |
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 does the same thing as SetForeGroundWindow, but it doesn't do anything if your application isn't the frontmost application. Finally, BringWindowToTop only brings the window to the top, and doesn't change the keyboard focus. |
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);
else
throw new Exception("Invalid Column #" + (column + 1).ToString());
}
|
> 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. Why write code for something you've paid for?
What if it's not a commercial library, but an open source one? What if the patch to be applied is not from the releasing entity (e.g. your own 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)
{
//the Converts to double and back to int are just so Floor() can be used
Double value = Convert.ToDouble((n-1) / 26);
int firstLetterVal = Convert.ToInt32(Math.Floor(value))-1;
firstLetter = Convert.ToChar(firstLetterValue + 65).ToString();
}
//second letter repeats
int secondLetterValue = (n-1) % 26;
String secondLetter = Convert.ToChar(secondLetterValue+65).ToString();
return firstLetter + secondLetter;
}
|
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, many white rabbits going on a hunch...the let me down more times than they've been right.
|
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.urlopen('http://www.example.com/sound.mp3')
mp3 = response.read()
Will work fine. Or, if you don't want to deal with the "response" object you can call **read()** directly:
import urllib
mp3 = urllib.urlopen('http://www.example.com/sound.mp3').read() |
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 to run a whole conversion to XML every time I hit a key. Easier just to tie input and output directly to my in-memory DOM tree.
Edit:
Oh, and the only problem with XHTML is that I do want to support basic pagination. Though I guess there's nothing stopping me with using some additional tags for that... |
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 <Window.Resources> section directly:
myTreeViewControl.ItemTemplate = this.Resources["SomeTemplate"] as DataTemplate;
If it's somewhere deep within your window, like in a <Grid.Resources> section or something, I think this'll work:
myTreeViewControl.ItemTemplate = this.FindResource("SomeTemplate") as DataTemplate;
And if it's elsewhere in your application, I *think* App.FindResource("SomeTemplate") will work.
|
[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-us/library/ms950721.aspx
|
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>
</head>
<body>
</body>
</html>
Notice the extra comma in the array declaration.
The code above gives different outputs for various browsers:
Safari: 5
Firefox: 5
IE: 6
The extra comma in the array is being ignored by Safari and FF while IE treats it as another object in the array.
On some search, I have found mixed opinions about which answer is correct. Most people say that IE is correct but then Safari is also doing the same thing as Firefox. I haven't tested this on other browsers like Opera but I assume that there are discrepancies.
My questions:
1. Which one of these is correct?
2. Are there any other such Javascript browser quirks that I should be wary of?
3. How do I avoid errors such as these?
|
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>
</head>
<body>
</body>
</html>
Notice the extra comma in the array declaration.
The code above gives different outputs for various browsers:
Safari: 5
Firefox: 5
IE: 6
The extra comma in the array is being ignored by Safari and FF while IE treats it as another object in the array.
On some search, I have found mixed opinions about which answer is correct. Most people say that IE is correct but then Safari is also doing the same thing as Firefox. I haven't tested this on other browsers like Opera but I assume that there are discrepancies.
My questions:
i. **Which one of these is correct?**
*Edit: By general consensus (and ECMAScript guidelines) we assume that IE is again at fault.*
ii. **Are there any other such Javascript browser quirks that I should be wary of?**
*Edit: Yes, there are loads of Javascript quirks. [www.quirksmode.org][1] is a good resource for the same.*
iii. **How do I avoid errors such as these?**
*Edit: Use [JSLint][2] to validate your javascript. Or, use some external [libraries][3]. Or, [sanitize][4] your code.*
*Thanks to [DamienB][5], [JasonBunting][8], [John][7] and [Konrad Rudolph][6] for their inputs.*
[1]: http://www.quirksmode.org
[2]: http://www.jslint.com/
[3]: http://openjsan.org/
[4]: http://stackoverflow.com/questions/29053/javascript-browser-quirks-arraylength#29062
[5]: http://stackoverflow.com/users/3069/damien-b
[6]: http://stackoverflow.com/users/1968/konrad-rudolph
[7]: http://stackoverflow.com/users/2168/john
[8]: http://stackoverflow.com/users/1790/jasonbunting |
"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 the full class name is more helpful as it documents the code better than 'var' does.
I feel that it's up to the developer to make the decision. There is no silver bullet. No "one true way".
Cheers! |
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 type is specified except in a single place, which follows the Don't Repeat Yourself principle.
Any single line statement where a type's name can be specified for both a variable and its value should definitely use var, especially when it's a long Generic< OtherGeneric< T,U,V>, Dictionary< X, Y>>> |
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, I don't think the reasons I've heard to date apply. Instead, I do my best to avoid any resizing, or any partition becoming too small - which is best achieved with one huge partition.
As for the size of swap and /boot - if your machine has 4GB memory, you may not want to have double that in swap. It's nonetheless wise to at least have some. Even if you nonetheless have double, you're using a total of 9GB, for 0.9% of your new drive. /boot can be smaller than 1GB, this is just my standard "will not become full, ever" size. |
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. Minimise the dependencies of your tests.
6. Mock behviour with mocks.
|
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. Minimise the dependencies of your tests.
6. Mock behviour with mocks.
|
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 concerns][3].
5. Minimise the dependencies of your tests.
6. Mock behviour with [mocks][4].
[1]: http://www.artima.com/weblogs/viewpost.jsp?thread=35578 "one"
[2]: http://en.wikipedia.org/wiki/Test-driven_development "before"
[3]: http://en.wikipedia.org/wiki/Separation_of_concerns "Separate your concerns"
[4]: http://en.wikipedia.org/wiki/Mock_object "mocks" |
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 hotfix e-mail is delivered to you within five minutes. However, sometimes unforeseen issues in e-mail delivery systems may cause delays.
> We will send the e-mail from the “hotfix@microsoft.com” e-mail account. If you use an e-mail filter or a SPAM blocker, we recommend that you add “hotfix@microsoft.com” or the “microsoft.com” domain to your safe senders list. (The safe senders list is also known as a whitelist or an approved senders list.) This will help prevent our e-mail from going into your junk e-mail folder or being automatically deleted.
I'm sure that the email is not getting caught in a spam catcher.
How long does it normally take to get one of these hotfixes? Am I waiting for some human to approve it, or something? Should I just give up and try to get the file I need some other way? |
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)
> Usually, our hotfix e-mail is delivered to you within five minutes. However, sometimes unforeseen issues in e-mail delivery systems may cause delays.
> We will send the e-mail from the “hotfix@microsoft.com” e-mail account. If you use an e-mail filter or a SPAM blocker, we recommend that you add “hotfix@microsoft.com” or the “microsoft.com” domain to your safe senders list. (The safe senders list is also known as a whitelist or an approved senders list.) This will help prevent our e-mail from going into your junk e-mail folder or being automatically deleted.
I'm sure that the email is not getting caught in a spam catcher.
How long does it normally take to get one of these hotfixes? Am I waiting for some human to approve it, or something? Should I just give up and try to get the file I need some other way? |
|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)
> Usually, our hotfix e-mail is delivered to you within five minutes. However, sometimes unforeseen issues in e-mail delivery systems may cause delays.
> We will send the e-mail from the “hotfix@microsoft.com” e-mail account. If you use an e-mail filter or a SPAM blocker, we recommend that you add “hotfix@microsoft.com” or the “microsoft.com” domain to your safe senders list. (The safe senders list is also known as a whitelist or an approved senders list.) This will help prevent our e-mail from going into your junk e-mail folder or being automatically deleted.
I'm sure that the email is not getting caught in a spam catcher.
How long does it normally take to get one of these hotfixes? Am I waiting for some human to approve it, or something? Should I just give up and try to get the file I need some other way?
(*Update*: Replaced "me@mycompany.com" with "(my correct email address)" to resolve [Martín Marconcini's][1] ambiguity.)
[1]: http://stackoverflow.com/questions/30297/ms-hotfix-delayed-delivery#30356 |
Refer to/select a drive based only on its label? (i.e., not the drive letter) |
|windows|batch-file| |