DaveAmour 160 Mmmmmm beer Featured Poster

I've been studying TDD for a few years and read quite a few books but none that good to be honest. Can anyone recomend any good ones. I'm not interested in BDD but am keen on anything that tackles the many problems of mocking intrinsic MVC objects.

DaveAmour 160 Mmmmmm beer Featured Poster

Those 2 urls are not the same!

DaveAmour 160 Mmmmmm beer Featured Poster

Did they have Source Control?

overwraith commented: It would have been nice wouldn't it have been? +3
DaveAmour 160 Mmmmmm beer Featured Poster

When you first enter the outer loop i is equal to 6. You then start the inner loop with j initially being equal to 1. You tell the inner loop to keep going while j is less than or equal to i. With each pass of the loop you subtract 1 from j so j starts at 1 then goes 0, -1, -2 etc so j is always less than i so the loop will never end until something crashes or your numbers flip (not sure how Java handles this as I am not a Java programmer).

DaveAmour 160 Mmmmmm beer Featured Poster

If you make then Date objects can you not use comparison operators - eg >, < etc?

DaveAmour 160 Mmmmmm beer Featured Poster

Ok my apologies just ignore me then.

DaveAmour 160 Mmmmmm beer Featured Poster

They are the patterns you use to select elements eg:

p
{
    color: red;
}

This makes all paragraphs red - the "p" is the selector

Or:

.active
{
    border: 1px solid red;
}

The selector is ".active" which selects all elements with a class of active

DaveAmour 160 Mmmmmm beer Featured Poster

` var input = "BB5 6BN, BB4 6BN,BB4 8BN, CF10 3BA";

var trimmedInput = input.Replace(", ", ",");`
DaveAmour 160 Mmmmmm beer Featured Poster

Top Tip - look at T4MVC

@Html.ActionLink("Delete Dinner", "Delete", "Dinners", new { id = Model.DinnerID }, null)

T4MVC lets you write

@Html.ActionLink("Delete Dinner", MVC.Dinners.Delete(Model.DinnerID))

https://github.com/T4MVC/T4MVC
https://visualstudiogallery.msdn.microsoft.com/8d820b76-9fc4-429f-a95f-e68ed7d3111a

DaveAmour 160 Mmmmmm beer Featured Poster

Fiddler is your friend here. Could be cookies, or header related. Look at a normal logon in fiddler and compare it with yours. http://www.telerik.com/fiddler

DaveAmour 160 Mmmmmm beer Featured Poster

At a high level you need to provide a mechanism for client code to specify what it wants loaded.

Ef with Linq does this as follows:

var customers = context.Customers.ToList();

var customers = context.Customers.Include("Invoices").ToList()

var customers = context.Customers.Include("Invoices.InvoiceLines").ToList()

So the first says load just customers, the second says load customers and invoices and the last says load customers, invoices and invoicelines.

The above usually uses lambdas rather than strings so:

var customers = context.Customers.Include(c => c.Invoices).ToList()

and so on.

So in your code you need to examine the client specification and when building your sql add joins as appropriate to get the data you need. You then need to parse the resuls from SQL and create OO objects from the flat data.

Thats is really at a very high level. Of course it is more tricky in practice but that's the general idea I think.

DaveAmour 160 Mmmmmm beer Featured Poster
public class MyModel
{
    public Model1 Model1 { get; set;}
    public Model2 Model2 { get; set;}
}
DaveAmour 160 Mmmmmm beer Featured Poster

Look at the code that hashed them in the first place.

irshad398 commented: I don't have that code now. I have only database stored. +0
DaveAmour 160 Mmmmmm beer Featured Poster
DaveAmour 160 Mmmmmm beer Featured Poster

Databases can generate their own unique keys. Any reason why you can't do this? Sounds like you are making hard work for yourself.

If you really do want to generate unique keys yourself though then try a Guid eg:

private static string GenerateScanID()
{
    return Guid.NewGuid().ToString();
}
DaveAmour 160 Mmmmmm beer Featured Poster

Jim is spot on "efficiency is irrellevent. Focus more on clear code" - that's exactly the mindset to be in.

