Friday, July 8, 2022

My First Ever Coding Job Interview

    Now I've worked for a couple companies already which required me to code but believe it or not none of them gave me coding interviews. I basically was thrown into the position and expected to catch up/learn what I had to and just work. Well here is my first ever coding interview and honestly I think I did horrible lol. The interview started off great, the interviewer introduced herself (who she was and how long she has been at the company), very nice person. It was then my turn to introduce myself a bit and I said my name and how I am passionate about code, and solving problems through programming. I don't remember the order of things but I will try to recall as best I can from this point. I believe she then asked me about scenarios on linux and wanted me to tell her what linux commands I would use to solve the scenario. I have linux on my resume but that was supposed to mean that I used linux and can navigate it, I didn't expect to have to remember commands for it, I mean I don't remember all the commands for windows (my daily driver). I guess its time I practice those commands for the future. Anyways now onto the part that I should've been good at.

    The question was very simple (though it wasn't immediately obvious to me because I overthought it). Return the number of days between two dates. The template code she had up was in python and while I don't code in python in my day to day, I've learned it enough through porting code etc to understand it. I then asked if I had to write the solution in python or java, to which she replied I can use any language. C# being my favorite language at the moment was what I chose. Opened Visual studio, created a new .Net 6 project and the first thing I did was recreate the class she had in her python example, no biggie. Afterwards I wrote the beginnings of what would be the GetDifference() method which is what the name of method for the solution was expected to be. Now having dealt with time in the past and all the time zone related stuff I immediately overthought the complexity of the problem. This didn't require time-zones etc but for some reason that idea stuck with me, I didn't realize it immediately, and I began to break even more than I already am. I thought, there is no way she is asking me to calculate date time accurately from scratch right? I asked... "Can I assume that months are exactly 30 days?". She (to my relief) replied yes. I thought "Oh, this should be easy now". I started to code, adding constants for the number of days in a month and months in a year so I can refer to them by name later if need be. This is around the time I realized that non of my questions had any relevance because we weren't dealing with time-zones, shoot we weren't even dealing with time, just dates. While this should make me feel better because the problem isn't as complicated as I had misunderstood it to be (to clarify this is entire my fault, I guess I was going into this expecting a much more complicated problem) but instead this error caused my mind to race. I glance over to her stream, she looked bored of it all (might have been my imagination), I had decided to say what I was doing. In hindsight I guess that was a good decision because talking to myself made me calm down a bit. Unfortunately that wasn't going to last for long. I finished my code, at this point I don't even know what logic I had just laid down, I run the program and immediately I get an error. Red everywhere, I have a micro freak-out to myself. Okay its not so bad. I fix it, this time it actually compiles, but it gives the wrong answer. I'm thinking "I Flopped, there's no recovering from this". She lets me know that the months don't have the same number of days. I thought to myself, "didn't you just say that I can assume that the months have 30 days?", maybe I was hearing things before. I go back to my code, the short little code I had written not long ago, seemed daunting and alien to me. I changed up the design, looking up how many days there were in each month and how many days are in Feb on leap years. I didn't know what I was even doing anymore. I somehow manage to focus on the array I had made to keep count of the number of days per month and from there I was able to focus a bit more on the flow of the code. My answer was off by about double, so I told myself it has to be the loop which counts the days for a year. I go to the loop and I see a potential issue, I added the "- 1". At this point I'm numb, I speak... "I don't know if this will work until i try it I guess", shoot... I didn't mean to say that out loud, I paused for the split second from the awkwardness. I click run, okay it compiles, and to my surprise the result was.... WRONG. I thought "Just kill me", if I cant even write a program to solve this easy problem, then how are they going to believe I have any competence in coding and solving problems. Sorry to say but at this point I had no energy, I was drained and I honestly didn't know where to even start debugging because my mind was in another universe. I was defeated. The defeat I had would be solidified as the interviewer said "its okay, you dont have to get the exact answer". I knew that because the number of days was indeed deterministic there should be no excuse why I couldn't provide the correct exact number. I was maybe 2 weeks off but because of the properties I just stated, that might as well be infinitely wrong.

    We ended the interview on a good note (or just my wish) with smiles although her smile might have been my imagination (she is nice and I was still in lala-land), but my smile was one which took effort to put on. I was a failure, there was nothing I could smile about. I look at my phone, and told my friends about the interview and how I felt about it. Some tried to cheer me up, some jokingly made fun of me, and of course some couldn't care less (these guys help me snap back to reality). I then sat there for a bit thinking about the interview and then tried telling myself "well the problem isn't solved until its solved". I hopped back on visual studios and proceeded to read my code. It's unbelievable how much more clear everything is when anxiety isn't tugging on your heart strings. I had made several mistakes and these where easily spotted if I had just read the code properly. In the ported code, the constructor takes 3 parameters which were day, month, year, in that order and all ints. When I went to create them in "program.cs" I had incorrectly used the wrong format of month, day, year. The dates I put there were probably wrong to begin with since I was dazed as all heck when she was reading them to me. The other issue I found was that the calculation for adding days to the total tally for a year was wrong. I fixed that as well and used https://www.timeanddate.com/date/duration.html to check my answers, each time with different dates. This all took no time at all and yet I couldn't do it during the interview. I thought I'd at least push it up to my git to add to my portfolio lol, for what its worth. I still have an in person interview tomorrow so I really hope I do better there.

ADDED: I forgot that during the coding portion she also pointed at the keyword "internal" and asked what it was for. I didn't really know what she was asking so I replied with "I can turn it to public if you want", I proceeded to change internal to public. She further explained that she wanted to know what it was and what its used for. I told her that it was an access modifier and that it used to let the the rest of the program see the class and its members. Now thinking back on it, maybe that was too simplistic of an explanation? darn it, I did horrible on that whole interview.

IN-PERSON:

    Now the drive there was pretty uneventful but as I got closer and closer to my destination, I can feel my heart rate quicken. I followed the instructions on the email I got for parking and parked the car. I started walking up the hill, with every step I realized more and more where I was. This was not some small startup, I was reminded that this is a big established company. I walk into the building and tell the front desk that I'm there for the interview. I sit and wait in the lobby, and I am dazed, I'm staring out the front window thinking "I can't believe I'm here". My interviewer introduced himself and I immediately missed his name, I reactively ask for his name again and then told him my name. I get my visitor
s sticker and I follow him. We reached the elevators and we got in. Yup just me and him in the elevator, I need to relax, so I breathe deeply but slowly. He breaks the silence by asking me how I pronounced my name, I told him its like saying the letters 'T' and 'N' and furthered it by saying I tell people that if they've watched DragonBall Z its just like the character Tien. Unfortunately he hasn't seen the show so I just reaffirmed that its just the letters 'T' and 'N'. We walk and entered a corner room. Two of the walls were glass and the other two were what seemed to be white boards. He further introduced himself and basically what they do there. I remember thinking this is some official shiz lol. I was then asked to give more of an in depth introduction about myself. I said I was passionate about coding, and I like making tools for people, and my hobby is coding to ultimately get better and learn new things etc. We proceed to talk about my reasons for leaving my previous place of employment and explaining the gap. He then explained to me that not everything there was going to be orderly and optimal and that it isn't going to go my way. I completely understood and thought it was perfectly reasonable. I guess I came off as if I left the old place because they didn't do things perfectly. I hope I reassured him that isn't the case. He was very level with me and honestly great to converse with. We also talked about teamwork and agile. I told him that at my old workplace we did agile but I wasn't too sure if it was what we actually did. By the end of the interview I essentially told him my strengths and weaknesses. I also asked a couple questions like "with the conversation we had thus far, how do you think I fare". He said he saw some of my code on GitHub but unfortunately he didn't look at one I had hoped people would look at which at the moment is BijouDB. I mean the one he looked at wasn't really bad I think but I don't think it is as impressive. Id like to get along with this interviewer seeing as potentially he would be my Lead but also to pick his brain and learn things lol.

Wednesday, March 23, 2022

Photino on Net 6

Photino is a way to develop cross platform applications utilizing web technologies. There is a .Net wrapper for it but it doesn't yet support Net 6 as of writing this, or does it lol. Here is a working snippet for their .Net sample project running on Net 6.

Friday, August 6, 2021

Making a virtual multi-tap using ViGEm/ViGEm.NET

Update 1/24/2022: Updated the download, includes the required but missing file this time, also fixed some bugs which prevents the addition of new controllers.

    So my brother has been playing a game on PCSX2 and its a multiplayer game and he asked me if I could make a program which acts as basically a virtual controller that mimics the actions of the physical controller. Now receiving controller inputs I was familiar with through DirectInput and XInput but simulating/emulating a controller is something I haven't a clue about but I know we have lots of talented people so I did some research. Now I am mainly a C# developer these days so I specifically researched on that front. Sure enough there is a driver for simulating/emulating a controller called ViGEm and even a .net wrapper called ViGEm.NET. With this in hand I did some tests and after all test passing, I proceeded to ask my brother the specifications he would like for the program and off I went. With the driver and wrapper it was easy functionality-wise but most of the work went into handling the mappings and conversions to a DualShock4. Weirdly enough the XBox360 controller emulation didn't work. I went into the discord channel for ViGEm and asked around and they couldn't figure out why either but that was fine, dualshock4 will do.

So I made this:
https://mega.nz/file/7FhWADTZ#mC76AbApajA6TSFJ0mIo3Zvq2k6yEhzJmhX3Epg6Phk

I'll number each step I mention here as a comment in the source here:
https://github.com/TizzyT566/VirtualMultitap

0) This step isn't going to be in the source code but you have to install the ViGEm.NET package which can be found here:
https://www.nuget.org/packages/Nefarius.ViGEm.Client/
Another thing is we have to specify useLegacyV2RuntimeActivationPolicy="true" in the App.config file. Finally you have to have the driver installed which can be obtained here:
https://github.com/ViGEm/ViGEmBus

