Translate

26.3.17

Read 20,000 lines in 3 seconds || .NET Application

Sometimes last year, I was working on this Desktop application (VB.NET) that had to read a large file and run some complex analysis to give output in various formats. 
Anyway, reading the large file took the better part of 5 weeks and I more or less tried all suggested solutions (from stackoverflow & co and MSDN website itself). Nothing. 

I tried datareaders, datatables, tableadapters, xmlserializer, etc ( the whole microsoft file reading arsenal). I cracked my brain alongside my friend and system analyst Adelore Oreoluwa (he's awesome). They were all either too slow, or ineffective. (Some read part of the file and skipped some, some misplaced part of my input data, some simply hung the entire application and consumed large memory).

I finally fixed the problem by reading all my data directly from Excel 2003 (.xls) format, using a dll file got from some spanish programmer friends.  The code snippets are below (in case you ever run into same problem). It read me over 20,000 rows of data in less than 3 seconds and misplaced none of my input. 

Imports Excel    //Of course you know where to put this

Private Sub CheckExcel()
        Dim result As DataSet = Nothing

        If Path.GetExtension(Me.txtfilename.Text).ToLower().Equals(".xls") Then
            'Call the ReadExcelFile function
            Call ReadExcelFile(result)

            'Check that the excel file matches your input template
            Call CheckTemplate(result)
        Else
        End If
 End Sub

Private Sub ReadExcelFile(ByRef result As DataSet)
        Dim stream As FileStream = File.Open(Me.OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
        Dim excelReader As IExcelDataReader

        excelReader = ExcelReaderFactory.CreateBinaryReader(stream)

        result = excelReader.AsDataSet()
        Return
    End Sub


    Private Sub CheckTemplate(ByVal result As DataSet)
        Try
            objTable = result.Tables(0)

          Dim fields(9) As String
            For Each row As DataRow In objTable.Rows
                For j As Int16 = 0 To 8
                    If row(j).ToString <> String.Empty Then
                        fields(j) = row(j).ToString
                    End If
                Next

                Call loadtobase(fields)
            Next
            'MessageBox.Show(objTable.Rows.Count.ToString + " Records Loaded", "Success")
        Catch ex As Exception
            ' MessageBox.Show(ex.ToString)
            Exit Sub
        End Try
    End Sub

||||||--------------------------------------------------------------------------------------|||||||||||||||||||
This code is in VB.Net, I'm sure if C#, F#, or Visual C++ is your thing, you can easily translate to fit your needs. (I can help with the C#, just contact me).

The dll has to be placed in the debug folder, something like: C:\Users\Username\Documents\Visual Studio 2012\Projects\Zeed REgiz\SeedlingRegistry1\SeedlingRegistry\bin\Debug\Excel.dll
(Adjust path to suit your System settings).

The dll file can be found on my github: github.com/C-spydo    . It will work for any .NET language.

20.3.17

Annoying Client || HTTP Error 500 || 18 hours down the drain (II)

Sorry for the long break, back to my narrative.

3 days after working the magic of page cloning for these guyz, they realised it made them look too similar to the guys they were copying, so now, they wanted original designs again. In addition, they also wanted to change the name of the platform entirely. (Did I mention that they had already changed names like twice?).

I conceded to their wishes (didn't really have much of a choice at that stage) and wasted another couple hours of my precious time redesigning the front end. (Time I could have spent perfecting the core of the web application itself. Still, I pulled it off, managed a superman-like sequence of coding marathons to get the middle/backend done.  I congratulated myself for a good job well done and deployed a demo to a dev server.

I was in bliss, already counting my balance in my mind when these guys called again. This time around, they wanted new features on the backend, features they didn't realise they needed but (according to them) expected me to have known they would need it. They didn;'t even talk politely, they spoke like they owned me, and that was when I lost it completely. 

At this point, I regretted  a couple of things:
1. The lack of a super-tight formal contractual agreement before the commencement of the gig.
2. Not collecting more than 70% of my fee upfront..
3. Being  super gentle with them so far all in the spirit of pleasing the clients.  (Learn from my mistake)

I was so angry at them, and more at myself. These guys were talking like they owned me (Nobody does, One main point of being a coder, according to me is that nobody really owns you, it's all in your head, and that head is on your shoulders).

So out of anger, I told them I would get back to them, terminated the call and then went off the grid for them (If you know what I mean).

15.3.17

Annoying Client || HTTP Error 500 || 18 hours down the drain (I)

Getting frustrated with a client can actually mess with your creativity when working on their project.
I just finished deploying a PHP web application a short while ago. Should have been done earlier, but HTTP Internal Error 500 took about 3 hours of my time. But why?

First, this guyz undisputably win the Most Annoying Client Award (For Now).
One of the guys on their team is a "mediocre" web developer (one of those people that know a little HTML & CSS ) and then talk like they've been LAMP Stack expert for 100 years.

The other main guy on their team knows next to nothing about this stuff (fine by me), but has a hard time explaining what they actually want ( because he probably doesn't really understand it himself). He also has the habit of changing his mind on things like a zillion times per day.

First, they told me they wanted a super awesome landing page with heavy animations and all the shebangs. Contrary to my advice about using too much animations on a landing page, they insisted on it, I did my best at that, and they loved it. For less than 24 hours. One of them happened to be in an area with terrible connection and decided to checkout the site demo(using Opera Browser, on his mobile phone) and then he saw the point of my advice.

I was actually happy about the incident, but not at the decision it made them reach. All of a sudden, they had found this wonderful website that looked like what they wanted and they wanted me to clone/ replicate the site. In the spirit of pleasing the client, I did just that. Cloned the site (using some pretty nice tools you might know about), messed around with the content and CSS and voila, their landing page was born. They loved it also, for about 3 days.


..............................will continue very soon, got to take a call.

About Me

I'm gonna be as brief as possible about this:

I am a graduate of computer science, University of Ibadan, Nigeria. Been coding for almost 6 years now and been using computers for about 7 years. I'm a male Nigerian (Yoruba ethnic group) in my early twenties.

I consider myself to be a good programmer(just my own opinion, you make yours) and I know more than 10 programming languages. I've been freelancing for more than 3 years now (though  I take up contract employment from time to time, when I want to) and I'm not doing bad.

On the side, I love doing music in my spare time and I have very good experience in journalism/writing & editing.

Every other detail you need to know, check www.sam.clientserver.com.ng

Thanks.

Welcome

A great programmer once told me to write about my code. Probably its gonna help ease the tension ( you know, meeting deadlines, fixing annoying bugs, working out algorithms and stuff). And probably its gonna help others too, especially those I happened to have introduced or mentored in the world of computing.

Anyways, that is what this blog will be all about. My codes, my projects, the good, the bad, the ugly, the bugs, the bug fixes, the patches, the tricks, the tools, etc,, etc. I will try to keep it as regular as possible, but I'm pretty busy, so , no promises.

I'm writing for myself as much as you, so, welcome as you come along with me