Also in a real trivia game you have a Deck of used questions and a Deck of unused questions so you could model it that way maybe.

So if you have a Deck class you can then implement IEnumberable and your deck is then both a collection of questions and has other properties and methods too - eg GetNextQuestion

https://msdn.microsoft.com/en-us/library/dd145423.aspx?f=255&MSPPError=-2147217396

If you model things in this kind of way then your client or orchestration code will be clear, elegant and beautiful! Easy to understand and easy to maintain.

Finally if you have the time and desire then this is a great case for TDD http://www.codeproject.com/Articles/560137/NET-TDD-Test-Driven-Development-by-example-Part

DaveAmour 160 Mmmmmm beer Featured Poster

Not sure if this is right but try emoving brackets:

document.getElementById('clickMe').onclick = testOne;

DaveAmour 160 Mmmmmm beer Featured Poster

You have two action attribues in your form tag - is that right?

DaveAmour 160 Mmmmmm beer Featured Poster

I got my email to cash out my five dollars. I shall allow it to bounce back to you though so you can run your servers for 20 minutes longer!

tobyITguy commented: Nice guy. +0
DaveAmour 160 Mmmmmm beer Featured Poster

What is the code doing? If it is on the main thread and it is doing a lot it can freeze the UI. Consider running the code on another thread.

DaveAmour 160 Mmmmmm beer Featured Poster

Open a command prompt in Windows

Type "Regsvr32" then hit enter. If it's good enough for MS, it's good enough for me!

DaveAmour 160 Mmmmmm beer Featured Poster

Ok I see.

I have never seen this before to be honest but have looked into it.

Consider the code below if I put a breakpoint on line 35. In there localContacts contains 1 item and the liveContacts contains several hundred.

So Local is all of the items which have not yet been committed to the database.

To quote MS - Gets an ObservableCollection<T> that represents a local view of all Added, Unchanged, and Modified entities in this set.

https://msdn.microsoft.com/en-us/library/gg696248%28v=vs.113%29.aspx?f=255&MSPPError=-2147217396

EFLocal.png

DaveAmour 160 Mmmmmm beer Featured Poster

@Slavi - There is a famous chess opening called the Slav

Slavi commented: great! :D Pretty big chess fan myself =] +6
DaveAmour 160 Mmmmmm beer Featured Poster
Performing Selective Includes in Entity Framework with the Fluent API

When we are using Entity Framework as our data access choice to work with SQL Server then there are some potential pitfalls.

One of these pitfalls is doing selective includes. What do I mean by selective includes?

To answer that let's first look at our class and database model.

Lets suppose we have some customers and some invoices in our application. Our database schema and model classes could look like this:

schema.png

And we may have data like this:

data.png

Now suppose we wanted to select all customer records and their invoices raised in August 2014. With plain SQL we might do something like this:

select-invoices.png

And from there we could create one customer object in C# for Mary and load in 3 invoice objects into her Invoices collection. Nice and simple.

In Entity Framework our first go at coding this problem might look something like this:

GetCustomerAndInvoicesByDateRange.png

If we run this and debug it though we see that all invoices have been loaded as seen below:

Debug1.png

The reason for this is that our code in plain English is actually saying get Customers where they have any invoices in August 2014 and include invoices.

Entity Framework will actually include all of the Invoices though - the where clause is just acting on customers - ie select customers who have …

DaveAmour 160 Mmmmmm beer Featured Poster

Here's my go:

    <script>
        function CustomDate()
        {
            this.date = new Date();  
            this.dayPart = this.date.getHours() < 12 ? "AM" : "PM";

            this.toString = function()
            {
                return this.date.getMonth() + "/" + this.date.getDate() + "/" + this.date.getFullYear()
                    + " - " + this.date.getHours( ) + ":" + this.date.getMinutes()
                    + ":" + this.date.getSeconds() + " " + this.dayPart;
            };
        }

        var d = new CustomDate();

        alert(d);
    </script>
DaveAmour 160 Mmmmmm beer Featured Poster

Hi

Sorry for the late replay, out all day yesterday.

The compact shorthand I have used here is called a Method Group.

To really understand this I would type for about 10 pages or if you have time watch these videos in this order. Will take a while but they are really high quality and very enjoyable.