1) I want to ask the user how many virtual controllers they want, since my brother only asked for up to 4 players thats what I did.

2) Now that I know how many controllers the user wants, we can leave that info for later, we'll come back to it, the first controller related step is to get user inputs for a single controller which will control the virtual controllers. We can do that via Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly). We specify that we only want to get GameControllers that are currently attached. Each device has a device id which is represented by a guid. We can populate a list of these guids to query these controllers later.

3) Lets actually make some virtual controllers now. We first create an instance of the ViGEmClient so we can use it to make the controllers. The number we stored in step 1 will be used to create 2 arrays. One array to store the actual virtual controllers and a second to represent active ones. We want to be able to specify which of the 4 or even all of them to be active on the fly.

4) Now getting back to that list of device guids. We need to be able to single out a master controller for the virtual controllers.

4.1) We are only given the device guids so we cant really tell which device is which unless you memorized the guids. Even then because windows is wonky handing out these ids you'll never be able to distinguish any 2 controllers reliably. So there must be a method to detect which controller you want instead of selecting from a list. In this case I made it so that if the user selects 0, it would go into a sort of detection mode where the user physically presses a button on the controller they want to act as the master controller. To do that we create an array of devices and populate it with aquired devices using the guids from the list we created earlier. We have to make sure to se the data that comes back from the device be joystick data. Then we loop through the device array over and over again until one of the controllers DPad or buttons are pressed, and we make note of that device, setting it to a variable. To clean up we iterate over the device array one last time to Unacquire all the controllers we arent using.

