instruction
stringlengths
0
30k
RSS isn't "push", which means that you need to have something that polls the website. It's much less traffic than getting the whole site or front page (for instance, you can say "Give me all articles newer than the last time I asked"), but it's traffic nonetheless. It's generally understood you shouldn't have a refresh of more than 30 minutes in an automated client. (Citation required). Having said that, you may find a client which allows you to set a more frequent refresh.
I've used [Pingie][1] in the past to send me an SMS when a new items appears in an RSS feed. Perhaps that would be useful for you if you have a cell phone text messaging plan. [1]: http://www.pingie.com
I enabled compression following similar articles to those posted above. The key to accessing the ViewState before the application sends it was overriding this method; protected override void SavePageStateToPersistenceMedium(object viewState) You can call the base method within this override and then add whatever additional logic you require to handle the ViewState.
[RSS2mail][1] is a simple python script which I used extensively a few years back. As Matthew stated you really shouldn't bother an RSS feed more than the producer allows but you can use http headers to check for changes in a very light way which is something rss2email does quite well. [1]: http://exo.org.uk/code/rss2mail/
I would also mock the database, and check that the queries are what you expected. There is the risk that the test checks the wrong sql, but this would be detected in the integration tests
I blogged about this a while back, quoting on [Todd Snyder's excellent post on the difference between the two][1]. > Here are the key differences between > the patterns: > > MVP Pattern > > - View is more loosely coupled to the model. The presenter is > responsible for binding the model to > the view. > - Easier to unit test because interaction with the view is through > an interface > - Usually view to presenter map one to one. Complex views may have > multi presenters. > > MVC Pattern > > - Controller are based on behaviors and can be shared across > views > - Can be responsible for determining which view to display Best explanation on the web I could find. [1]: http://blogs.infragistics.com/blogs/tsnyder/archive/2007/10/17/mvc-or-mvp-pattern-whats-the-difference.aspx
You could always knock something up yourself... I've done it in the past and it really isn't too difficult a job to write an RSS parser. Of course, as others have mentioned, there's an etiquette question as to how much of the website's valuable bandwidth you want to hog for yourself in RSS request traffic. That's a matter for your own conscience. ;)
Both of these frameworks aim to seperate concerns - for instance, interaction with a data source (model), application logic (or turning this data into useful information) (Controller/Presenter) and display code (View). In some cases the model can also be used to turn a data source into a higher level abstraction as well. A good example of this is the [MVC Storefront project][1]. There is a discussion [here][2] regarding the differences between MVC vs MVP. The distinction made is that in an MVC application traditionally has the view and the controller interact with the model, but not with each other. MVP designs have the Presenter access the model and interact with the view. Having said that, ASP.NET MVC is by these definitions an MVP framework because the Controller accesses the Model to populate the View which is meant to have no logic (just displays the variables provided by the Controller). To perhaps get an idea of the ASP.NET MVC distinction from MVP, check out [this early MIX presentation][3] (Silverlight) by Scott Gu on ASP.NET MVC (accessed from [this][4] Scott Hanselman's blog post). [1]: http://blog.wekeroad.com/mvc-storefront/ [2]: http://codebetter.com/blogs/jeremy.miller/archive/2007/10/31/development-trivial-pursuit-the-difference-between-mvc-and-the-different-flavors-of-mvp.aspx [3]: http://www.hanselman.com/silverlight/ScottGuAtAltnetConf/ [4]: http://www.hanselman.com/blog/ScottGuMVCPresentationAndScottHaScreencastFromALTNETConference.aspx
Both of these frameworks aim to seperate concerns - for instance, interaction with a data source (model), application logic (or turning this data into useful information) (Controller/Presenter) and display code (View). In some cases the model can also be used to turn a data source into a higher level abstraction as well. A good example of this is the [MVC Storefront project][1]. There is a discussion [here][2] regarding the differences between MVC vs MVP. The distinction made is that in an MVC application traditionally has the view and the controller interact with the model, but not with each other. MVP designs have the Presenter access the model and interact with the view. Having said that, ASP.NET MVC is by these definitions an MVP framework because the Controller accesses the Model to populate the View which is meant to have no logic (just displays the variables provided by the Controller). To perhaps get an idea of the ASP.NET MVC distinction from MVP, check out [this MIX presentation][3] by Scott Hanselman. [1]: http://blog.wekeroad.com/mvc-storefront/ [2]: http://codebetter.com/blogs/jeremy.miller/archive/2007/10/31/development-trivial-pursuit-the-difference-between-mvc-and-the-different-flavors-of-mvp.aspx [3]: http://www.hanselman.com/blog/ASPNETMVCSessionAtMix08TDDAndMvcMockHelpers.aspx [4]: http://www.hanselman.com/blog/ScottGuMVCPresentationAndScottHaScreencastFromALTNETConference.aspx
MVP = Model-View-Presenter MVC = Model-View-Controller 1. Both presentation patterns. They separate the dependencies between a Model (think Domain objects), your screen/web page (the View), and how your UI is supposed to behave (Presenter/Controller) 2. They are fairly similar in concept, folks initialize the Presenter/Controller differently depending on taste. 3. A great article on the differences is [here][1]. Most notable is that MVC pattern has the Model updating the View. [1]: http://blogs.infragistics.com/blogs/tsnyder/archive/2007/10/17/mvc-or-mvp-pattern-whats-the-difference.aspx
- MVP = Model-View-Presenter - MVC = Model-View-Controller 1. Both presentation patterns. They separate the dependencies between a Model (think Domain objects), your screen/web page (the View), and how your UI is supposed to behave (Presenter/Controller) 2. They are fairly similar in concept, folks initialize the Presenter/Controller differently depending on taste. 3. A great article on the differences is [here][1]. Most notable is that MVC pattern has the Model updating the View. [1]: http://blogs.infragistics.com/blogs/tsnyder/archive/2007/10/17/mvc-or-mvp-pattern-whats-the-difference.aspx
The problem I experienced when unit testing persistence, especially without an ORM and thus mocking your database (connection), is that you don't really know if your queries succeed. It could be that you your queries are specifically designed for a particular database version and only succeed with that version. You'll never find that out if you mock your database. So in my opinion, unit testing persistence is only of limited use. You should always add tests running against the targeted database.
If you have access to Microsoft Outlook 2007 or Thunderbird, these email clients allow you to add RSS feeds in the same way you would add an email account. I use Google Reader generally but when I want to keep up-to-date with something specific, I add the RSS feed to Outlook and it arrives in my inbox as if it was an email.
For NHibernate, I'd definitely advocate just mocking out the NHibernate API for unit tests -- trust the library to do the right thing. If you want to ensure that the data actually goes to the DB, do an integration test.
I've been using Copy Handler. The nicest thing about it is that it queues up its jobs like a download manager. It has a shell extension so you can either rightclick drag, or just set copy with copyhandler as the default action.
Technically unit tests of persistance are not Unit tests the are Integration tests. With C# using mbUnit, you simply use the SqlRestoreInfo and RollBack attributes [TestFixture] [SqlRestoreInfo(<connectionsting>, <name>,<backupLocation>] public class Tests { [SetUp] public void Setup() { } [Test] [RollBack] public void TEST() { //test insert. } } The same can be done in NUnit, excpet the attribute names differ slighty. As for checking if your query was succeful, you normally need to follow if was a second query to see if the database has been changed as you expect.
Technically unit tests of persistance are not Unit tests they are Integration tests. With C# using mbUnit, you simply use the SqlRestoreInfo and RollBack attributes [TestFixture] [SqlRestoreInfo(<connectionsting>, <name>,<backupLocation>] public class Tests { [SetUp] public void Setup() { } [Test] [RollBack] public void TEST() { //test insert. } } The same can be done in NUnit, excpet the attribute names differ slighty. As for checking if your query was succeful, you normally need to follow it with a second query to see if the database has been changed as you expect.
i built myself a pc with 4gb ram, dual core 1.8ghz 40gb pata drive primary, and 250gb sata drive secondary and installed vista business edition. when i had to copy 120gb of data from my old pata disk, vista failed miserably and kept crashing. i definately recommend teracopy free edition.
I would definitely prefer: 1) [Teracopy][1] - GUI based, replaces the default Windows copy/move UI and adds itself to context menu. Basic version is free (for home use I guess). 2) [Robocopy][2] - CLI based, useful when scripting. Free tool from MS and is included in Vista/Windows 2008. MS Technet has a GUI for robocopy as well - useful to create statements that you can later embed in scripts or on the command prompt. PS: I know these have been already suggested here and I would have voted on them, if I could. [1]: http://www.codesector.com/teracopy.asp [2]: http://en.wikipedia.org/wiki/Robocopy
You say you have enough trouble getting one cube to display... so I am not sure if you have got one to display or not. Basically... put your code for writing a cube in one function, then just call that function 100 times. void DrawCube() { //code to draw the cube } void DisplayCubes() { for(int i = 0; i < 10; ++i) { for(int j = 0; j < 10; ++j) { glPushMatrix(); //alter these values depending on the size of your cubes. //This call makes sure that your cubes aren't drawn overtop of each other glTranslatef(i*5.0, j*5.0, 0); DrawCube(); glPopMatrix(); } } } That is the basic outline for how you could go about doing this.
You say you have enough trouble getting one cube to display... so I am not sure if you have got one to display or not. Basically... put your code for writing a cube in one function, then just call that function 100 times. void DrawCube() { //code to draw the cube } void DisplayCubes() { for(int i = 0; i < 10; ++i) { for(int j = 0; j < 10; ++j) { glPushMatrix(); //alter these values depending on the size of your cubes. //This call makes sure that your cubes aren't drawn overtop of each other glTranslatef(i*5.0, j*5.0, 0); DrawCube(); glPopMatrix(); } } } That is the basic outline for how you could go about doing this. If you want something more efficient take a look into Display Lists sometime once you have the basics figured out :)
The .Net 2.0 framework namespace System.IO.Compression supports GZip and Deflate algorithms. Here are two methods that compress and decompress a byte stream which you can get from your file object. You can subsitute GZipStream for DefaultStream in the methods below to use that algorithm. This still leaves the problem of handling files compressed with different algorithms though. public static byte[] Compress(byte[] data) { MemoryStream output = new MemoryStream(); GZipStream gzip = new GZipStream(output, CompressionMode.Compress, true); gzip.Write(data, 0, data.Length); gzip.Close(); return output.ToArray(); } public static byte[] Decompress(byte[] data) { MemoryStream input = new MemoryStream(); input.Write(data, 0, data.Length); input.Position = 0; GZipStream gzip = new GZipStream(input, CompressionMode.Decompress, true); MemoryStream output = new MemoryStream(); byte[] buff = new byte[64]; int read = -1; read = gzip.Read(buff, 0, buff.Length); while (read > 0) { output.Write(buff, 0, read); read = gzip.Read(buff, 0, buff.Length); } gzip.Close(); return output.ToArray(); }
No, because while you thought LINQ is really just syntactic sugar, it actually heavily used expression trees -- a feature absent in .NET 2.0. That being said .NET 3.5 only builds up on top of .NET 2.0, and that's the reason why the IL doesn't look "different" or "special". I do not see a reason why you shouldn't just install the .NET 3.5 Framework. Everything .NET 2.0 will work fine on it, promise :)
There are some "Hacks" that involve using a System.Core.dll from the 3.5 Framework to make it run with .net 2.0, but personally I would not want use such a somewhat shaky foundation. See here: [http://weblogs.asp.net/fmarguerie/archive/2007/09/05/linq-support-on-net-2-0.aspx][1] > 1. Create a new console application > 2. Keep only System and System.Core as referenced assemblies > 3. Set Copy Local to true for System.Core, because it does not exist in .NET 2.0 > 4. Use a LINQ query in the Main method. For example the one below. > 5. Build > 6. Copy all the bin output to a machine where only .NET 2.0 is installed > 7. Run (Requires .net 2.0 SP1 and I have no idea if bundling the System.Core.dll violates the EULA) [1]: http://weblogs.asp.net/fmarguerie/archive/2007/09/05/linq-support-on-net-2-0.aspx
In theory yes, provided you distribute the LINQ specific assemblies and any dependencies. However that is in violation of Microsoft's licensing. Scott Hanselman wrote a blog post about [Deploying ASP.NET MVC on ASP.NET 2.0][1] which is similar to what you are wanting to do. [1]: http://www.hanselman.com/blog/DeployingASPNETMVCOnASPNET20.aspx
If you correctly markup your HTML code, there is no need for javascript. The following code will allow the user to click on the label text to tick the checkbox. <label for="surname">Surname</label> <input type="checkbox" name="surname" id="surname" /> The *for* attribute on the label element links to the *id* attribute on the input element and the browser does the rest.
If you correctly markup your HTML code, there is no need for javascript. The following code will allow the user to click on the label text to tick the checkbox. <label for="surname">Surname</label> <input type="checkbox" name="surname" id="surname" /> The *for* attribute on the label element links to the *id* attribute on the input element and the browser does the rest. This has been testing to work in: - IE6 - IE7 - Firefox
As far as I know the LINQ library is only available since the framework 3.0. If you want to use something similar in the framework 2.0, you would need to rewritte it yourself :) or find a similar third-party library. I only found a bit of information [here][1] but it didn't convinced me either. [1]: http://weblogs.asp.net/fmarguerie/archive/2007/09/05/linq-support-on-net-2-0.aspx
You can wrap your checkbox in the label: <label style="display: block; padding: 50px 0 0 50px; background-color: pink; width: 80px; height: 80px"> <input type="checkbox" name="surname"> </label>
You can accomplish this with Section Handlers. There is a basic overview of how to write one at [http://www.codeproject.com/KB/aspnet/ConfigSections.aspx][1] however it refers to app.config which would be pretty much the same as writing one for use in web.config. This will allow you to essentially have your own XML tree in the config file and do some more advanced configuration. [1]: http://www.codeproject.com/KB/aspnet/ConfigSections.aspx
Assuming you have the correct assemblies and a C# compiler you in theory can use whatever you want to edit the code and then just run the compiler by hand or using a build script. That being said it is a real pain doing .NET development without Visual Studio/SharpEdit/Monodevelop in my opinion.
Ronnie, If you wanted to enclose the label text and checkbox inside a wrapper element, you could do the following: <label for="surname"> Surname <input type="checkbox" name="surname" id="surname" /> </label>
I haven't done SWING development since my early CS classes but if it wasn't built in you could just inherit javax.swing.AbstractButton and create your own. Should be pretty simple to wire something together with their existing framework.
Wrapping with the label still doesn't allow clicking 'anywhere in the box' - still just on the text! This does the job for me: <div onclick="dob.checked=!dob.checked" class="checkbox"><input onclick="checked=!checked" id="dob" type="checkbox"/>Date of birth entry must be completed</div> but unfortunately has lots of javascript that is effectively toggling twice.
The JITter will sometimes use non-virtual calls to methods in sealed classes since there is no way they can be extended further. There are complex rules regarding calling type, virtual/nonvirtual, and I don't know them all so I can't really outline them for you, but if you google for sealed classes and virtual methods you might find some articles on the topic. Note that any kind of performance benefit you would obtain from this level of optimization should be regarded as last-resort, always optimize on the algorithmic level before you optimize on the code-level.
The JITter will sometimes use non-virtual calls to methods in sealed classes since there is no way they can be extended further. There are complex rules regarding calling type, virtual/nonvirtual, and I don't know them all so I can't really outline them for you, but if you google for sealed classes and virtual methods you might find some articles on the topic. Note that any kind of performance benefit you would obtain from this level of optimization should be regarded as last-resort, always optimize on the algorithmic level before you optimize on the code-level. Here's one link mentioning this: [Rambling on the sealed keyword](http://codebetter.com/blogs/patricksmacchia/archive/2008/01/05/rambling-on-the-sealed-keyword.aspx)
Sealed classes *should* provide a performance improvement. Since a sealed class cannot be derived, any virtual members can be turned into non-virtual members. Of course, we're talking really small gains. I wouldn't mark a class as sealed just to get a performance improvement unless profiling revealed it to be a problem.
Normally you'd copy it to svn+ssh://host.example.com/repos/project/branches/mybranch so that you can keep several branches in the repository, but your syntax is valid. Here's some advice on [how to set up your repository layout][1]. [1]: http://svnbook.red-bean.com/en/1.1/ch04s07.html
If you even plan on merging your branch, I highly suggest you look at this: [http://www.orcaware.com/svn/wiki/Svnmerge.py][1] I hear Subversion 1.5 builds more of the merge tracking in, I have no experience with that. My project is on 1.4.x and svnmerge.py is a life saver! [1]: http://www.orcaware.com/svn/wiki/Svnmerge.py
I believe you are talking about a content management system. The way I have delt with this situation in the past is to either: 1. Allow a page/content to define an extra custom stylesheet or 2. Allow a page/content to define inline style tags
This will allow you to pass a weight of 0 and still work properly. Notice the === operator, this checks to see if weight matches "null" in both value and type (as opposed to ==, which is just value, so 0 == null == false). PHP: public function createShipment($startZip, $endZip, $weight=null){ if ($weight === null) $weight = $this->getDefaultWeight(); }
What's the best way to implement BDD/TDD in .NET 2.0?
|c#|.net|testing|tdd|bdd|
I'm looking to add a testing suite to my application, however I can't move to the newer testing frameworks for .NET 3.5. Does anyone have a suggestion about good testing frameworks to use?
How do I make a checkbox toggle from clicking on the text label as well?
|html|checkbox|
Checkboxes in html forms don't have implicit labels with them. Adding an explicit label (some text) next to it doesn't toggle the checkbox.
|html|checkbox|
Thxm, Mc! http://asm.objectweb.org/ is another one. _Excellent_ documentation on byte code instrumentation, but nothing "directly" aimed at writing a coverage tool - just some hints or ideas.
Quick'n Dirty: First create your **ConfigurationSection** and **ConfigurationElement** classes: public class MyStuffSection : ConfigurationSection { ConfigurationProperty _MyStuffElement; public MyStuffSection() { _MyStuffElement = new ConfigurationProperty("MyStuff", typeof(MyStuffElement), null); this.Properties.Add(_MyStuffElement); } public MyStuffElement MyStuff { get { return this[_MyStuffElement] as MyStuffElement; } } } public class MyStuffElement : ConfigurationElement { ConfigurationProperty _SomeStuff; public MyStuffElement() { _SomeStuff = new ConfigurationProperty("SomeStuff", typeof(string), "<UNDEFINED>"); this.Properties.Add(_SomeStuff); } public string SomeStuff { get { return (String)this[_SomeStuff]; } } } Then let the framework know how to handle your configuration classes in **web.config**: <configuration> <configSections> <section name="MyStuffSection" type="MyWeb.Configuration.MyStuffSection" /> </configSections> ... And actually add your own section below: <MyStuffSection> <MyStuff SomeStuff="Hey There!" /> </MyStuffSection> Then you can use it in your code thus: MyWeb.Configuration.MyStuffSection configSection = ConfigurationManager.GetSection("MyStuffSection") as MyWeb.Configuration.MyStuffSection; if (configSection != null && configSection.MyStuff != null) { Response.Write(configSection.MyStuff.SomeStuff); }
You could always try the Synth look & feel. You provide an xml file that acts as a sort of stylesheet, along with any images you want to use. The code might look like this: try { SynthLookAndFeel synth = new SynthLookAndFeel(); Class aClass = MainFrame.class; InputStream stream = aClass.getResourceAsStream("\\default.xml"); if (stream == null) { System.err.println("Missing configuration file"); System.exit(-1); } synth.load(stream, aClass); UIManager.setLookAndFeel(synth); } catch (ParseException pe) { System.err.println("Bad configuration file"); pe.printStackTrace(); System.exit(-2); } catch (UnsupportedLookAndFeelException ulfe) { System.err.println("Old JRE in use. Get a new one"); System.exit(-3); } And the xml file might look like this: <synth> <style id="button"> <font name="DIALOG" size="12" style="BOLD"/> <state value="MOUSE_OVER"> <imagePainter method="buttonBackground" path="dirt.png" sourceInsets="2 2 2 2"/> <insets top="2" botton="2" right="2" left="2"/> </state> <state value="ENABLED"> <imagePainter method="buttonBackground" path="dirt.png" sourceInsets="2 2 2 2"/> <insets top="2" botton="2" right="2" left="2"/> </state> </style> <bind style="button" type="name" key="dirt"/> </synth> And a couple of useful links: <http://javadesktop.org/articles/synth/> <http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/synth.html>
You could always try the Synth look & feel. You provide an xml file that acts as a sort of stylesheet, along with any images you want to use. The code might look like this: try { SynthLookAndFeel synth = new SynthLookAndFeel(); Class aClass = MainFrame.class; InputStream stream = aClass.getResourceAsStream("\\default.xml"); if (stream == null) { System.err.println("Missing configuration file"); System.exit(-1); } synth.load(stream, aClass); UIManager.setLookAndFeel(synth); } catch (ParseException pe) { System.err.println("Bad configuration file"); pe.printStackTrace(); System.exit(-2); } catch (UnsupportedLookAndFeelException ulfe) { System.err.println("Old JRE in use. Get a new one"); System.exit(-3); } From there, go on and add your JButton like you normally would. The only change is that you use the setName(string) method to identify what the button should map to in the xml file. The xml file might look like this: <synth> <style id="button"> <font name="DIALOG" size="12" style="BOLD"/> <state value="MOUSE_OVER"> <imagePainter method="buttonBackground" path="dirt.png" sourceInsets="2 2 2 2"/> <insets top="2" botton="2" right="2" left="2"/> </state> <state value="ENABLED"> <imagePainter method="buttonBackground" path="dirt.png" sourceInsets="2 2 2 2"/> <insets top="2" botton="2" right="2" left="2"/> </state> </style> <bind style="button" type="name" key="dirt"/> </synth> The bind element there specifies what to map to (in this example, it will apply that styling to any buttons whose name property has been set to "dirt"). And a couple of useful links: <http://javadesktop.org/articles/synth/> <http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/synth.html>
NUnit is always a favorite of mine. However if you are using TFS as your source control I suggest you stick with the Microsoft Stack.
Set the CSS "display" property for the label to be a block element and use that instead of your div - it keeps the semantic meaning of a label while allowing whatever styling you like. For example <label for="test" style="width: 100px; height: 100px; display: block; background-color: #e0e0ff;"> A ticky box! <input type="checkbox" id="test" /> </label>
Yes, this is possible. One of the main pros for using Swing is the ease with which the abstract controls can be created and manipulates. Here is a quick and dirty way to extend the existing JButton class to draw a circle to the right of the text. package test; import java.awt.Color; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; import javax.swing.JButton; import javax.swing.JFrame; public class MyButton extends JButton { private static final long serialVersionUID = 1L; private Color circleColor = Color.BLACK; public MyButton(String label) { super(label); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Dimension originalSize = super.getPreferredSize(); int gap = (int) (originalSize.height * 0.2); int x = originalSize.width + gap; int y = gap; int diameter = originalSize.height - (gap * 2); g.setColor(circleColor); g.fillOval(x, y, diameter, diameter); } @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); size.width += size.height; return size; } /*Test the button*/ public static void main(String[] args) { MyButton button = new MyButton("Hello, World!"); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); Container contentPane = frame.getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(button); frame.setVisible(true); } } Note that by overriding **paintComponent** that the contents of the button can be changed, but that the border is painted by the **paintBorder** method. The **getPreferredSize** method also needs to be managed in order to dynamically support changes to the content. Care needs to be taken when measuring font metrics and image dimensions. For creating a control that you can rely on, the above code is not the correct approach. Dimensions and colours are dynamic in Swing and are dependent on the look and feel being used. Even the default *Metal* look has changed across JRE versions. It would be better to implement **AbstractButton** and conform to the guidelines set out by the Swing API. A good starting point is to look at the **javax.swing.LookAndFeel** and **javax.swing.UIManager** classes. <http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/LookAndFeel.html> <http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/UIManager.html> Understanding the anatomy of LookAndFeel is useful for writing controls: [Creating a Custom Look and Feel][1] [1]: http://java.sun.com/products/jfc/tsc/articles/sce/index.html
For a Mock Object library, I've found the BSD-licensed [Rhino.Mocks][1] to be rather pleasing. [1]: http://ayende.com/projects/rhino-mocks.aspx
NUnit is available at <http://www.nunit.org> I would suggest this even when working on the MS stack - the support for non-MS frameworks is happening in the MVC previews which shows a definate movement in the right direction to allow us all to customise our stacks to fit.
in 1.x there used to be things DataTables couldn't do which DataSets could (don't remember exactly what). All that was changed in 2.x. My guess is that's why a lot of examples still use DataSets. DataTables should be quicker as they are more lightweight. If you're only pulling a single resultset, its your best choice between the two.
It really depends on the sort of data you're bringing back. Since a DataSet is (in effect) just a collection of DataTable objects, you can return multiple distinct sets of data into a single, and therefore more manageable, object. Performance-wise, you're more likely to get innefficiency from unoptimised queries than from the "wrong" choice of .NET construct. At least, that's been my experience.
One feature of the DataSet is that if you can call multiple select statements in your stored procedures, the DataSet will have one DataTable for each.
How to filter and combine 2 datasets in C#
|c#|.net|
I am building a web page to show a customer what software they purchased and to give them a link to download said software. Unfortunately, the data on what was purchased and the download information are in separate databases so I can't just take care of it with joins in a query. The common item is SKU. I'll be pulling back a list of SKUs from the customer purchases database, and on the download table is a comma deleted list of SKUs associated with that download. My intention, at the moment, is to create from this one datatable to populate a GridView. Any suggestions on how to do this efficiently would be appreciated. If it helps, I can pretty easily pull back the data as a DataSet or a DataReader, if either one would be better for this purpose. Eric Sipple
From the [Python FAQ][1]: > Lists and tuples, while similar in many respects, are generally used in fundamentally different ways. Tuples can be thought of as being similar to Pascal records or C structs; they're small collections of related data which may be of different types which are operated on as a group. For example, a Cartesian coordinate is appropriately represented as a tuple of two or three numbers. > Lists, on the other hand, are more like arrays in other languages. They tend to hold a varying number of objects all of which have the same type and which are operated on one-by-one. Generally by convention you wouldn't choose a list or a tuple just based on its (im)mutability. You would choose a tuple for small collections of completely different pieces of data in which a full-blown class would be too heavyweight, and a list for collections of any reasonable size where you have a homogeneous set of data. [1]: http://www.python.org/doc/faq/general/#why-are-there-separate-tuple-and-list-data-types
Add Custom Tag to Visual Studio Validation
|visual-studio|
How can I add rules to Visual Studio (2005 and up) for validating property markup (HTML) for a vendor's proprietary controls? My client uses a control which requires several properties to be set as tags in the aspx file which generates something like 215 validation errors on each build. It's not preventing me from building, but real errors are getting lost in the noise.
Definitely not a ruby expert, but I'll give it a shot. $ irb system "echo Hi" Hi => true You should also be able to do things like... cmd = 'ls' system(cmd)
I am thinking off the top of my head here. If you load both as Data Tables in the same Data Sets, and define a relation between the two over SKU, and then run a query on the Data Set which produces the desired result.
Thanks Adhip, this is what I came up with: In the page load function: HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("default_body"); body.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#2E6095"); Where default_body = the id of the body tag.
<p>if its .net on both sides:</p> <p>think you should use binary serialization and send the byte[] result.</p> <p>trusting your struct to be fully blittable can be trouble.</p> <p>you will pay in some overhead (both cpu and network) but will be safe.</p>
ASP.NET Display SVN Revision Number
|asp.net|svn|
I see in the Stack Overflow footer that the SVN Revision number is displayed. Is this automated and if so, how does one implement it in ASP.NET? *(Solutions in other languages are acceptable)*
Subversion doesn't really support branches or tags. What it allows instead is a very very light and efficient copying facility. Branching and Tagging are, effectively the same. Just copy a whole folder in the repository to somewhere else in the repository. Basically this means that it is by convention what copying a folder means - whether it be a backup, tag, branch or whater. Depending upon how you want to think about things (normally depending upon which SCM tool you have used in the past) you need to set up a folder structure within your repository to support your style. Common styles are to have a bunch of folders at the top of your repository called 'tags', 'branches' and 'trunk' etc. - that allows you to copy your whole 'trunk' (or sub-sets) into the tags and/or branches folders. If you have more than one project you might want to replicate this kind of structure under each project: It can take a while to get used to the concept - but it works - just make sure you (and your team) are clear on the conventions that you are going to use. It is also a good idea to have a good naming convention - something that tells you why the branch/tag was made and whether it is still apropriate - consider ways of archiving branches that are obsolete.
File size differences after copying a file to a server vía FTP
|python|
I had an PHP script to update the webserver from a local directory. I'm migrating the script into Python, it works almost OK but after a PUT command the size of the file in the server isn't the same as the local file. Once I download again the file from the FTP server, the only difference is the CR/LF mark. It annoys me because the same script is comparing the size of the files to update. Also, it works perfectly in PHP vía ftp_put. from ftplib import FTP ftpserver = "myserver" ftpuser = "myuser" ftppass = "mypwd" locfile = "g:/test/style.css" ftpfile = "/temp/style.css" try: ftp = FTP(ftpserver, ftpuser, ftppass) except: exit ("Cannot connect") f = open (locfile, "r") try: ftp.delete (ftpfile) except: pass # ftp.sendcmd ("TYPE I") # ftp.storlines("STOR %s" % ftpfile, f) ftp.storbinary("STOR %s" % ftpfile, f) f.close() ftp.dir (ftpfile) ftp.quit() ### Any suggestions? TIA, Pablo
How do I build a collection in classic ASP?
|vbscript|asp|
I want to be able to do: For Each thing In things End For
|asp|vbscript|
I want to be able to do: For Each thing In things End For CLASSIC ASP - NOT .NET!
Whatever your [things] are need to be written outside of VBScript. In VB6, [you can write a Custom Collection class][1], then you'll need to compile to an ActiveX DLL and register it on your webserver to access it. [1]: http://www.vb-helper.com/howto_custom_collection_with_for_each.html
Do you need to open the locfile in binary using "rb"? f = open (locfile, "rb")
Well if you go under the properties of your file in Windows or a *nix environment, you will notice two sizes. One is the sector size, and one is the actual size. The sector size is the number of sectors in bytes that are used up on your hard disk. That is because two files cannot be in the same sector with most modern file systems, so if your file fills up half of the sector the whole sector is marked as filled. So you might be comparing the sector file size to the actual file size on the FTP server or vice versa.
Make sure that the file has svn:keywords "Rev Id" and then put $Rev$ somewhere in there. See [this question and the answers to it][1]. [1]: http://stackoverflow.com/questions/163/how-do-i-sync-the-svn-revision-number-with-my-aspnet-web-site
If you need to populate each member variable by hand you can generalize it a bit as far as the primitives are concerned by using FormatterServices to retrieve in order the list of variable types associated with an object. I've had to do this in a project where I had a lot of different message types coming off the stream and I definitely didn't want to write the serializer/deserializer for each message. Here's the code I used to generalize the deserialization from a byte[]. public virtual bool SetMessageBytes(byte[] message) { MemberInfo[] members = FormatterServices.GetSerializableMembers(this.GetType()); object[] values = FormatterServices.GetObjectData(this, members); int j = 0; for (int i = 0; i < members.Length; i++) { string[] var = members[i].ToString().Split(new char[] { ' ' }); switch (var[0]) { case "UInt32": values[i] = (UInt32)((message[j] << 24) + (message[j + 1] << 16) + (message[j + 2] << 8) + message[j + 3]); j += 4; break; case "UInt16": values[i] = (UInt16)((message[j] << 8) + message[j + 1]); j += 2; break; case "Byte": values[i] = (byte)message[j++]; break; case "UInt32[]": if (values[i] != null) { int len = ((UInt32[])values[i]).Length; byte[] b = new byte[len * 4]; Array.Copy(message, j, b, 0, len * 4); Array.Copy(Utilities.ByteArrayToUInt32Array(b), (UInt32[])values[i], len); j += len * 4; } break; case "Byte[]": if (values[i] != null) { int len = ((byte[])values[i]).Length; Array.Copy(message, j, (byte[])(values[i]), 0, len); j += len; } break; default: throw new Exception("ByteExtractable::SetMessageBytes Unsupported Type: " + var[1] + " is of type " + var[0]); } } FormatterServices.PopulateObjectMembers(this, members, values); return true; }
As long as the two databases are on the same physical server (assuming MSSQL) and the username/password being used in the connection string has rights to both DBs, then you should be able to perform a join across the two databases. Example: select p.Date, p.Amount, d.SoftwareName, d.DownloadLink from PurchaseDB.dbo.Purchases as p join ProductDB.dbo.Products as d on d.sku = p.sku where p.UserID = 12345
Right-click on the Source view of an HTML / ASP page and select "Formatting and Validation". Click "Tag Specific Options". Expand "Client HTML Tags" and select the heading. Click "New Tag...". And just fill it in!
Right-click on the Source view of an HTML / ASP page and select "Formatting and Validation". 1. Click "Tag Specific Options". 2. Expand "Client HTML Tags" and select the heading. 3. Click "New Tag...". 4. And just fill it in! I wish that I could add custom CSS values as well.
How do I turn on line numbers by default in TextWrangler on the Mac?
|macos|textwrangler|
I am fed up having to turn them on every time I open the application.
Go to TextWrangler > Preferences. Choose Text Status Display in the category pane, then check the option "Show line numbers" and close the preferences. This should now be on by default when you open existing documents.
You can also use the backtick operators (`), similar to Perl: directoryListing = `ls /` puts directoryListing # prints the contents of the root directory Handy if you need something simple. Which method you want to use depends on exactly what you're trying to accomplish; check the docs for more details about the different methods.
There is nothing VS specific with the MVC framework - it is just a bunch of DLLs that you can use. The wizards in VS just build you a quick-start framework. ASP.NET MVC is "bin-deployable" - there is nothing too clever to set up on the server either - just point the wildcard ISAPI filter to ASP.NET
How do I use (n)curses in Ruby?
|ruby|unix|curses|
I'd like to create a progress bar to indicate the status of an a batch job in Ruby. I've read some [tutorials][1] / [libraries][2] on using ncurses, none of which were particularly helpful in explaining how create an "animated" progress bar in the terminal or using curses with Ruby. I'm already aware of using a separate thread to monitor the progress of a given job, I'm just not sure how to proceed with drawing a progress bar. [1]: http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ "NCURSES Programming HOWTO" [2]: http://ncurses-ruby.berlios.de/ "ncurses-ruby"