Recover deleted files by VisualStudio

Image this: You are working on a new functionality. You open up your IDE and start hacking away. You create several new files, invest your time and effort and then you accidentally delete the wrong file. No problem, that’s what we have Git for, right? But you forgot to add that now deleted file to version control. Aaarrrrggh. There is no way to retrieve that lost file. Bad, bad stupid little programmer. There is one little hack to save you (if you are in Windows): Locate the folder of deleted file and press Ctrl-Z. That will undo your deletion. It …

Continue Reading

Difference between async loops in C#

What do you think will happen when you run these 2 snippets of code? They both looks quite similar at the first sight, don’t they. This one var results = new List<SomeClass>(); mylist.ForEach(async item => { var result = await SomeDbQueryAsync(item); results.Add(result); }); versus this one var results = new List<SomeClass>(); foreach(var item in mylist) { var result = await SomeDbQueryAsync(item); results.Add(result); }); The code looks remarkably similar, but the 1st sample will throw this exception “A second operation started on this context before a previous asynchronous operation completed. Use ‘await’ to ensure that any asynchronous operations have completed before …

Continue Reading

VisualStudio has problem when multiple versions of Typescript are installed

You can have several versions of Typescript installed on your machine and each project in Visual Studio can be configured to use different version by specifying that version in .csproj file. Like this But you might still have problems with IntelliSense for some native javascript objects. VisualStudio uses file lib.d.ts  to learn interfaces of window objects, events, etc. This lib.d.ts is updated with each version of typescript you install. When some interface become obsolete, it is removed from lib.d.ts, and VisualStudio then marks usage of such an interface as invalid and refuses to build. Now you have problem. You can either manually update …

Continue Reading

In defence of literate programming

We tend to write code differently when we know that someone will be reading it, don’t we … [Josh Johnston, X-Team] The thing is, you should always try to write (and rewrite) your code so that it is as clear as possible. Not only because of your possible code-reviewer, but also because of yoour future self. What may seem obvious to you at the time when you are writing code, might be quite unclear at the time when you read it half a year later. You will spent long time just trying to understand your old code. So, next time you …

Continue Reading

Hledám kancelář

PROSÍM O SDÍLENÍ Od 1.1.2016 budu pracovat na volné noze a potřebuji si najít nějakou pěknou kancelář. Nechci být celý den zavřený v kanceláři úplně sám, takže bych se rád k někomu připojil nebo našel někoho, kdo se připojí ke mně. Jsem programátor, takže k práci potřebuji klid na soustředění. Potřebuji také dobré světlo, aby mě nebolely oči a neleskl se monitor. Většinou pracuji ve stoje se sluchátky na uších, takže se nebudeme moc rušit. Ideální by bylo najít někoho s podobnými požadavky na práci: ticho, světlo, příjemný prostor a stabilní rychlý internet. Lokalita: Liberec nebo velmi blízké okolí  

Continue Reading

How to set VisualStudio 2015 to always run “as Administrator” in Windows 10

You might have the same problem like me after upgrading to Visual Studio 2015. The project could not be loaded because it depended on IIS and to run IIS it needed administration rights. Solution? Run VS as Administrator. Better still? Make sure that it always runs under administrator rights. Just follow these simple steps 1) Local Visual Studio in Startup menu   2) Right click and select “Troubleshoot compatibility”     3) Select “troubleshoot program” 4) Raise permissions

Continue Reading

C# Coding conventions

These coding conventions were originally written by my colleagues Filip Kassovic and Michal Třešňák in ST-Software. I have only made slight updates and published it on my blog. Do not use “var” keyword when not necessary var response = SomeClass.SomeMethod(input); Reason we don’t see the type of “response” “Find Usages” or “Find all references” doesn’t find usage of type when using “var” Exceptions obviously, you have to use it for anonymous types var anonymous = new { A = 1, B = 2 }; Do not use complex object initializer PaymentTransaction transaction = new PaymentTransaction { Token = statusResponse.RefNo, Error = …

Continue Reading

Download files via POST request in AngularJs

There are times when you need to download file but the download is initiated via POST request, because the request contains too much parameters to fit into limited GET request. In my case I needed to generate ZIP file. First you need to define custom method on your $resource which will handle the download method, like in the example below. Have a look at the transformResponse method. It creates a Blob from the server response (binary representation of the Zip file) and tries to extracts the file name from response headers. Then you need to define method on controller. User clicks button “Download ZIP”, your …

Continue Reading

How to write for-loop like code in SQL

I needed to dynamically generate missing items in database. I had a list of Sports and Categories, and I needed to generate items with all combinations of these two entities. But some of them already existed in database, so those should be skipped. My idea was to perform kind of for-each loop iterating over the Sports collection, but written in SQL. In each iteration I would check if given combination already exist in DB and if not, I create it. SQL Cursor comes to help If you run into issues with another coding technique and need to get something done …

Continue Reading