4.2) If the user selects an option other than 0, the first thing we need to do is decrement the selected option by 1 since 0 was taking the place for Detecting a controller in step 4.1. We then initialize a Device using the selected guid. We set the dataformat and acquire it and make note of it just like in step 4.1.

5) Now that we have the master controller established we need to deal with the mappings. I decided to store the mappings in the Documents\Virtual Multitap folder. If the folder doesn't exist yet, we create it. We construct the mapping's full file path using the guid. The JoyStickState structure doesn't correlate directly with how the DualShock4 is mapped in ViGEm so I just associated one mapping to another using indexes. We loop over and over again for each input for a DualShock4 controller, mapping all buttons, sliders, axises, and the viewpoint (aka DPad). Finally I save the mapping with each dualshock4 input on a separate line in Document\Virtual Multitap\<guid>.

6) We now load the mapping we just made or load one if one already exists for that device guid.

7) The last thing to do in our routine is to kick off a loop to listen for keyboard presses and events on the physical controller and simulate them on the virtual controller. I don't use a regular loop, instead I use a SpinWait(). This allows the loop to process relatively fast while not hogging a bunch of CPU.

Friday, November 13, 2020

Mouse Speed Profiler

UPDATE 1.1: Previous versions lost profiles because the mouse ids would change upon system restarts etc. That has hopefully been resolved with this version. Download link updated.

    
So I work from home or more recently at a friends house. I use my friends computer to get work done but he has multiple mice, and they are all set to different DPI settings and every time I use one or the other I have to go into the mouse control panel, and adjust the cursor speed setting so that its comfortable. I decided it would be some what fun and useful if I made a program to automate the process either entirely or as much as possible. I had an idea which later turned out not to work. I was originally going to poll the mice with DirectX and using their DeviceInstance GUIDs. But I couldn't distinguish the mice from each other. What ever I did I could not associate mouse data separately. I went to researching, It turns out that since DirectX 9.0 Microsoft has pulled the plug on unique mouse and keyboard instances. All mice are merged together into one GUID and that's that, same with Keyboard it seem (haven't tested but was mentioned). So I thought, lets go the RawInput route, I hated this route as this wouldn't allow me to Poll anymore from a console application. Not only was RawInput a pain in the ass to get working properly, it didn't seem like anyone really had any real examples online on how to go about doing it. People seemed to always be very vague like, "you need a window, have the window register for rawinputs", I'm over here think "is there any chance I can make DirectX work" but no I finally found some sample code which semi worked. The code sometimes worked... well rarely worked, more times then not it would crash the program and this is the demo program the author made. The crash wasn't normal either, no error messages, codes or anything, it simply just closed the program. So I went to troubleshooting and debugging. Voila!!! now that I can distinguish between multiple mice, I can now work on getting and setting the windows mouse speed setting. This wasn't so bad, some MSDN C++ docs and P/Invokes later and it was all done. Finally I have to turn these functionalities into an application.

    When the program runs, it loads a "speed.prf" file (if it exists) which stores any mouse profiles. While its running and becomes focused (via Alt+Tab) you can switch to which ever mouse you want to use. A new mouse window will popup if a new mouse has been detected. You give the mouse profile a name (the mouse id is used as default), and you set what you want the windows mouse speed to be and click save; while you are moving the slider the mouse speed is set accordingly as well. You can then do the same with another mouse, etc. Now the next time you want to switch mice, you Alt+Tab to the profiler, and just start using the mouse you want.

DOWNLOAD:
https://mega.nz/file/rFow1b4S#qUNEYFMNhKf-3wqbML9bawgAxF9VOvUtin3fdDBpDo4

Wednesday, July 8, 2020

A very basic Sudoku game

   Here is a Sudoku game I made a long time ago, going through my old projects I came across it and I thought why not put this up on my blog since I haven't posted anything in a while anyways. I might come back to this but writing it from scratch since this was written in vb.net and I have since moved mostly to C# with that maybe new features etc.

DOWNLOAD: https://mega.nz/file/jZ4DWQQK#xrQgbgHqIbsNs0VEnYeMfgbAomof8L3R9hmI-J5aoWA