instruction stringlengths 0 30k ⌀ |
|---|
I've followed this otherwise [excellent tutorial][1] on getting Xen working with Ubuntu but am not able to get a console into my virtual machine (domU). I've got the `extra = '2 console=xvc0'` line in my /etc/xen/**hostname_here**.cfg file like they say, but am not able to get a console on it.
If I statically assign an IP to the VM I can SSH to it, but for now I need to be able to use DHCP to give it an address (and since that's what I'm trying to debug, there's the problem). I know I've got a free DHCP address (although I'm getting more at the moment), so I don't think that's the problem. I've looked on Google and the Xen forums to no avail as well.
Any ideas?
[1]: http://howtoforge.com/ubuntu-8.04-server-install-xen-from-ubuntu-repositories |
I've never come across a tool that would do the job. Instead I've used individual files, numbered so that I know which order to run them: essentially, a manual version of Rails migrations, but without the rollback.
Here's the sort of thing I'm talking about:
000-clean.sql # wipe out everything in the DB
001-schema.sql # create the initial DB objects
002-fk.sql # apply referential integrity (simple if kept separate)
003-reference-pop.sql # populate reference data
004-release-pop.sql # populate release data
005-add-new-table.sql # modification
006-rename-table.sql # another modification...
I've never actually run into any problems doing this, but it's not very elegant. It's up to you to track which scripts need to run for a given update (a smarter numbering scheme could help). It also works fine with source control.
Dealing with surrogate key values (from autonumber columns) can be a pain, since the production database will likely have different values than the development DB. So, I try never to reference a literal surrogate key value in any of my modification scripts if at all possible. |
What Craig said, plus if you do want to change the default it's in Tools -> Options -> Projects And Solutions.
I've never changed the default and never created a solution/project in the default location, which might tell you something about how relevant it is... |
Tools -> Options -> Projects & Solutions.
There is a Visual Studio Projects box. |
The best way of going through a proxy that requires authentication is using [urllib2][1] to build a custom url opener, then using that to make all the requests you want to go through the proxy. Note in particular, you probably don't want to embed the proxy password in the url or the python source code (unless it's just a quick hack).
import urllib2
def get_proxy_opener(proxyurl, proxyuser, proxypass, proxyscheme="http"):
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, proxyurl, proxyuser, proxypass)
proxy_handler = urllib2.ProxyHandler({proxyscheme: proxyurl})
proxy_auth_handler = urllib2.ProxyBasicAuthHandler(password_mgr)
return urllib2.build_opener(proxy_handler, proxy_auth_handler)
if __name__ == "__main__":
import sys
if len(sys.argv) > 4:
url_opener = get_proxy_opener(*sys.argv[1:4])
for url in sys.argv[4:]:
print url_opener.open(url).headers
else:
print "Usage:", sys.argv[0], "proxy user pass fetchurls..."
In a more complex program, you can seperate these components out as appropriate (for instance, only using one password manager for the lifetime of the application). The python documentation has [more examples on how to do complex things with urllib2][2] that you might also find useful.
[1]: http://docs.python.org/lib/module-urllib2.html
[2]: http://docs.python.org/lib/urllib2-examples.html |
I don't trust programmatic migrations. If it's a simple change, such as adding a NULLable column, I'll just add it directly to the live server. If it's more complex or requires data changes, I'll write a pair of SQL migration files and test them against a replica database.
When using migrations, *always* test the rollback migration. It is your emergency "oh shit" button. |
Run Purify.
It is a near-magical tool that will report when you are clobbering memory you shouldn't be touching, leaking memory by not freeing things, double-freeing, etc.
It works at the machine code level, so you don't even have to have the source code.
One of the most enjoyable vendor conference calls I was ever on was when Purify found a memory leak in their code, and we were able to ask, "is it possible you're not freeing memory in your function foo()" and hear the astonishment in their voices.
They thought we were debugging gods but then we let them in on the secret so they could run Purify before we had to use their code. :-)
<http://www-306.ibm.com/software/awdtools/purify/unix/>
(It's pretty pricey but they have a free eval download) |
E-mail Notification's |
|.net|email| |
In a .net system I'm building, there is a need for automated e-mail notifications. These should be editable by an admin. What's the easiest way to do this? SQL table and WYSIWIG for editing? |
E-mail Notifications |
How about using the new Workflow components in .Net 3.0 (and 3.5)? That is what we use in combination with templates in my current project. The templates have the basic format and the the tokens that are replaced with user information. |
The cell location is an attached property - the value belongs to the TextBlock rather than Grid. However, since the property itself belongs to Grid, you need to use either the property definition field or the provided static functions.
TextBlock tb = new TextBlock();
//
// Locate tb in the second row, third column.
// Row and column indices are zero-indexed, so this
// equates to row 1, column 2.
//
Grid.SetRow(tb, 1);
Grid.SetColumn(tb, 2); |
WPF makes use of a funky thing called [attached properties][1]. So in your XAML you might write this:
<TextBlock Grid.Row="0" Grid.Column="0" />
And this will effectively move the TextBlock into cell (0,0) of your grid.
In code this looks a little strange. I believe it'd be something like:
g.Children.Add(tb);
g.SetRow(tb, 0);
g.SetColumn(tb, 0);
Have a look at that link above - attached properties make things really easy to do in XAML perhaps at the expense of intuitive-looking code.
[1]: http://msdn.microsoft.com/en-us/library/ms749011.aspx |
WPF makes use of a funky thing called [attached properties][1]. So in your XAML you might write this:
<TextBlock Grid.Row="0" Grid.Column="0" />
And this will effectively move the TextBlock into cell (0,0) of your grid.
In code this looks a little strange. I believe it'd be something like:
g.Children.Add(tb);
Grid.SetRow(tb, 0);
Grid.SetColumn(tb, 0);
Have a look at that link above - attached properties make things really easy to do in XAML perhaps at the expense of intuitive-looking code.
[1]: http://msdn.microsoft.com/en-us/library/ms749011.aspx |
How to structure a java application, in other words: where do I put my classes? |
following on from my [previous question](http://stackoverflow.com/questions/19454/enforce-attribute-decoration-of-classesmethods) I have been working on getting my object model to serialize to XML. But I have now run into a problem (quelle surprise!).
The problem I have is that I have a collection, which is of a abstract base class type, which is populated by the concrete derived types.
I thought it would be fine to just add the XML attributes to all of the classes involved and everything would be peachy. Sadly, thats not the case!
So I have done some digging on Google and I now understand _why_ it's not working.. In that **the _XmlSerializer_ is in fact doing some clever reflection in order to serialize objects to/from XML, and since its based on the abstract type, it cannot figure out what the hell it's talking to**. Fine.
I did come across [this page](http://www.codeproject.com/KB/XML/xmlserializerforunknown.aspx) on CodeProject, which looks like it may well help a lot (yet to read/consume fully), but I thought I would like to bring this problem to the StackOverflow table too, to see if you have any neat hacks/tricks in order to get this up and running in the quickest/lightest way possible :)
There seems to be a lot of "Animal/Mammal", "Car/Bike/Truck" examples but not a lot of fresh ideas!
Thanks a lot people :)
###EDIT:
One thing I should also add is that I **DO NOT** want to go down the _XmlInclude_ route.. There is simply too much coupling with it, and this area of the system is under heavy development, so the it would be a real maintenence headache!
_ _ _
##Problem Solved!
OK, so I finally got there (admittedly with a **lot** of help from [here](http://www.codeproject.com/KB/XML/xmlserializerforunknown.aspx)!).
So summarise:
###Goals:
- I didn't want to go down the _XmlInclude_ route due to the maintenence headache.
- Once a solution was found, I wanted it to be quick to implement in other applications.
- Collections of Abstract types may be used, as well as individual abstract properties.
- I didn't really want to bother with having to do "special" things in the concrete classes.
###Identified Issues/Points to Note:
- _XmlSerializer_ does some pretty cool reflection, but it is _very_ limited when it comes to abstract types (i.e. it will only work with instances of the abstract type itself, not subclasses).
- The Xml attribute decorators define how the XmlSerializer treats the properties its finds. The physical type can also be specified, but this creates a **tight coupling** between the class and the serializer (not good).
- We can implement our own XmlSerializer by creating a class that implements _IXmlSerializable_ .
##The Solution
I created a generic class, in which you specify the generic type as the abstract type you will be working with. This gives the class the ability to "translate" between the abstract type and the concrete type since we can hard-code the casting (i.e. we can get more info than the XmlSerializer can).
I then implemented the _IXmlSerializable_ interface, this is pretty straight forward, but when serializing we need to ensure we write the type of the concrete class to the XML, so we can cast it back when de-serializing. It is also important to note it must be **fully qualified** as the assemblies that the two classes are in are likely to differ. There is of course a little type checking and stuff that needs to happen here.
Since the XmlSerializer cannot cast, we need to provide the code to do that, so the implicit operator is then overloaded (I never even knew you could do this!).
The code for the AbstractXmlSerializer is this:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
namespace Utility.Xml
{
public class AbstractXmlSerializer<AbstractType> : IXmlSerializable
{
// Override the Implicit Conversions Since the XmlSerializer
// Casts to/from the required types implicitly.
public static implicit operator AbstractType(AbstractXmlSerializer<AbstractType> o)
{
return o.Data;
}
public static implicit operator AbstractXmlSerializer<AbstractType>(AbstractType o)
{
return o == null ? null : new AbstractXmlSerializer<AbstractType>(o);
}
private AbstractType _data;
/// <summary>
/// [Concrete] Data to be stored/is stored as XML.
/// </summary>
public AbstractType Data
{
get { return _data; }
set { _data = value; }
}
/// <summary>
/// **DO NOT USE** This is only added to enable XML Serialization.
/// </summary>
/// <remarks>DO NOT USE THIS CONSTRUCTOR</remarks>
public AbstractXmlSerializer()
{
// Default Ctor (Required for Xml Serialization - DO NOT USE)
}
/// <summary>
/// Initialises the Serializer to work with the given data.
/// </summary>
/// <param name="data">Concrete Object of the AbstractType Specified.</param>
public AbstractXmlSerializer(AbstractType data)
{
_data = data;
}
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
return null; // this is fine as schema is unknown.
}
public void ReadXml(System.Xml.XmlReader reader)
{
// Cast the Data back from the Abstract Type.
string typeAttrib = reader.GetAttribute("type");
// Ensure the Type was Specified
if (typeAttrib == null)
throw new ArgumentNullException("Unable to Read Xml Data for Abstract Type '" + typeof(AbstractType).Name +
"' because no 'type' attribute was specified in the XML.");
Type type = Type.GetType(typeAttrib);
// Check the Type is Found.
if (type == null)
throw new InvalidCastException("Unable to Read Xml Data for Abstract Type '" + typeof(AbstractType).Name +
"' because the type specified in the XML was not found.");
// Check the Type is a Subclass of the AbstractType.
if (!type.IsSubclassOf(typeof(AbstractType)))
throw new InvalidCastException("Unable to Read Xml Data for Abstract Type '" + typeof(AbstractType).Name +
"' because the Type specified in the XML differs ('" + type.Name + "').");
// Read the Data, Deserializing based on the (now known) concrete type.
reader.ReadStartElement();
this.Data = (AbstractType)new
XmlSerializer(type).Deserialize(reader);
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
// Write the Type Name to the XML Element as an Attrib and Serialize
Type type = _data.GetType();
// BugFix: Assembly must be FQN since Types can/are external to current.
writer.WriteAttributeString("type", type.AssemblyQualifiedName);
new XmlSerializer(type).Serialize(writer, _data);
}
#endregion
}
}
So, from there, how do we tell the XmlSerializer to work with our serializer rather than the default? We must pass our type within the Xml attributes type property, for example:
[XmlRoot("ClassWithAbstractCollection")]
public class ClassWithAbstractCollection
{
private List<AbstractType> _list;
[XmlArray("ListItems")]
[XmlArrayItem("ListItem", Type = typeof(AbstractXmlSerializer<AbstractType>))]
public List<AbstractType> List
{
get { return _list; }
set { _list = value; }
}
private AbstractType _prop;
[XmlElement("MyProperty", Type=typeof(AbstractXmlSerializer<AbstractType>))]
public AbstractType MyProperty
{
get { return _prop; }
set { _prop = value; }
}
public ClassWithAbstractCollection()
{
_list = new List<AbstractType>();
}
}
Here you can see, we have a collection and a single property being exposed, and all we need to do is add the _type_ named parameter to the Xml declaration, easy! :D
**NOTE: If you use this code, I would really appreciate a shout-out. It will also help drive more people to the community :)**
Now, but unsure as to what to do with answers here since they all had their pro's and con's. I'll upmod those that I feel were useful (no offence to those that weren't) and close this off once I have the rep :)
Interesting problem and good fun to solve! :) |
If you want to have a go at doing a highly parallel version of a simple task, or see real solutions, you could do worse than look at the [wide finder](http://www.tbray.org/ongoing/When/200x/2007/09/20/Wide-Finder) project. Basically it's about how to do parallel regex matching of log files efficiently, but trying to add as little code as possible.
Participants have submitted solutions in many different languages and the [performance results](http://www.tbray.org/ongoing/When/200x/2007/10/30/WF-Results) are posted. The original project has now finished and there is now [wide finder 2](http://www.tbray.org/ongoing/When/200x/2008/05/01/Wide-Finder-2) taking the work on.
[CodingHorror](http://www.codinghorror.com/) has a good [introduction to wide finder](http://www.codinghorror.com/blog/archives/001131.html). |
Use the following script.
<SCRIPT TYPE="text/javascript">
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
{
myfield.form.submit();
return false;
}
else
return true;
}
//-->
</SCRIPT>
For each field that should submit the form when the user hits enter, call the submitenter function as follows.
<FORM ACTION="../cgi-bin/formaction.pl">
name: <INPUT NAME=realname SIZE=15><BR>
password: <INPUT NAME=password TYPE=PASSWORD SIZE=10
onKeyPress="return submitenter(this,event)"><BR>
<INPUT TYPE=SUBMIT VALUE="Submit">
</FORM> |
Can Slickedit automatically update it's tag files? |
|slickedit|ide| |
I prefer SlickEdit for my IDE but the only way I can get it to update the tag files to incorporate code changes is to recreate the project and/or run start a re-tag manually. Is there a way to setup Slick Edit so that it automatically incorporates changes in the code base that happen after project creation.
This problem is especially noticeable when working on large shared code bases where I must check out files that have been modified by other users. |
|slickedit|ide|fix-title-typo| |
Can SlickEdit automatically update its tag files? |
|ide|slickedit| |
Take a look at HUDSON (https://hudson.dev.java.net/) . It's highly customizable, and, i my humble opinion, easier than CruiseControl. |
Not sure why you are wanting to do this - regex for HTML sanitisation isn't always the best method (you need to remember to sanitise attributes and such, remove javascript: hrefs and the likes)... but, a regex to match HTML tags that aren't `<p></p>`:
`(<[^pP].*?>|</[^pP]>)`
Verbose:
(
< # < opening tag
[^pP].*? # p non-p character, then non-greedy anything
> # > closing tag
| # ....or....
</ # </
[^pP] # a non-p tag
> # >
)
|
Create an assembly using VS.NET.
Add an installer class to the project - select 'Add - New Item'. Select intaller class.
This class derives from System.Configuration.Install.Installer. It has a number of virtual methods such as Install(). This will be called when by the windows installer engine at install time.
This assembly can then be added to your Windows Installer project as a custom action.
Sorry this is a little brief. |
There is support for exactly this in .NET/Windows Installer
Create an assembly using VS.NET.
Add an installer class to the project - select 'Add - New Item'. Select intaller class.
This class derives from System.Configuration.Install.Installer. It has a number of virtual methods such as Install(). This will be called when by the windows installer engine at install time.
This assembly can then be added to your Windows Installer project as a custom action.
Sorry this is a little brief. |
There is support for exactly this in .NET/Windows Installer
Create an assembly using VS.NET.
Add an installer class to the project - select 'Add - New Item'. Select intaller class.
This class derives from System.Configuration.Install.Installer. It has a number of virtual methods such as Install(). This will be called when by the windows installer engine at install time.
This assembly can then be added to your Windows Installer project as a custom action. The method used to declare the custom action as a .NET installer class depends on the tool you are using to create the installation.
Sorry this is a little brief. |
Does make think one of the targets is failing? If so, it will stop the make after the running jobs finish. You can use -k to tell it to continue even if an error occurs. |
I do think that games and puzzles are a good place to start as they can give great scope for developing more complex versions. For example a **tic-tac-toe** program can be built as a simple command line program initially that lets two players play the game.
This step can be used to show how a simple data structure or array can represent the game board, simple input to get user commands/moves, simple output to display the game board and prompts etc. Then you can start showing how an algorithm can be used to allow player vs computer mode. I like the simple magic square math algorithm for **tic-tac-toe** as it's based on *very* simple math. After this the sky's the limit, UI improvements, using file I/O to load and save games, more advanced algorithms to get the computer to play better etc. More complex and satisfying games can still be produced using text mode or simple graphics.
I've used the **Sokoban** game as a means of showing lots of techniques over the years.
The simplest game I've used is a number list reversing game. This involves a mixed up list of numbers from 1-9. The player can specify a number of digits to reverse on the left of the list. The aim is to get the list sorted. This is great for absolute beginners. Each little part of the game can be written and tested separately.
|
When ever I need to do something similar, usually I end up using <a href="http://search.cpan.org/~ebohlman/XML-Parser-EasyTree-0.01/EasyTree.pm">XML::Parser::EasyTree </a> it has better documentation and is simpler to use.
I highly recommend it. |
What control is this? ("Open" Button with Drop Down) |
|.net|.net-2.0|winforms| |
|.net|winforms|.net-2.0| |
The "Open" button on the open file dialog used in certain windows applications includes a dropdown arrow with a list of additional options -- namely "Open with..".
I haven't seen this in every windows application, so you may have to try a few to get it, but SQL Server Management Studio and Visual Studio 2005 will both show the button that way if you go to the menu and choose _File->Open->File..._
I want to use a button like this with a built-in list in one of my applications, but I can't find the control they're using anywhere in visual studio. I should clarify that I'm looking for that specific button, not the entire dialog. Any thoughts? |
Any pitfalls developing C#/.NET code in a Virtual Machine running on a MAC? |
|macos|.net|vmware|vista| |
I am considering buying an Apple MAC book Pro, are than any pitfalls developing C#/.NET code in a Virtual Machine running on a MAC?
For this purpose, is it better to run Vista or XPPro? |
|.net|macos|vmware| |
I found the answer here: http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/
You just concatenate the string and insert a CHAR(13) where you want your line break. Example:
DECLARE @text NVARCHAR(100)
SET @text = 'This is line 1.' + CHAR(13) + 'This is line 2.'
SELECT @text
This prints out the following:
This is line 1.
This is line 2. |
I found the answer here: http://blog.sqlauthority.com/2007/08/22/sql-server-t-sql-script-to-insert-carriage-return-and-new-line-feed-in-code/
You just concatenate the string and insert a CHAR(13) where you want your line break. Example:
DECLARE @text NVARCHAR(100)
SET @text = 'This is line 1.' + CHAR(13) + 'This is line 2.'
SELECT @text
This prints out the following:
This is line 1.
This is line 2. |
Use more generics
abstract class Vehicle<T> where T : Axle
{
public string Name;
public List<T> Axles;
}
class Motorcycle : Vehicle<MotorcycleAxle>
{
}
class Car : Vehicle<CarAxle>
{
}
abstract class Axle
{
public int Length;
public void Turn(int numTurns) { ... }
}
class MotorcycleAxle : Axle
{
public bool WheelAttached;
}
class CarAxle : Axle
{
public bool LeftWheelAttached;
public bool RightWheelAttached;
} |
> but is it good or bad
The first adjective that comes to mind is "unnecessary". C++ has free functions and namespaces, so why would you need to make them static functions in a class?
The use of static methods in uninstantiable classes in C# and Java _is a workaround_ because those languages don't have free functions (that is, functions that reside directly in the namespace, rather than as part of a class). C++ doesn't have that flaw. Just use a namespace.
|
Why Subversion over VSS?
* Free software
* Easier to manage
* "check-ins" are <b>atomic</b>!
* Easy to Branch and Merge
* Continued development (i.e. VSS is dead end)
* Better tools for tracking changes and viewing logs
* Toolset and platform agnostic, but also integrates with many tools
I made the proposal to my manager, and it was a pretty easy sell. I've found it to be much easier to use, especially for branching (our project took 5 hours to "share and pin" in VSS, and then each operation took extra time to complete!). |
version control practice |
|version-control| |
In my current job the supervisor's practice is to only check in production ready code. Most recently the project I was on involved work by 3 different developers with some file overlap. This meant manually integrating changes despite the fact that some changes took a day and then it was done. I wanted to see if this was a common practice and get suggestions on how to change this practice with the knowledge that many times my opinion means little in the grand scheme of things. |
Code that is checked in should be unit tested, but, to me, "production ready" implies that it's gone through integration and system testing. You can't do that until a code freeze, so I don't see how you can do that before every check in. |
You can try WMICodeCreator it generates vbscript jscript vb.net and c# code
[Download WMICodeCreator from Microsoft][1]
[1]: http://www.microsoft.com/downloads/details.aspx?familyid=2cc30a64-ea15-4661-8da4-55bbc145c30e&displaylang=en |
How to start using ndepend? |
|.net|static-analysis|ndepend| |
I recently downloaded ndepend and ran an analysis on an open source project I participate in.
I did not now where to look next - a bit of visual and information overload and it turned out I don't even know where to start.
Can anyone suggest starting points?
- What information should I look for first?
- What points out problems in the code (in a BIG way)?
- What would the low hanging fruit that can immediately seen?
|
OK, rails is actually pretty good, but there is just a little bit too much magic going on in there (from the Ruby world I would much prefer merb to rails). I personally use Pylons, and am pretty darn happy. I'd say (compared to django), that pylons allows you to interchange ints internal parts easier than django does. The downside is that you will have to write more stuff all by youself (like the basic CRUD).
Pros of using a framework:
1. get stuff done quickly (and I mean lighning fast once you know the framework)
1. everything is compying to standards (which is probably not that easy to achieve when rolling your own)
1. easier to get something working (lots of tutorials) without reading gazillion articles and docs
Cons:
1. you learn less
1. harder to replace parts (not that much of an issue in pylons, more so with django)
1. harder to tweak some low-level stuff (like the above mentioned SQLs)
From that you can probably devise what they are good for :-) Since you get all the code it is possible to tweak it to fit even the most bizzare situations (pylons supposedly work on the Google app engine now...). |
Windows Mobile and CE used to suck, really, really badly. These days however it's definitely passable and worth checking out, especially if you code C#.
Just remember that it is the baby brother of the full framework and has nowhere near enough toys and throws a lot of NotImplementedExceptions. :) |
Guids will certainly be slower (and use more memory) than standard integer keys, but whether or not that is an issue will depend on the type of load your system will see. Depending on your backend DB there may be issues with indexing guid fields.
Using guids simplifies a whole class of problems, but you pay for it part will performance and also debuggability - typing guids into those test queries will get old real fast! |
This is a perfectly good use of GUIDs. The only draw backs would be a slight complexity in working with GUIDs over INTs and the slight size difference (16 bytes vs 4 bytes).
I don't think either of those are a big deal. |
Quick ls command |
|unix|ls|command| |
I've got to get a directory listing that contains about 2 million files, but when I do an "ls" command on it nothing comes back. I've waited 3 hours. I've tried "ls | tee directory.txt", but that seems to hang forever. I assume the server is doing a lot of inode sorting. Is there any way to speed up the ls command to just get a directory listing of filenames? I don't care about size, dates, permission or the like at this time.
Thanks,
Mark
|
|unix|bash|command|ls| |
If the pages are static, why would you change them on the fly instead of preprocessing all pages on a site, adding the piece of requiered javascript to each one of them? This is simple and probably more efficent (you probably have more pageviews than pages to change)
This could be done a lots of way. I would suggest a small perl to to inline replacement.
|
Try upgrading to jQuery 1.2.6, you should be on the latest release of jQuery if you are having problems first ensure you are on the latest and greatest. |
How many constructor arguments is too many? |
|untagged| |
Let's say you have a class called Customer, which contains the following fields:
- UserName
- Email
- First Name
- Last Name
Let's also say that according to your business logic, all Customer objects must have these four properties defined.
Now, we can do this pretty easily by forcing the constructor to specify each of these properties. But it's pretty easy to see how this can spiral out of control when you are forced to add more required fields to the Customer object.
I've seen classes that take in 20+ arguments into their constructor and it's just a pain to use them. But, alternatively, if you don't require these fields you run into the risk of having undefined information, or worse, object referencing errors if you rely on the calling code to specify these properties.
Are there any alternatives to this or do you you just have to decide whether X amount of constructor arguments is too many for you to live with? |
One thing you need to keep in mind is the size of your data set. I believe that Dillie-O was the only one who even remotely hit the point.
If you have a small, single user, consumer app then I would say DB. I have a DVD management app that uses the file system (in Program Files at that) and it is a PIA to backup. I wish EVERY time that they would store them in a db, and let me choose where to save that file.
For a larger commercial application then I would start to change my thinking. I used to work for a company that developed the county clerks information management application. We would store the images on disk, in an encoded format [to deal with FS problems with large numbers of files] based on the county assigned instrument number. This was useful on another front as the image could exist before the DB record (due to their workflow).
As with most things: 'It depends on what you are doing' |
Or if using the Visual Studio command line,
cl.exe /Fa[assembler code filename]
If you just want to view the assembler code in the IDE you can start the debugger and then select the Go To Dissassembly choice on the right click menu. |
You might also want to add a way to pin and unpin that 64-bit pointer to a 32-bit memory address. Since this is Delphi, I'm pretty sure it's Windows specific, so you might as well use [Address Windowing Extensions][1]. That way, you can support allocating, freeing, and pinning and unpinning memory to a 32-bit address range and still take advantage of a 64-bit memory allocation space. Assuming that the user will actually commit the memory such that it fits in the 32-bit virtual address space.
MSN
[1]: http://msdn.microsoft.com/en-us/library/aa366527(VS.85).aspx |
What areas of specialization within programming would you recommend to a beginner |
|language-agnostic|education| |
I am a student studying software development, and I feel programming, in general, is too broad of a subject to try to know everything. To be proficient, you have to decide which areas to focus your learning and understanding. Certain skill sets synergize with each other, like data-driven web development and SQL experience. However, all the win32 API experience in the world may not directly apply to linux development. This leads me to believe, as a beginning programmer, I should start deciding where I want to specialize after I have general understanding of the basic principles of software development.
This is a multi-part question really. What are the common specializations within computer programming and software development. Which of these specializations have more long-term value, both as a foundation for other specializations and/or as marketable skills. Which skill sets complement each other. Are there any areas of specialization that hinder your ability of developing other areas of specialization. |
|language-agnostic|education| |
I am a student studying software development, and I feel programming, in general, is too broad of a subject to try to know everything. To be proficient, you have to decide which areas to focus your learning and understanding. Certain skill sets synergize with each other, like data-driven web development and SQL experience. However, all the win32 API experience in the world may not directly apply to linux development. This leads me to believe, as a beginning programmer, I should start deciding where I want to specialize after I have general understanding of the basic principles of software development.
This is a multi-part question really:
1. What are the common specializations within computer programming and software development?
2. Which of these specializations have more long-term value, both as a foundation for other specializations and/or as marketable skills?
3. Which skill sets complement each other?
4. Are there any areas of specialization that hinder your ability of developing other areas of specialization. |
|java|architecture| |
First of all, I know how to build a java application. But I was always puzzled where to put my classes. There are proponents for organizing the packages strictly domain oriented, others separate by tier.
I for myself have always problems a) with naming, b) with placing
Where do you put your domain specific constants (and what is the best name for such a class)? Where do you put classes for stuff which is both infrastructural and domain specific (for instance I have a FileStorageStrategy class, which stores the files either in the database, or alternatively in database)? Where to put Exceptions?
Are there any standards to which I can refer? |
Is there a reason you can't just send the data to a page which handles sending the mail? It is pretty easy to send an email in most languages, so unless there's a strong reason to push it to client side, I would recommend that route. |
Use attached properties of the Grid class.
in C#:
`Grid.SetRow( cell, rownumber )`
In XAML:
`<TextBlock Grid.Row="1" />`
Also, I would advice if you do not use dynamic grids, use the XAML markup language. I know, it has a learning curve, but once you mastered it, it is so much easier, especially if you are going to use ControlTemplates and DataTemplates! ;) |
Use attached properties of the Grid class.
in C#:
<pre><code>Grid.SetRow( cell, rownumber )</code></pre>
In XAML:
<pre><code><TextBlock Grid.Row="1" /></code></pre>
Also, I would advice if you do not use dynamic grids, use the XAML markup language. I know, it has a learning curve, but once you mastered it, it is so much easier, especially if you are going to use ControlTemplates and DataTemplates! ;) |
Class names should always be descriptive and self-explanatory. If you have multiple domains of responsibility for your classes then they should probably be refactored.
Likewise for you packages. They should be grouped by domain of responsibility. Every domain has it's own exceptions.
Generally don't sweat it until you get to a point where it is becoming overwhelming and bloated. Then sit down and don't code, just refactor the classes out, compiling regularly to make sure everything works. Then continue as you did before. |
Another possibility is to use DTS or Integration Services (DTS for SQL Server 7 or 2000, SSIS for 2005 or higher). Both are from Microsoft, included in the Sql Server installation (in Standard edition at least) and have an FTP task and are designed for import/export jobs from Sql Server. |
I think the best introduction to the (any) subject are some good examples.
[This article][1] at codeProject gives a fairly easy to follow guide trough web service security for a .NET application.
[1]: http://www.codeproject.com/KB/webservices/WS-Security.aspx |
Use packages to group related functionality together.
Usually the top of your package tree is your domain name reversed (`com.domain.subdomain`) to guarantee uniqueness, and then usually there will be a package for your application. Then subdivide that by related area, so your `FileStorageStrategy` might go in, say, `com.domain.subdomain.myapp.storage`, and then there might be specific implementations/subclasses/whatever in `com.domain.subdomain.myapp.storage.file` and `com.domain.subdomain.myapp.storage.database`. These names can get pretty long, but `import` keeps them all at the top of files and IDEs can help to manage that as well.
Exceptions usually go in the same package as the classes that throw them, so if you had, say, `FileStorageException` it would go in the same package as `FileStorageStrategy`. Likewise an interface defining constants would be in the same package.
There's not really any standard as such, just use common sense, and if it all gets too messy, refactor! |
To submit the form when the enter key is pressed create a javascript function along these lines.
<pre><code>
function checkSubmit(e)
{
if(e && e.keyCode == 13)
{
document.forms[0].submit();
}
}
</code></pre>
Then add the event to whatever scope you need eg on the div tag
<pre><code><div onKeyPress="return checkSubmit(event)"/></code></pre>
This is also the default behaviour of internet explorer 7 anyway though (probably earlier versions as well). |
I believe you suffer from having a different instance of the VCL in each of your dlls and exes. Classes from the dll are not the same as the ones from your exe, even if they are called the same. Also global variables (Application, Screen) are not shared between them. Neither is the memory since they both have their own memory manager.
The solution is to have the dlls and the exe share the VCL library and the memory manager. I am not a BCB developer, but a Delphi developer. In Delphi we would just use the rtl and the vcl as runtime packages. Maybe you could do the BCB equivalent. |
From the code you've posted, it's not clear that after an exception is thrown the system is definitely able to restart - e.g. if the exception comes from doStuff(), then the control flow will pass back (after the 10 minute wait) to openConnection(), without ever passing through closeConnection().
But as others have said, just attach a debugger and find where it actually is. |
[Sharepoint][1] also does a good (ok decent) job of versioning MS-specific documents.
[1]: http://office.microsoft.com/en-us/sharepointtechnology/default.aspx |
<pre>
ssize_t
recvfrom(int socket, void *restrict buffer, size_t length, int flags,
struct sockaddr *restrict address, socklen_t *restrict address_len);
ssize_t
recvmsg(int socket, struct msghdr *message, int flags);
[..]
If address is not a null pointer and the socket is not connection-oriented, the
source address of the message is filled in.
</pre>
<code>
int nbytes = recvfrom(sock, buf, MAXBUFSIZE, MSG_WAITALL, (struct sockaddr *)&bindaddr, &addrlen);
fprintf(stdout, "Read %d bytes on %s\n", nbytes, inet_ntoa(bindaddr.sin_addr.s_addr));
</code>
hope this helps. |
<pre>
ssize_t
recvfrom(int socket, void *restrict buffer, size_t length, int flags,
struct sockaddr *restrict address, socklen_t *restrict address_len);
ssize_t
recvmsg(int socket, struct msghdr *message, int flags);
[..]
If address is not a null pointer and the socket is not connection-oriented, the
source address of the message is filled in.
</pre>
Actual code:
<code>
int nbytes = recvfrom(sock, buf, MAXBUFSIZE, MSG_WAITALL, (struct sockaddr *)&bindaddr, &addrlen);
fprintf(stdout, "Read %d bytes on local address %s\n", nbytes, inet_ntoa(bindaddr.sin_addr.s_addr));
</code>
hope this helps. |
http://www.yoda.arachsys.com/csharp/threads/ |
I use TeamCity with an nant build script. TeamCity makes it easy to setup the CI server part, and nant build script makes it easy to do a number of tasks as far as report generation is concerned.
Here is an article I wrote about using CI with CruiseControl.NET, it has a nant build script in the comments that can be re-used across projects:
[Continuous Integration with CruiseControl][1]
[1]: http://www.codeproject.com/KB/cs/Continuous_Integration.aspx |
+1 for Umbraco as a great CMS. As far as multilingual support though, I'm in the same boat as seanb. I know it supports it, but I've never dealt with it myself. |
I would personally not approve of this because sometimes that's the best way to catch problem code with less experienced developers (by seeing it as they are working on it) and when you "check in early and often" you can rollback to earlier changes you made (as you were developing) if you decide that some changes you made earlier was actually a better idea. |
wouldn't it be a good idea to have a testing branch of the repo that can have the non "production ready code" checked in after the changes are done and tested?
the main trunk should never have code checked in that breaks the build and doesn't pass unit tests, but branches don't have to have all those restrictions in place. |
Identifying ASP.NET web service references |
|web-services|iis|reflection|esb| |
At my day job we have load balanced web servers which talk to load balanced app servers via web services (and lately WCF). At any given time, we have 4-6 different teams that have the ability to add new web sites or services or consume existing services. We probably have about 20-30 different web applications and corresponding services.
Unfortunately, given that we have no centralized control over this due to competing priorities, org structures, project timelines, financial buckets, etc., it is quite a mess. We have a variety of services that are reused, but a bunch that are specific to a front-end.
Ideally we would have better control over this situation, and we are trying to get control over it, but that is taking a while. One thing we would like to do is find out more about what all of the inter-relationships between web sites and the app servers.
I have used Reflector to find dependencies among assemblies, but would like to be able to see the traffic patterns between services.
What are the options for trying to map out web service relationships? For the most part, we are mainly talking about internal services (web to app, app to app, batch to app, etc.). Off the top of my head, I can think of two ways to approach it:
- Analyze assemblies for any web references. The drawback here is that not everything is a web reference and I'm not sure how WCF connections are listed. However, this would at least be a start for finding 80% of the connections. Does anyone know of any tools that can do that analysis? Like I said, I've used Reflector for assembly references but can't find anything for web references.
- Possibly tap into IIS and passively monitor the traffic coming in and out and somehow figure out what is being called and where from. We are looking at enterprise tools that could help but it would be a while before they are implemented (and cost a lot). But is there anything out there that could help out quickly and cheaply? One tool in particular (AmberPoint) can tap into IIS on the servers and monitor inbound and outbound traffic, adds a little special sauce and begin to build a map of the traffic. Very nice, but costs a bundle.
I know, I know, how the heck did you get into this mess in the first place? Beats me, just trying to help us get control of it and get out of it.
Thanks,
Matt |
Strong Validation in WPF |
|language-agnostic|education| |