Saturday, April 18, 2020

HttpWebRequest, String.Join and formatting code

Weekly wrap:

1. When you work with Visual Studio 2010 you are grateful for posts such as this on Stack Overflow.

I needed to make post request using .NET framework 4.0. In the top rated answer, the methods C and D work with .NET framework 2.0+

I ended up using the Method C which used HttpWebRequest


2. Actually working with C# I had never used String.Join() before. In fact, I knew about python's .join() routine before C#. In the language of python, there is definitely a push by the programmers and by the creators to write as little code as possible (they call it pythonic). But even C# has a similar routine and I think it is pretty useful:



3. By the way I formatted the above code using gists on github. More info in this SO post


Sunday, December 9, 2018

Job Crawlers

Did you know you can create job crawlers with python? I won't say it is easy but it is not rocket science either. I have uploaded a crawler in the github link below.

It crawls and creates a dictionary of jobs from Caesars Entertainment company
    You can view the jobs on their careers page: https://caesars.taleo.net/careersection/czr_ext_cs/jobsearch.ftl?lang=en&portal=8100120159

A json request is created with the appropriate body and headers. The json response is then parsed to create a dictionary of jobs

GitHub link: https://github.com/rsk2/job-crawlers/tree/master/Job%20Crawlers

Convert ASP.NET GridView to Excel the right way

This sample VB.NET code over comes following limitations of using the Interop dll:
1. RegisterForEventValidation can only be called during Render https://stackoverflow.com/questions/7228718/registerforeventvalidation-can-only-be-called-during-render
2. GridView must be placed inside a form tag with runat=“server” even after the GridView is within a form tag https://stackoverflow.com/questions/6343630/gridview-must-be-placed-inside-a-form-tag-with-runat-server-even-after-the-gri


Github link: https://github.com/rsk2/export-gridview-to-excel



Monday, May 28, 2018

Why is the web page taking a long time to load?

Is this a good question to ask during interviews? I do feel like it tests the problem-solving skills of candidates. Can he/she tell me all the possible causes? Can the break the issue down to its components? Can they identify the different items that can cause problems?

Further, if they do say there is something wrong with the server code ( which is normally their top answer) , I can dig deeper into their ideas on improving the efficiency of the code. 

Sunday, March 4, 2018

Shared Programming

Programming doesn't need to be a lonely activity. I'd love for it to be taught, shared, discussed and debated on.



Saturday, March 3, 2018

Get the Gridview row, row index which fired the RowCommand event

Here is the code snippet:

Public Sub gvTestGrid_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvTestGrid.RowCommand
Dim gvr As GridViewRow = CType(CType(e.CommandSource, LinkButton).NamingContainer,           GridViewRow)
Dim rowIndex As Integer = gvr.RowIndex
//Make a label visible in this row
CType(gvr.FindControl("UserSelected"), Label).Visible = True
End Sub


This assumes you have ItemTemplate column in your GridView (gvTestGrid) containing a label with Id="UserSelected" which is hidden by default.

Type of parameter is not CLS-compliant

So it's just another normal day, I am coding and coding and coding and suddenly this squiggly line shows up!
Oh no! The squiggly line of death you ask?? Not quite it's like a caterpillar and not much more than that really. It's not dreaded, deceitful or deadly. So I am pretty sure I won't die and neither would my laptop.


This squiggly line appeared below a function parameter. On closer inspection, as I hover my mouse over the caterpillar,  a message pops up saying that "Type of parameter 'someVariableName' is not CLS compliant. "
First time I have seen that error. Now if you'll want more details of the error you can find it here
In my specific case, this was caused because 'Unsigned types should not be part of the public interface of the class'. This particular function was being made public and the parameter in question was a enumerator type.
Which means ..... (drum roll)...........
Enums are stored as unsigned integers by default!
No, no they are not. Actually, here is the real reason why I got the compiler warning:
"The method was being publicly exposing from an assembly marked as CLS-Compliant a type that is from an assembly that is not CLS-Compliant.
This post on SO helped