Here's a quick little one-liner I use all the time.
It will create a concrete instance that implements 'I' interface. This has a string as a parameter, but there are lots of other possibilities (and overloads for Type and CreateInstance).
But, be careful with this, you can easily get into trouble, as the magic happens at runtime, so watch your speeling.
public class Activator<I> { public static I Create(string s) { return (I)System.Activator.CreateInstance(Type.GetType(s)); } }
Here are my favorite Firefox add-ons
Web Developer tool bar (gotta love Ctrl+Shift+f)
Firebug (the best javascript debugger and more)
Html Validator (great for seeing all your awesome htmlz c0dez)
Sqlite Manager (the version for Firefox 3.5 is much improved)
Greasemonkey (custom scripts)
Modify Headers (I use to test other user agents)
Live Page Rank (get google page rank for the site you're on)
Search Status (lots of SEO goodies)
Add n Edit Cookies (easily add and/or modify cookies)
Remove Cookies for Site (removes cookies only for the site you're on)
ColorZilla (eyedropper tool to get any color on a web page, in an image, or html)
refspoof (change the referring url)
YSlow (figure out why your site is slow :( )
Hackbar (test your site with various sql injection strings)
So, to begin, the following has NOT happened to me, but I wanted to make sure people understand why public computers and certain browser features can be bad... very bad for you.
Let's say you sign in to your email account on a public, or unfamiliar computer. The machine asks you to save the password for that site, and silly you, chooses to accept. OK. So, now you've finished your work,you haven't erased your tracks, and the next person comes along... if the next person comes to the same email provider that you have visited, they'll see something like this :
| username | |
| password |
yikes
So yeah, they can login as you, see all your mail, perhaps other sensitive information in emails...in short, they can find out a lot. If they were really naughty, they would just do this in the address bar and get your password :
javascript:alert(document.getElementById('Pass').value);
without looking at the src code on this page, you can try it here and see what I've set as the password above.
What can you do? Well, here are 5 safety tip for using a public computer.
Year after year you know you have a product that will be updated at a[round] a certain month. It happens a lot with my business domain. Rather than changing lots of text, this should work nicely for my needs. (I didn't use any timezone or culture considerations)
the pivot month is the int that decides when we flip to next year.
/// <summary> /// Figures out if should use this year ///or next based on a defined pivot month. /// </summary> /// <returns>4 digit year</returns> public int YearPivot(DateTime dt, int pivotMonth) { return (dt.Month <= pivotMonth) ? dt.Year : dt.AddYears(1).Year; }
couple tests showing it in action...
DateTime dt = new DateTime(2009, 10, 1); //returns 2009 Assert.AreEqual(2009, m.YearPivot(dt, 10)); //returns 2010 Assert.AreEqual(2010, m.YearPivot(dt, 5));
I work for a fabulous company, I've been with them for about 3 years. They are incredible about making sure developers have what they need to get the job done, whether it's software or hardware (or classes, or books). In fact, I'm on my third development machine! Most software requests are usually also granted.
So what does your gear look like? What development software has your company gotten for you to help better your work?
This is what it looks like for me:(as of posting)
Hardware:
- Windows XP 64, core 2 quad @ 2.5 GHz, 8 gigs of ram
- 3 19 inch widescreen monitors
- microsoft natural ergo keyboard
- trackball mouse
- physical server 03 box [for testing]
- various XP/03 virtual machines [more testing]
Software:
- Resharper 4
- dotTrace
- NDepend
- NCover complete
- RegexBuddy
- BareTail Pro
- All the microsoft dev. stuff (VS 03,05,08, SQL server 05,08)
- Snag it
- ultramon
What about you?
Here's a better version of string.IsNullOrEmpty(). Why is it better you say? Well my friend, this one checks the string for spaces... It also returns a positive statement (true if it is NOT null and NOT empty)
public static class Extensions { public static bool IsSafe(this string s) { return (s != null && s.Trim().Length > 0); } }
And some unit tests...
[Test] public void IsSafeStringTest() { string cheese = "is good"; Assert.IsTrue(cheese.IsSafe()); cheese = ""; Assert.IsFalse(cheese.IsSafe()); cheese = " "; Assert.IsFalse(cheese.IsSafe()); cheese = null; Assert.IsFalse(cheese.IsSafe()); //------------------------------- cheese = "yum"; Assert.IsFalse(string.IsNullOrEmpty(cheese)); cheese = ""; Assert.IsTrue(string.IsNullOrEmpty(cheese)); cheese = null; Assert.IsTrue(string.IsNullOrEmpty(cheese)); // rut roh... // string.IsNullOrEmpty() and spaces are not nice together. cheese = " "; // should be true! Assert.IsFalse(string.IsNullOrEmpty(cheese)); }
While the following might be nice, we know that we can't do it because of the null reference exception we might get (if cheese were to be null)...
string.IsNullOrEmpty(cheese.Trim());
Anyway, while we're doing some extension methods, here's a similarly named one I also use when working with generic lists.
public static bool IsSafe<T>(this List<T> t) { return (t != null && t.Count() > 0); }
And some unit tests...
Yo yo howdy-doody. I'm doing a talk on NUnit (and friends) with VS 2008 at CTDOTNET's second CodeCamp -- June 13th, 2009.
It's an intro to unit testing, but I'll talk about reasons why testing is beneficial, how to setup a unit testing environment, and tools (friends) to use along the way.
Get the deets about the day.
Hope to see you there!
This post will allow you to unit test objects that have a dependency on a SqlDataReader by mocking/stubbing a data reader.
Here I've made a 'wrapper' of sorts for the good ol' Microsoft SqlHelper class, which is ancient now, ya? Since the SqlHelper.ExecuteReader's method class implements the IDataReader interface we're in luck.
public interface IFetch { //add members as necessary IDataReader ExecuteDataReader(string connectionString, string storedProcedureName,SqlParameter[] parameters); } public class Fetch : IFetch { public IDataReader ExecuteDataReader(string connectionString, string storedProcedureName, SqlParameter[] parameters){ return SqlHelper.ExecuteReader(connectionString, CommandType.StoredProcedure,storedProcedureName, parameters); } }
Next we create our object from the results of our IDataReader. The SqlHelper class removes the worry about mocking SqlCommand and SqlConnection classes. All you need to worry about are the results (SqlDataReader).
(You can make your own RockStar object, fo sho.)
Whether you call it constructor initialization or constructor chaining, we have it here, and will allow us to inject the correct dependency, in this case, an interface that defines an ExecuteReader method. (I've never gotten into DI/IoC frameworks, should I, and which??)
private readonly RockStar rs; private readonly IFetch fetch; //here's the magic sauce for the unittests public FetchCms(IFetch fetch, RockStar rs){ this.fetch = fetch; this.rs = rs; } //production code calls this which calls //the other constructor. mmm. public FetchRockStar() : this(new Fetch(), new RockStar()) { } public RockStar GetRockStar(string urlToLookup){ try { var parms = new[] { new SqlParameter("@urlName", urlToLookup) }; using (IDataReader reader = fetch.ExecuteDataReader("localhell", "rockstar_page_get",parms)){ if (reader != null && reader.Read()){ rs.Name = reader["name"].ToString(); rs.Guitar = reader["guitar"].ToString(); //add some logic... and so on... } } } catch //swine flu {} return fs; }
ok, so now your production code is hawt, but how do you 'fake' a reader, or 'fake' its results? Good question, but never fear, Phil Haack has you covered with his totally rock-tacular StubDataReader class. Get it.
so now, in your UnitTest project...
I'm creating some fake results that I can use to test my expectations, using the StubDataReader class you've downloaded above and added to your UnitTest project.
private static StubDataReader getData_Kerry_King(){ var resultSet = new StubResultSet("name", "guitar"); resultSet.AddRow("Kerry King", "B.C. Rich"); return new StubDataReader(resultSet); }
I'm using the Moq framework to mock my interfaces. (it's from an older release, hence the Expect calls rather than the Setup calls [anyone: what does the new version get me?])
[Test] public void Execute_DataReader_Test() { var m = new Mock<IFetch>(); //here i'm expecting that my ExecuteReader implementation //return my 'fake' data m.Expect( x => x.ExecuteReader( It.IsAny<string>(), It.IsAny<string>(), It.IsAny<SqlParameter[]>() ) ).Returns(getData_Kerry_King()); var rockStar = new RockStar(); // pass IN the interface using the special constructor. var fetch = new FetchRockStar(m.Object, rockStar); rockStar = fetch.GetRockStar("kerry-king"); //assert Assert.AreEqual("Kerry King",rockStar.Name); Assert.AreEqual("B.C. Rich",rockStar.Guitar); }
Even Kerry thinks you should be testing!

After looking at google analytics (ga) graphs all these months, I've come to the conclusion that if my site's ga graph were that of a stock/eft/etc I'd be a RICH dude. I'm guessing you'd be too since it's not a terribly new phenomenon; traffic or sales dropping off on the weekend. Akin to the turmoil on wall street, investors are often afraid to hold securities over the weekend. I don't blame them.
But really what do people do on the weekends? Beats me. I guess they don't read my blog! Granted it is somewhat technical-related. I don't read anyone's on the w/e either so whatev.
Ok, so here is the ga graph... (this is a snapshot from a month ago... by week)

I can assure you, this continues on for months...and months.... and months.
"So what does this all mean?" you ask. Well, in the next highly technically list, I will tell you the secret to becoming rich in this psuedo website exchange.
1. Know the future (which I clearly know regarding this site's traffic)
2. Buy / Cover low.
3. Sell / Short high.

Here I've clearly laid out the points for which actions should be taken! Depending on your strategy, buying, shorting or both (just not at the same time :)) you too can be richy!
happy trading.
















