Saturday, January 23, 2010

ClamAV Live CD -> OpenDiagnostics Live CD

I have gone ahead and added more functionality to the the ClamAV Live CD as well as fixed most of the major bugs people have had with kernel mismatches and dell's, but now that ClamAV probably won't be the main use, I have gone ahead and renamed the project to OpenDiagnostics.

I haven't updated my site yet, so the planets are getting a sneak peek of a sort :-).

Currently, I guess the major changes are X and (real)XFCE are installed, but aren't started by default. You are still dropped in runlevel 3, you just have to type startx to get a GUI going. But this gives us use of some awesome tools like wireshark, hardinfo, and clamtk to help fix and diagnose problems with the computer or network at hand. Many new command line tools have been added for benchmarking and stress testing networks, drives, and computers, as well as a slew of little utilities (john with full wordlist in /opt gzipped, apg/otp, weplab, ntfsprogs, netperf, etc...). I am getting up documentation this evening. Cool thing is it is still 300 mb, so a 512 mb USB drive (if they still make them) will work great and give you some extra space for files and stuff you like to keep with you.

You can also use it with the USB Creator in Ubuntu now, so that's a nice thing.

The virus definitions are still being updated daily for ClamAV for those who don't have access to internet all the time.

Download here!

Updates about the CD will be made here from now on if anyone is interested.
Comments/Complaints/Concerns welcome!

Saturday, November 28, 2009

StackOverflowException overriding Page in custom class

I was overriding the Page in a custom class that defined user control specific things that my app would do while being run. Each user control inherited from this UserControl class that inherited from System.Web.UI.UserControl. The problem was every time I tried to access the property, I would get a StackOverflowException. My code:


public new VolatileMinds.Web.Common.Page Page { get { return this.Page as VolatileMinds.Web.Common.Page; } }


ended up looking like this;


public new VolatileMinds.Web.Common.Page { get { return System.Web.HttpContext.Current.Handler as VolatileMinds.Web.Common.Page; } }



The problem was that it was trying to recursively cast the Page over and over again, causing the StackOverflowException. Using the Current.Handler sovles this issue.

NOTE: I don't really use absolute namespaces when doing this stuff, I thought it would be easier, however, to understand what was happening if I did.

Friday, November 13, 2009

Cannot add an entity with a key that is already in use.

I got this error today while working with Linq2Sql.

I had an object "Person".

Person person = new Person();

Person has a property called Child, but the child already exists in the database. I thought that assigning the current child in the DB to the person.Child property would just set the value for the Person and not mess with child. It doesn't quite work that way.


person.Child = dc.Childs.Where(c => c.ChildID == childID).SingleOrDefault();


dc.Persons.InsertOnSubmit(person);
dc.SubmitChanges();


The last line will fail with the aformentioned error. I ended up using the ChildID property instead (the former was the better way for the problem at hand, but setting the child ID worked after adding some additional code) so it looked like this.


person.ChildID = childID;

dc.Persons.InsertOnSubmit(person);
dc.SubmitChanges();


The reason this happens is because  you are trying to save an object that is already in the database.
Nifty.

Wednesday, November 11, 2009

gnump3d on Karmic

Go here: http://packages.debian.org/etch/all/gnump3d/download

download from your favorite mirror.

sudo dpkg -i gnump3d*.deb


rejoice!

Sunday, November 8, 2009

Credit Card Validator in C#

I needed a credit card validator for a few of my projects. I found a few snippets of code throughout google, but nothing really just giving me what I needed, so I wanted to post my class. Maybe it will help others doing the same thing I did.

    public class CardValidator
    {
        public string CardType { get; private set; }
        public bool IsValid { get; private set; }
        public string ResultingError { get; private set; }
       
        public string CardNumber { get; set; }
        public DateTime CardExpiration { get; set; }

        public void Validate()
        {
            IsValid = false;

            if (string.IsNullOrEmpty(CardNumber))
            {
                ResultingError = "Card number empty....";
                return;
            }

            if (CardNumber.Length > 16)
            {
                ResultingError = "Card number too long";
                return;
            }

            foreach (char digit in CardNumber)
            {
                if (!char.IsDigit(digit))
                {
                    ResultingError = "Card number contains invalid characters";
                    return;
                }
            }

            if (CardExpiration < DateTime.Today)
            {
                ResultingError = "Card has expired.";
                return;
            }

            int sum = 0;
            for (int i = CardNumber.Length - 1; i >= 0; i--)
            {
                if (i % 2 == CardNumber.Length % 2)
                {
                    int n = int.Parse(CardNumber.Substring(i, 1)) * 2;
                    sum += (n / 10) + (n % 10);
                }
                else
                {
                    sum += int.Parse(CardNumber.Substring(i, 1));
                }
            }

            IsValid = (sum % 10 == 0);

            if (IsValid == true)
            {
                switch (CardNumber.Substring(0, 1))
                {
                    case "3":
                        CardType = "AMEX/Diners Club/JCB";
                        break;
                    case "4":
                        CardType = "VISA";
                        break;
                    case "5":
                        CardType = "MasterCard";
                        break;
                    case "6":
                        CardType = "Discover";
                        break;
                    default:
                        CardType = "Unknown";
                        break;
                }
            }
            else
            {
                CardType = "Invalid";
            }
        }
    }

Sunday, October 4, 2009

Getting an XmlElement from string in C#

I had a bunch of Xml coming at me in a POST response and needed it to be an XmlElement. I ended up doing writing a quick method that does the trick, but I am not sure if it is the best way (making it an extension method made sense in context).

public XmlElement ToXmlElement (this string xml)
{
XmlDocumentFragment frag = new XmlDocument().CreateDocumentFragment();

frag.InnerXml = xml;

return frag.FirstChild as XmlElement;
}

The problem with this is you have to assume the string you are passing in is well-f0rmed XML.

Friday, September 25, 2009

New ClamAV Live CD update

I updated the ClamAV Live CD to 0.95.2 today (finally). I have been wondering what I want to do with this project the past few months. When I first created the CD, I wanted it to be as small as possible so that I could put it on a 128 MB thumbdrive (or 150 MB mini-cd), so I worked extremely hard trying to get it as small as I could. I needed the CD to run on computers with as little as 128 MB of ram! I also didn't know it would be such a popular tool when I released the iso on my website, so I never included documentation on how to use it, prettied it up, things like that. I liked it the way it was, completely minimal and still gets the job done.

I have, however, gotten requests from a few people (five or so) that ask for it to be more user friendly. I am torn between the ease of use vs portability aspects of the project, so I ask you fellow Ubunteers your opinion. Of those who have used it, do you like the minimal approach, or would you prefer a prettier, more user friendly/graphical tool? Maybe two versions? If I went with the more graphical tool, I would look to utilize the full extent of a normal CD, so I would be including many more tools and such.

Thanks for any feedback!