baavgai's Profile User Rating: *****

Reputation: 5835 Overlord
Group:
Mentors
Active Posts:
12,690 (5.01 per day)
Joined:
16-October 07
Profile Views:
122,325
Last Active:
User is offline Today, 08:24 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
725
Expert In:
C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

Latest Visitors

Icon   baavgai has not set their status

Posts I've Made

  1. In Topic: project for developing my skills in OOP

    Posted 23 Sep 2014

    I like cards. A simple blackjack game is a good choice.

    The Card itself is an object. The Deck, with methods like Card deal() {. A player's hand.

    Cards, in particular, are fun, because they have ranks and suits and several ways to describe them in strings. Blackjack has a quirk in that an Ace can change value.

    You could do a vending machine, if you're really jazzed by vending machines. Choose something smallish that will hold your interest. Chess is not smallish; it's more of a torture test. Keep chess in mind for the future, but don't make it a learning project.
  2. In Topic: Program to Count Uppercase and Lowercase Characters

    Posted 23 Sep 2014

    Glad you got it, but you really are trying too hard. If you simply count everything...

    Also, you have some warnings and a gets.

    Here's another approach:
    #include <stdio.h>
    #include <string.h>
    
    int main() {
        char string[100];
        int c, counts[256] = {0};
    
        // error
        // printf("Enter a string:\t", string);
        printf("Enter a string:\t");
        // never, never, never, gets(string); 
        fgets (string, 100, stdin);
    
        while ( string[c] != '\0' ) { counts[string[c++]]++; }
    
        for (c = 'a'; c<='z'; c++ ) {
            if( counts[c] != 0 ) { printf("%c : %d\n",c, counts[c]); }
        }
        for (c = 'A'; c<='Z'; c++ ) {
            if( counts[c] != 0 ) { printf("%c : %d\n",c, counts[c]); }
        }
        return 0;
    }
    
    


    Alternately, you could have a single loop and print out the ones you like. However, since you're putting lower before upper, that would be awkward. You could also play with functions here, if you like.

    Overall, good work. Happy programming.
  3. In Topic: Determinate type of object and pass it through method

    Posted 22 Sep 2014

    For now, forget objects. I don't honestly see that you're currently using them in a meaningful way. Instead, think about configuration. Things like paths and all the other moving parts.

    If you can see how OO would help, use it. However, you currently seem only confused by it; so don't use it.

    How would I improve what I see? I'd strip out all the gratuitous classes and just get the thing to run. I'd organized into classes later, as needed.

    e.g.
    class Server {
        public string ServiceHttpAdress { get; }
        public string xml_outputFP { get; }
    }
    
    enum LogMsgType { ERROR, INFO, WARNING, FATAL }
    
    class StatisticPaths {
        public string RequestFileName { get; set; }
        public string RequestFullPath { get; set; }
        public string ResultFileName { get; set; }
        public string ResultFullPath { get; set; }
        public string ExcelFileName { get; set; }
        public string ExcelFP { get; set; }
        public string RequestFileTemplateFullPath { get; set; }
        public StatisticPaths() { }
    }
    
    class MyClient {
        public enum KPI { LSP, LSPInventory, MEM, CPU };
        public enum FtpResult { Success, CopyError, DeleteError };
    
        private readonly Server server;
        private readonly IDictionary<KPI, StatisticPaths> allPaths;
        public MyClient(Server server, IDictionary<KPI, StatisticPaths> allPaths) {
            this.server = server;
            this.allPaths = allPaths;
        }
    
        public IEnumerable<string> GetAttributes(KPI kpi) {
            List<string> attrs = new List<string>();
            if (kpi == KPI.LSP) {
                attrs.Add("ElemStartTimeInPrograme");
                attrs.Add("testedObject");
                attrs.Add("minimumRoundTripTime");
                attrs.Add("maximumRoundTripTime");
                attrs.Add("averageRoundTripTime");
                attrs.Add("packetsSent");
                attrs.Add("responsesReceived");
                attrs.Add("packetSize");
                attrs.Add("packetsLost");
                attrs.Add("lossPercentage");
                attrs.Add("timeCaptured");
                attrs.Add("timedout");
            }
            return attrs;
        }
    
        public string LogDir { get; set; }
    
        //public static void MyFTP(string xml_outputFP, string ResultFullPath, string ResultFileName, KPIName kpiName, out bool isErrorWithCopy, out bool isErrorWithDelete) {
        public FtpResult Ftp(KPI kpi) {
            // your code here
            return FtpResult.Success;
        }
        public DataTable CreateDataTable(IEnumerable<string> attrs) { return null; }
    
        private void ProcessReponse(KPI kpi, WebResponse res) {
            if (kpi == KPI.LSPInventory) {
                using (var rd = new StreamReader(res.GetResponseStream())) {
                    var xdoc = new XmlDocument();
                    xdoc.LoadXml(rd.ReadToEnd());
                    xdoc.Save(allPaths[kpi].ResultFullPath);
                }
            }
        }
    
        private void Log(LogMsgType t, string msg) { /* your code here */  }
    
        private DataTable FillDTByXMLResult(KPI kpi, DataTable dt) {
            /* your code here */
            return dt;
        }
    
        public bool ExportToExcel(DataTable dt) { return false; /* your code here */ }
    
        public bool ExecuteSOAP(KPI kpi) {
            var success = true;
            var paths = allPaths[kpi];
            try {
                var request = (HttpWebRequest)WebRequest.Create(server.ServiceHttpAdress);
                request.Headers.Add(@"SOAP:Action");
                request.ContentType = "text/xml;charset=\"utf-8\"";
                request.Accept = "text/xml";
                request.Method = "POST";
    
                using (var fileRequestStream = File.OpenRead(paths.RequestFullPath)) {
                    using (Stream webRequestStream = request.GetRequestStream()) {
                        fileRequestStream.CopyTo(webRequestStream);
                    }
                }
                using (WebResponse response = request.GetResponse()) { ProcessReponse(kpi, response); }
            } catch (Exception ex) {
                success = false;
                Log(LogMsgType.ERROR, "inside ExecuteSOAP method for " + kpi + " error message: " + ex.ToString());
            }
            return success;
        }
    
    
        private void CallExecuteSoapSuccess(KPI kpi) {
            var name = kpi.ToString();
            var AttributesList = CreateDataTable(GetAttributes(kpi));
            FillDTByXMLResult(kpi, AttributesList);
            if (AttributesList.Rows.Count != 0) {
                Log(LogMsgType.INFO, "Putting results to Excel");
                if (ExportToExcel(AttributesList)) {
                    Log(LogMsgType.INFO, "Done with " + name + " part");
                }
            } else {
                Log(LogMsgType.ERROR, name + " Result file is empty");
            }
            Log(LogMsgType.INFO, "Ending LSP at: " + DateTime.Now);
        }
    
    
    
        public void CallExecuteSoap(KPI kpi) {
            var name = kpi.ToString();
            Log(LogMsgType.INFO, "Starting " + name + " at: " + DateTime.Now);
            Log(LogMsgType.INFO, "Aligning date for previous day...");
            Log(LogMsgType.INFO, "Starting " + name + " request...");
            if (ExecuteSOAP(kpi)) {
                var ftpResult = Ftp(kpi);
                if (ftpResult == FtpResult.CopyError) {
                    Log(LogMsgType.ERROR, name + " process aborted due to FTP download file failed " + DateTime.Now);
                } else if (ftpResult == FtpResult.DeleteError) {
                    Log(LogMsgType.WARNING, "Couldnt delete file from FTP location for: " + name);
                } else {
                    CallExecuteSoapSuccess(kpi);
                }
            } else {
                Log(LogMsgType.FATAL, name + " process aborted due to ExecuteSOAp method failed " + DateTime.Now);
            }
        }
    
    
    
    }
    
    static class Program {
        static void Main(string[] args) {
            var client = new MyClient(null, null); // these wouldn't be null
            foreach (var kpi in new MyClient.KPI[] { MyClient.KPI.LSP, MyClient.KPI.MEM, MyClient.KPI.CPU }) {
                client.CallExecuteSoap(kpi);
            }
        }
    }
    
    
  4. In Topic: Need help adding an array of items to a linked list

    Posted 22 Sep 2014

    You're not allowed to use what is clearly the most appropriate method? Is this bad programming 101?

    Your LinkedList class exposes the entire node implementation, which is horrid. However, with this, you could really show off why it's bad.

    Oh, wait, looks like your method belongs to the class you can't change? So you can change it?

    Using any method but addLast, you can create a new list, then just replace the current one. e.g.:
    public void addAll(T[] items) {
        LinearLinkedList newList = new LinearLinkedList();
        for (int i = items.length-1; i>=0; i--) { newList.addFirst(items[i]; }
        while(!isEmpty()) { newList.addFirst(removeFirst()); }
        setFirstNode(newList.getFirstNode());
    }
    
    


    Hope this helps.
  5. In Topic: Help with SQL query

    Posted 21 Sep 2014

    So...
    Users
        UserID PK
        Name 
    Messages
        MessageID PK
        Content
        DateTime
        From FK Users(UserID)
        To FK Users(UserID)
    
    


    Given this, finding all the Messages for UserID=1 would look something like:
    select m.*, f.Name as FromUser, t.Name as ToUser,
        from Messages m
            inner join Users f on m.From=f.UserID
            inner join Users t on t.To=t.UserID
        where m.From=1 or m.To=1
    
    


    At this point, a ConversationID make no sense. Now, if you wanted something with conversations, I'd reconsider your structure. e.g.
    Conversation
        ConversationID PK
        StartedDt
    
    Message
        MessageID PK
        ConversationID FK
        UserID FK
        DateTime
        Content
    
    -- and, perhaps
    ConversationMember
        ConversationID PK FK
        UserID PK FK
    
    


    You could normalize that a little, I suppose:
    Speaker
        SpeakerID PK
        ConversationID FK
        UserID FK
        Unique(ConversationID, UserID)
    Message
        MessageID PK
        SpeakerID FK
        DateTime
        Content
    
    


    Hope this helps.

My Information

Member Title:
Dreaming Coder
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Location:
Jersey, be afraid.
Years Programming:
25
Programming Languages:
Most.

Contact Information

E-mail:
Click here to e-mail me
Website URL:
Website URL  http://

Comments

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  1. Photo

    8byte Icon

    10 Jan 2014 - 11:08
    Awesome, thanks for all the help!
  2. Photo

    codiddle Icon

    07 Mar 2013 - 18:59
    GENIUS GUY HERE MAN. Write a book!
  3. Photo

    mamelove25 Icon

    19 Feb 2013 - 10:53
    Hello My Dear, My Name is Mame. i saw your profile today and became interested in you,i will also like to know you more,and if you can send an email to my email address,i will give you my pictures here is my email address (mame25live@yahoo.co.uk) I believe we can move from here! Am waiting for your mail to my email address above because i have much to tell you,
    love Miss Mame.
  4. Photo

    bilbil0629 Icon

    24 Oct 2012 - 05:39
    hey! you mongolian?
  5. Photo

    Ticon Icon

    20 Aug 2012 - 13:23
    I just noticed your an expert in cheese. I lol'd
  6. Photo

    mostyfriedman Icon

    18 Aug 2012 - 23:13
    Hello there Brett
  7. Photo

    MehrdadSecret Icon

    26 Jul 2012 - 05:51
    hello, can i have a contact email or Yahoo or something? Need ur help badly
  8. Photo

    Jeet.in Icon

    18 Apr 2012 - 23:17
    Thanks ! Solved My problem !
    http://www.dreamincode.net/forums/topic/275578-simple-whitespace-remover/page__gopid__1603556&#entry1603556
  9. Photo

    RetardedGenius Icon

    25 Oct 2011 - 14:29
    I agree so much with your opinion of incompetent CS teachers. So true!
    http://www.dreamincode.net/forums/topic/252848-venting-a-frustration/page__view__findpost__p__1469659
  10. Photo

    WabiSabi Icon

    21 Oct 2011 - 11:00
    I agree with assert(C). However, I'd rather not specify what you are "the best" at.
  11. Photo

    assert(C) Icon

    20 Oct 2011 - 08:38
    You are the best
  12. Photo

    macosxnerd101 Icon

    30 Sep 2011 - 09:33
    Congrats on hitting the big 3k!
  13. Photo

    sjin Icon

    16 Aug 2011 - 18:41
    This guy is AWESOME! Cheers bro!
  14. Photo

    hulla Icon

    02 Aug 2011 - 02:50
    Wow that's alot of programming languages... :O
  15. Photo

    Aphex19 Icon

    04 Jul 2011 - 16:54
    Kudos to you baavgai, the most well deserved mentor on DIC in my opinion.
  • (3 Pages)
  • +
  • 1
  • 2
  • 3