https://www.youtube.com/watch?v=v6Zb0nD7PHA&index=1&list=PLdbkZkVDyKZVvizO94tJNmTfRzXWGDFZ3

https://www.youtube.com/watch?v=0nd-tcQcslc&list=PLdbkZkVDyKZVvizO94tJNmTfRzXWGDFZ3&index=2

https://www.youtube.com/watch?v=0qnwc5XqVs0&list=PLdbkZkVDyKZVvizO94tJNmTfRzXWGDFZ3&index=3

https://www.youtube.com/watch?v=WJItr-ecdCE

https://www.youtube.com/watch?v=OqSXsmAAZcw

Finally consider the following progression - think of that image of an ape gradually evolving into a human!

//var lettersOnly = String.Join("", word.ToLower().Where(delegate(char c) { return Char.IsLetter(c); }));
//var lettersOnly = String.Join("", word.ToLower().Where((char c) => { return Char.IsLetter(c); }));
//var lettersOnly = String.Join("", word.ToLower().Where(c => { return Char.IsLetter(c); }));
//var lettersOnly = String.Join("", word.ToLower().Where(c => Char.IsLetter(c)));
var lettersOnly = String.Join("", word.ToLower().Where(Char.IsLetter));
ddanbe commented: Gee man, again great stuff! +15
DaveAmour 160 Mmmmmm beer Featured Poster

How about this:

using System;
using System.Linq;

namespace Palindrome
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("racecar: " + "racecar".IsPalindrome());
            Console.WriteLine("dad: " + "dad".IsPalindrome());
            Console.WriteLine("mum: " + "mum".IsPalindrome());
            Console.WriteLine("dog: " + "dog".IsPalindrome());
            Console.WriteLine("floor: " + "floor".IsPalindrome());
            Console.WriteLine("Racecar: " + "Racecar".IsPalindrome());
            Console.WriteLine("Rac ecar: " + "Rac ecar".IsPalindrome());
            Console.WriteLine("Racecar': " + "Racecar'".IsPalindrome());

            Console.ReadKey();
        }
    }

    public static class StringExtensions
    {
        public static bool IsPalindrome(this string word)
        {
            var lettersOnly = String.Join("", word.ToLower().Where(Char.IsLetter));

            var reversedWord = String.Join("", lettersOnly.Reverse());

            return lettersOnly == reversedWord;        
        }
    }
}
ddanbe commented: Great LINQ! +15
DaveAmour 160 Mmmmmm beer Featured Poster

I haven't done this for a long time but used to use something called Index Server. This indexed certain folders which you specified and you queried index server much like you query a database - this was mainly for searching file contents I think.

You can certainly see what kind of simillar technologies are available these days. Depends if you are searching file names/types only or contents as well.

Also how often do your folder contents change? If not too often then caching is a defination consideration.

Also are you searching just in file names or contents as well?

If just the former you could cache the whole thing in memory and even cache search results in memory too so if person a searches the same as person b did 10 minutes ago then the results are there in memory already.

Hope that helps.

DaveAmour 160 Mmmmmm beer Featured Poster

If you are iterating over a collection which has enumerable properties then you can use foreach. For example:

foreach (var customer in customers)
{
    Console.WriteLine(customer.FirstName + " " + customer.LastName);
}

You could also achieve the same with a for loop:

for (var i = 0; i < customers.Count; i ++)
{
    Console.WriteLine(customers[i].FirstName + " " + customers[i].LastName);
}

In this case the first is more readable and easier to code right?

If you want to do a loop for some other reason though such as not iterating over a collectio but doing something x times then maybe a for loop is better. Also a for loop gives you access to the number of iterations you are on. So if you want to output:

1 Dave Amour
2 Fred Bloggs
3 Sarah Smith

Then there may be a case for using a for loop - it's up to you to make that call though.

Note - in order to be able to use foreach then the collection you are iterating over must implement IEnumberable or IEumerable<T>. Almost all collections do.

Here is a console app you can tinker with.

using System;
using System.Collections.Generic;

