Translate

10.2.18

Strange Thoughts - CSpydo

Sometimes I feel like I'm not as good as the best of coders. And then I go ahead and pull some crazy code stunts (most times, php/ C#, cos I just looooove em). And then I feel like I'm actually really good at thinking crazy ways out of tight corners.

And then I get a phone call about the possibility of joining a pretty cool project as developer. And then I start feeling Awesome again.

And then I realise, I should start my own firm. Wait, I already have a firm. Okay, I should seriously start running my firm seriously for real. Okay, when I'm done with NYSC.

I should start my own cryptocurrency also, maybe call it SpyCoin or some weird name like that.

Okay, finally decided I'm never abandoning my interest/skills/proficiency/experience in music,writing and performing arts also. I'll make it work somehow.

Okay, seriously need to start working on my To-Meet List also.

One more thing. And I totally got this bad habit from Barney Stinson. ...................Wait for It............


                   I ' M totally A . W . E . S . O . M . E

23.1.18

Yoruba Keyboard

Was with the Tech Club at my current workplace ( a high school in Osogbo, Osun State in Nigeria) trying to argue out the differences between the US and French (AZERTY) keyboard with my students.

Somehow, the idea of a Yoruba keyboard, specifically developed to accomodate yoruba alphabets , symbols and accents came about.

Not Software, I mean Hardware. The kind of keyboard you can just plug in anytime you have a yoruba document to type. That was over 24 hours ago, and its still very active in my head.

But I'm gon need some electronics nuts to roll with me  on this. Lets see how it goes.

And if you happen to be interested in working on it, contact me. 

Lookup Cell Value in MS-Excel VB.Net

Ran into a snag with this stuff in a program I was working on recently. Searched online and found a lot of confusing, not really functional answers. So, built on the ideas and came up with this.

Works perfectly, VB.Net, pretty sure any C# person can translate to C#, and hence, Java, etc.


1. Right Click on your project in Visual Studio.
2. Select Add Reference
3. In the Reference Box, Search for Excel
4. Select Microsoft.Interop.Excel from the Results and Click Ok
5. You Should see Microsoft.Interop.Excel under references in your project. That means you are good to go.

6. Put this at the top of your code  Imports Excell = Microsoft.Office.Interop.Excel

And Here is the method itself:


Public Function OpenExcelData(ByVal FileName As String, ByVal SheetName As String,
                                  ByVal column As Integer, ByVal row As Integer)
        Dim vvalue As Decimal = 0
        Dim dvalue As Object = vbNull
        If IO.File.Exists(FileName) Then
            Dim Proceed As Boolean = False
            Dim xlApp As Excell.Application = Nothing
            Dim xlWorkBooks As Excell.Workbooks = Nothing
            Dim xlWorkBook As Excell.Workbook = Nothing
            Dim xlWorkSheet As Excell.Worksheet = Nothing
            Dim xlWorkSheets As Excell.Sheets = Nothing
            Dim xlCells As Excell.Range = Nothing
            xlApp = New Excell.Application
            xlApp.DisplayAlerts = False
            xlWorkBooks = xlApp.Workbooks

            xlWorkBook = xlWorkBooks.Open(FileName)
            'xlApp.Visible = True
            xlWorkSheets = xlWorkBook.Sheets


            Dim wsno As Integer = 0
            If (sheetparam = 2) Then
                wsno = 1
            ElseIf (sheetparam = 3) Then
                wsno = 2
            End If

            Try
                xlWorkSheet = CType(xlWorkSheets(wsno), Excell.Worksheet)

                Dim xRng As Excell.Range = CType(xlWorkSheet.Cells(row, column), Excell.Range)
                dvalue = xRng.Value()

            Catch os As Exception
                'MessageBox.Show(os.ToString)
            End Try
            vvalue = Decimal.Parse(dvalue)
            xlWorkBook.Close()
            xlApp.UserControl = True
            xlApp.Quit()

            ReleaseComObject(xlCells)
            ReleaseComObject(xlWorkSheets)
            ReleaseComObject(xlWorkSheet)
            ReleaseComObject(xlWorkBook)
            ReleaseComObject(xlWorkBooks)
            ReleaseComObject(xlApp)
        Else
            MessageBox.Show("'" & FileName & "' not located.")
        End If
        Return vvalue
    End Function

    Public Sub ReleaseComObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        End Try
    End Sub


Modify as necessary. Feel free to give your opinion in comments section.

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.