Posts

Showing posts from 2019

Finding Partitions of a number

So recently i got a question from my friend Sameera who had this requirement.  Given a number N , he wanted to generate all possible combinations of n1,n2 where n1 + n2 = N For example if i give you 25 , you should output : 1,24 2,23 3,22 4,21 5,20 6,19 7,18 9,16 10,15 11,14 12,13 But he had an additional condition as well , these number pairs should not contain  an addition which involves a carry  .  ( As a non native English speaker this is the first time i even heard that word :) ) So that means in the above example if i gave you 25 , you should only output: 1,24 2,23 3,22 4,21 5,20 10,15 11,14 12,13 Notice that i have left out  6,19 7,18 9,16 Because adding them involves transferring 1 digit from one place to another. ( Please excuse my language as i am not a mathematician or well versed in maths so im trying to explain this in layman idiot terms here ). Ok , so in addition to the above mentioned

Sending a POST request in Simple Javascript

So recently i wanted to send a POST request to one of my backends using only simple plain Javascript. Found this code on Quora which worked nicely. Code : xhr = new XMLHttpRequest (); var url = "url" ; xhr . open ( "POST" , url , true ); xhr . setRequestHeader ( "Content-type" , "application/json" ); xhr . onreadystatechange = function () { if ( xhr . readyState == 4 && xhr . status == 200 ) { var json = JSON . parse ( xhr . responseText ); console . log ( json . email + ", " + json . name ) } } var data = JSON . stringify ({ "email" : "tomb@raider.com" , "name" : "LaraCroft" }); xhr . send ( data );

How to Debug NodeJs Easily

Found this great article on how to easily debug NodeJs using VSCode https://medium.com/the-node-js-collection/debug-your-node-js-app-in-60-seconds-9ee942a453f0

Angular for Dinosaurs : How i got started after being out of the game

Image
So you are a software developer who has been living away from the action for a while and suddenly when you came back to the real world , everyone is talking about all these fancy JavaScript frameworks and you have no effing clue how to get started ? Do not worry as your man gaba was on that same place a few months back . I used to work in a product company for 5 years , during that time i hardly had time to work with any new technologies specially JavaScript ( despite being a front end developer earlier in my career ). So finally when i decided to try my hand at Angular , needles to say i was confused with all the jargon and fancy JS stuff going around. But after a few months of effort i was able to come to terms with Angular and now i can say that i can manage an Angular project on my own! Of course i am no expert , but i'm good enough to manage the day to day work using the popular framework. So without further delays let me tell you how i crawled from under the rock an

Mysterious Errors in Visual Studio

Today i encountered this weird error after i upgraded one of my Kentico   projects to a new version.  The problem was , i added newer versions of some existing DLL file references to my Visual Studio solution and when i ran the build , it gave me mysterious errors ! Mysterious because even though there is no error seemingly , it gives the red error message and the whole deal. So after much googling i realized that it was my stupid mistake which caused all of this.  Cause of the error was : My project was built on an older .NET version than the one which the new DLLs were built on. So i did not get a clear error message but some generic "missing references" message. p.s - I know i am too stupid to not infer the cause from the "missing reference" message :P . But i will just post this for any future idiots like my self stuck in a rut.

SQL Case Statement

The S QL CASE Statement is a very handy little feature.  I recently had to update several rows of a table at once and i used it to good effect. I have no idea how it will perform when it comes to large updates but for a small amount of rows it works like a charm. Picked up from this SO thread. Multiple update UPDATE config SET config_value = CASE config_name WHEN 'name1' THEN 'value' WHEN 'name2' THEN 'value2' ELSE config_value END WHERE config_name IN ( 'name1' , 'name2' );

How to merge two different GIT repositories sitting on two different places

So recently in office i had to push the code that i was working with to my client's own code repository. My code base was on Gitlab and client had his own repo on BitBucket. Basically the same code base but on two different places. So how do i merge my code into client's repo ? i found this answer HERE on this great article . But i will explain what i did step by step just to make it clear to you. Let's assume that my requirement is to merge a repo called my-source into my-target . my-source is on Gitlab and my-target is on BitBucket. Here are the steps. 1. Clone  my-target on your trusty computer in a preferred folder. 2. Add the source ( the repo which you are trying to merge into your target ) as shown below to the local repo you cloned in step 1. git remote add -f my-source https://git.myawesomecodebase.com/my-source.git 3. You're almost there , now merge your branches together. In the following example i'm merging a branch called develop into my t

OneNote Code Format plugin

If you are using OneNote like me to keep your shit together and ever wondered why this does not have a built in code formatting option, then your worry days are over. No one wants to see their code lying around without formatting in plain text form , so make use of this plugin to make things prettier. https://www.makeuseof.com/tag/programmer-onenote-coding-add-on/