namespace ForeachVerusForLoop
{
    class Program
    {
        static void Main(string[] args)
        {
            var customers = GetCustomers();

            foreach (var customer in customers)
            {
                Console.WriteLine(customer.FirstName + " " + customer.LastName);
            }

            for (var i = 0; i < customers.Count; i ++)
            {
                Console.WriteLine(customers[i].FirstName + " " + customers[i].LastName);
            }

            Console.ReadKey();
        }

        static List<Customer> …
DaveAmour 160 Mmmmmm beer Featured Poster

You can call a function from anywhere.

You can call a function from main and this function inside it's body can call other functions. Those other functions can also call functions. This is how you build up complex applications.

A recursive function is one that calls itself. This is often used for things like traversing a directory structure or things of that nature.

There are many good tutorials on this.

Check out the following for example.

http://www.zentut.com/c-tutorial/c-recursive-function/
http://www.programiz.com/c-programming/c-recursion
http://www.cprogramming.com/tutorial/lesson16.html

Hope that helps.

DaveAmour 160 Mmmmmm beer Featured Poster

Database Replication is one term for synching databases - particularly when talking about SQL Server. Not sure about the other term - could be multi tenant?

DaveAmour 160 Mmmmmm beer Featured Poster

Here is one way.

using System;
using System.Linq;

namespace ForEach
{
    class Program
    {
        static void Main(string[] args)
        {
            const string s = "111\n222\n333";

            foreach (var line in s.Split('\n').ToArray())
            {
                if (line == "333")
                {
                    Console.WriteLine("Found the 333 number");
                }
            }

            Console.ReadKey();

        }
    }
}
DaveAmour 160 Mmmmmm beer Featured Poster

It just means you are declaring a variable called flag and giving it a value of 1 or 0. This will presumably be used elsewhere in the code to keep a track of the state of something. It is also probably boolean in nature.

DaveAmour 160 Mmmmmm beer Featured Poster

Read a book, watch some videos, take a class, find a provate tutor, read a website.

The above advice also applies to T in HowToLearn<T>

DaveAmour 160 Mmmmmm beer Featured Poster

Antony, this is a serious question...

Do you think we can give you an answer to this without knowing your database schema?

DaveAmour 160 Mmmmmm beer Featured Poster

Which course is this for?

DaveAmour 160 Mmmmmm beer Featured Poster

Hi Suzie

If I have read things right you are asking for a good way to reuse some code library you have written right? Eg a logging utility for example.

I can show you a few ways of doing this but have you also considered using nuget with third party code as well? If you don't use nuget I can happily explain what it is an how to use it.

DaveAmour 160 Mmmmmm beer Featured Poster

Hi

Sorry I'm a bit late coming to this thread now but pretty much agree with everything that has been said.

Do use self describing names for variables and methods though. So Iterate is maybe not the best method name - I would rethink that one.

Also naming conventions for things like variable names and method names etc are not set in stone and there are many standards out there. For me though and for most programmers I work with we tend to stick to the same standards as the framework code. Since our code is interspersed with framework code this makes sense. It is also I find a pretty well used standard across the industry. How do I know this? I've had about 40 jobs in IT as I'm a contractor so its based on experience.

So for:

MMatrix MA = new MMatrix(r, c);

I would use lower case for ma and also would use a whole, self describing word.

If you have time the video below is full of fantasic advice from a talented programmer and teacher and is also very funny too. He does also include a section on naming variables, methods etc.

https://www.youtube.com/watch?v=_Zqhs1IhGx4

ddanbe commented: Thanks for the advise. +15
DaveAmour 160 Mmmmmm beer Featured Poster

Here it is in a cleaner, more elegant way. It's much better this way.

if (ModelState.IsValid)
{
    if(db.products.Any(p => p.Name == product.Name))
    {
        ModelState.AddModelError("txtName","Product Name already exists.");
    }
    else
    {
        db.products.Add(product);
        db.SaveChanges();
        return RedirectToAction("Index");
    }
}
DaveAmour 160 Mmmmmm beer Featured Poster

Is it possible. Certainly. Operating systems are not trival though.

The ones we have today are the result of probably millions of man hours so I wish you the best of luck!

Mpradeep commented: thanks sir.....mr.daveAmour +0
DaveAmour 160 Mmmmmm beer Featured Poster
DaveAmour 160 Mmmmmm beer Featured Poster

insteadof echo $b, append a$ to C$ with a comma each time you go through your foreach. You will need a little finesse to make sure you don't end up with a comma at the very end.

DaveAmour 160 Mmmmmm beer Featured Poster

There are many ways you can do this. Perhaps the simplest is just to restructure your html slightly with:

        <div id="units">
            My Company Name
            <p>
                My company Address<br />
                <span>My Company Contact Numbers</span>
            </p>
        </div>

With CSS there are probably a dozen ways of doing it but the above seems least effort. PS You spelled Company wrong too!

DaveAmour 160 Mmmmmm beer Featured Poster

Ok no worries, you can always just send me a bag of cash if you like!

DaveAmour 160 Mmmmmm beer Featured Poster

Hi Suzie

Does this help?

using System;

namespace DaniWebDates
{
    class Program
    {
        static void Main(string[] args)
        {
            string d1 = "2015-04-04 00:06";

            Console.WriteLine(ConvertDate(d1));

            Console.ReadKey();

        }

        static DateTime ConvertDate(string s)
        {
            return Convert.ToInt32(s.Substring(11, 2)) < 5 ? DateTime.Parse(s).AddDays(-1) : DateTime.Parse(s);
        }
    }
}
DaveAmour 160 Mmmmmm beer Featured Poster

Ok I see.

Well first of all I am not a C++ programmer so cannot give you C++ code. I can give you pseudo code though.

Generate a random number between 1 and 9

Store this in a string

Generate another number between 1 and 9 and if this isn't already in the string, store it otherwise repeat. Use a loop for this.

Repeat the above x times or in this case 3 times in total. Wrap the above in a for statement.

Return the string cast to a number

Does that help? This is just one way of coding this off the top of my head.

DaveAmour 160 Mmmmmm beer Featured Poster

@wojciech1 - please don't hijack my posts as my problems don't get answered as the thread becomes all about you and people forget about my actual question - eg the CV thread for example.

Thank you.

DaveAmour 160 Mmmmmm beer Featured Poster

I'm not sure I understand your question as I think it could be worded slighly better but possibly you need loopback enabled.

Check out http://opensimulator.org/wiki/NAT_Loopback_Routers

DaveAmour 160 Mmmmmm beer Featured Poster
DaveAmour 160 Mmmmmm beer Featured Poster

Hi

Ok I'm really not clear on what you are asking here.

So I took your code and got it to compile - a few typos etc but got something working. I then renamed things and played around with it to give it more context - I find things easier to understand that way otherwise it all gets a bit abstract and dificult to follow!

I don't know if how I have renamed things and played around with them conveys your intentions or not but it does at least give us a working code baseline from which to start further discussions.

Hope what I have done helps, if not fire away.

using System;

namespace DaniWeb.Inheritance
{
    class Program
    {
        static void Main(string[] args)
        {
            IntegerFactory integerFactory = new IntegerFactory();
            StringFactory stringFactory = new StringFactory();

            var anInteger = integerFactory.BaseMethod();

            var aString = stringFactory.BaseMethod();

            Console.WriteLine("anInteger is type {0} and T is {1}", anInteger.GetType(), anInteger.GenericType);
            Console.WriteLine("watsit is type {0} and T is {1}", aString.GetType(), aString.GenericType);

            Console.ReadKey();
        }
    }

    public class GenericFactory<T>
    {
        public virtual string Name { get { return "Base"; } }
        public virtual Type GenericType { get { return typeof(T); } }

        public virtual GenericFactory<T> BaseMethod()
        {
            return new GenericFactory<T>();
        }
    }

    public class IntegerFactory : GenericFactory<int>
    {
        public override string Name { get { return "IntegerFactory"; } }

        public override GenericFactory<int> BaseMethod()
        {
            return new IntegerFactory();
        }
    }

    public class StringFactory : GenericFactory<string>
    {
        public override string Name { get { return "StringFactory"; } }

        public override GenericFactory<string> BaseMethod() …
ddanbe commented: Thanks for the "factory" code. +15