Working with Excel files using EPPlus and XLSX.JS

February 29, 2016 C#, JavaScript, Opinion, QuickTip, Tools 1 comment

Need to quickly generate an Excel file on the server (.NET) with no headache or need to import  another Excel file in your JS client?

I can recommend two libraries for their simplicity and ease of use.

XLSX.JS

To smooth transitioning from Excel files to electronic handling of data we offered our users possibility of importing data. As our application is web based it meant some JS library to work with Excel files. A bit of complication was that our users over time developed a habit of having all kinds of modifications in their “custom” Excel files. So something that would allow us easily work with different formats was a preference.

XLSX.JS library available on GitHub proved to be a good choice. I could only imagine how much better it is over some monsters that would only work in IE. I think starting documentation is fairly good, so I will just go through some bits and pieces from our use case.

Setting up XLSX.JS and reading files is straight forward: npm or bower, include of file and you are ready to write XLSX.readFile('test.xlsx') or App.XLSX.read(excelBinaryContents, {type: 'binary'}).

Reading as binary is probably a better bet as it will work in IE, though you will have to write some code to implement FileReader.prototype.readAsBinaryString() in IE. You can have a look at our implementation of file-select component on gist.

Using XLSX in your JavaScript is fairly easy, though there might be some hiccups with parsing dates. See this gist.

EPPlus

We also have two use cases where we need to generate Excel file on the server. One was to generate some documentation for business rules so we can have it up to date and share with our users at all times. It was implemented as part of CI that would save a file to a file system. The other use case was downloading of business related data via web interface. These two were super easy to do with open source library called EPPlus.

You just add EPPlus through NuGet and start using (var excelPackage = new ExcelPackage(newFileInfo)). See the gist below. First file demonstrates how to operate with cells and the other one just shows how you can use streams to make file downloadable.

These two libraries really helped me to efficiently implement some of the Excel file business use cases.

Next time I will have to generate Excel file on server or read it on client I will most certainly use these two again.


1 comment


Book Review: Release it! Design and Deploy Production-Ready Software

February 19, 2016 Book Reviews No comments

Book Review: Release it! Design and Deploy Production-Ready Software“Release it!” is an excellent book that makes you and your application prepared for the harsh production world. The book entertains on all kinds of things related to the most important part of development lifecycle – releasing your product and keeping it alive.

The book has four parts – stability, capacity, general design issues, and operations. Each part is introduced by interesting case studies, for instance describing how single unhandled exception costed an airline a day of nightmare and tons of money.

Keywords

Let me list some of the keywords from the book for better idea what the book is about:

  • Part I – Stability: scaling strategies; fail fast; SLA; timeouts; circuit breaker; bulkhead (don’t sink entire ship); common sense on log files; health checks; etc.
  • Part II – Capacity: resource pools; threads; payload sizes; db performance; cookies; caching; etc.
  • Part III – General Design Issues: load balancing; clustering; configurations; networking; security; etc.
  • Part IV – Operations: transparency; statistics; logging; monitoring systems; etc.

Pros

Things that I really liked about the book:

  • It easy to read, provided you have relevant experience
  • Real world case studies
  • “Remember This” sections after most of the chapters (better than boring summaries)
  • Realistic strategies and approaches
  • Business costs and impact discussed

There is a really nice strategy explained on zero-downtime. One, that especially boggles me, was approach related to database upgrade process for zero downtime. The strategy is relatively simple: 1) you extend the system/db and add some bits and pieces so it is backwards compatible, for db it could mean new nullable columns and triggers to fill-in data, 2) you roll out, 3) you cleanup. Easy!

Cons

Not so great things about the book:

  • Some technologies mentioned are somewhat outdated (book released in 2007)
  • Examples are in Java and frameworks mentioned are Java-world, so not totally language agnostic
  • At places a bit too ops heavy

Conclusion

The book will be most useful for developers of large enterprise applications, especially where downtime costs real money.

But, in any case, I would highly recommend any developer, and deployment engineer for that matter, to read this book!



No comments


Book Review: The Design of Everyday Things

February 1, 2016 Book Reviews No comments

TheDesignOfEverydayThings_BookCoverThere were few not so technical books that have made it to my technical reading list last year. One of those was a book called “The Design of Everyday Things”. It can probably be considered a classics for designers, it is also helpful for software developers who do some UI. But it doesn’t harm to read the book even if you have nothing to do with designing anything as it allows to understand how things are designed and why in many cases designer is there to blame and not you when something isn’t working as you were expecting.

For starters, have you even been in situation wondering how that damn thing is working? It could have been a microwave impossible to open or a complicated ticket machine in some country or software written by “lousy” software developers. Just look at the kettle on the book’s cover. Any ideas how to pour water with this kettle?

The book brings many show cases for good and bad design (somewhat dated, though). It explains what a good design means and what are constraints designers have to battle, like time, price and not the least look and feel.

Recently we found out that one of our old applications is not used by users because it is too complicated. At that same time, if used, it could save hours and hours of manual work. It is on our roadmap to rewrite this app, but at least I will have more gear in my tools belt.

I don’t think this is a required reading for software developers, but it definitely enriches your outlook. As a bonus you cal explain your co-workers why a tap in a kitchen is designed is a such and not a different way.



No comments


2016: Where Do You Want to Be In a Year?

January 19, 2016 YearPlanReport 2 comments

Some people say that the best way to motivate yourself is to be inspired and/or desperate. At the moment I don’t feel like I’m any of those two. I was very ambitious and inspired in the past, but I guess things change as you get older.

One thing that still helps me a bit with motivation is planning and recognition of my work by others. You can get inspired just by thinking on what you want to do in your life. Also, in my opinion, planning puts you in somewhat desperate situation as you want to complete items from the list. I don’t know if you like planning or not, but I use it for the above reasons and for the reason of keeping track of greater picture of my life goals.

I’ve been writing year resolution posts on my blog since 2010. There are few things that I’ve learned about planning for a year. It is easy to overestimate what can be done and to lose track if no detailed planning was done. So for this year I want to set somewhat smarter goals and do a detailed elaboration on achieving them. I will break down tasks to monthly tasks and keep track of those separately from this blog, as it will be a total mess to post it here.

92-of-all-new-year-resolutions-fail

Let me start my planning with list of life areas to improve.

I want to improve:

  • health by running regularly and doing some gym
  • life satisfaction by travelling and having more quality time with family
  • soft skills by copying the best characteristics of people I admire
  • professional skills by learning one or two technologies and doing a personal project
  • foreign languages proficiency by acquiring German B1 and fixing English accent
  • financials by learning more on investing, keeping expenses low and deciding on home purchase

Now let me convert this list into some concrete achievable and measurable items.

  1. Run 2-3 times a week for at least 5 warm months.
  2. Make start of the day more healthy and productive. Ideal scenario would be: get up at 05:55AM, drink glass of water, do exercises for 15-30 min, shower, some important task and/or planning for the day, breakfast, work… But I will consider this item achieved if I start doing exercises regularly even if it is only 2 times a week just for 10 minutes.
  3. Travel to the UK, Norway, sea side country, and do a car trip somewhere nice.
  4. Spend one hour every day with my daughter playing and learning things.
  5. Count not more than 12 weekends in a year when we didn’t go out to do some activities.
  6. Learn 12 simple skills from other people. To achieve this goal I will first identify 12 people from the community and those surrounding me and chose some characteristic I admire.
  7. Read at least 6 technical books.
  8. Watch at least 12 pluralsight courses.
  9. Write a simple stock analysing web site. It could have any set of features, point is to get something interesting running.
  10. Write any simple useful open source tool. I have WCF related idea in mind.
  11. Learn at least two web technologies. I have NodeJS and AngularJS in mind at the moment.
  12. Share knowledge more actively. Minimum would be to write 24 blog posts, answer 12 questions on SO, help few people online.
  13. Acquire B1 German certificate, attend German course, finish entire German Duolingo tree.
  14. Learn English language prosody and fix pronunciation of vowels. Optionally attend a specialized language course.
  15. Save 24X my monthly spendings, go through 13 investment books I read in 2015 and extract notes, do reviews and write about them.

In the end of this year I don’t want to find myself among those 92% who fail with their new year’s resolutions, therefore keep an eye on me and I promise I will keep an eye on you, provided that you share your list with me.

Happy New Year!

 

2016-Feb-01 UPDATE: This is how I’m now tracking completion of the above list. I have a broken-down list of tasks for each month in OneNote and I also have recurring and detailed tasks tasks in Wunderlist app.

ExampleOfTrackingNewYearResolutionList


2 comments


What I have done in 2015

January 15, 2016 YearPlanReport No comments

Year 2015 was the year of travel.

AndriyBudayInIceland_1500_500

In the resolution for 2015 we only planned for Iceland and the coast of Italy. But now I wouldn’t even be able to count the number of countries we visited in just one year with our little daughter.

I somehow managed to take short vacations almost every warm month. For that I had to work some additional time, but extra effort was definitely worth the experience. Outside of Schengen Area we went to Turkey and Israel and in Schengen Area itself there are only two countries left where we haven’t been.

I was so much engaged in enjoying my life that didn’t progress that well with my professional life, but on the other hand I expanded and improved some other areas of my life by travelling, investing and doing sports.

Now let’s go through the resolution list:

Travel to Iceland

It was the greatest trip of all we had so far. My wife wrote series of blog posts on this trip (in Ukrainian).

Travel the coast of Italy and do many other car trips

Italy was a week and two days car trip from Austria, but besides of this one we had two Nordic car trips. We drove all the way to Finland from Austria and also took a hired car from Germany to Sweden. I legally set my speed record of 220km/h. I drove two absolutely different car types in Iceland and Israel – two absolutely opposite countries by weather and security situation. Contrast between these two countries is just staggering. You cannot appreciate it unless you visit those two.

Improve German by attending at least 1 course

Attended two courses and hopefully learned something.

Improve English fluency and vocabulary by spending more time on learning words from read books

Subjective, but I guess there is some improvement. I indeed spent some time after reading books on vocabulary. Next big milestone should be my accent.

Read 4 sci-fi books

Done. Enjoyed some.

Read 13 software engineering books

Partially done. Unfortunately, I started way too many of them and haven’t finished reading. Notable mention would be “C# in Depth”.

Read 13 investment books

All done. This was my list. Will have a separate review list, maybe with ratings.

Start project with potential to make money

Not really. Had few friendly offers to work on things together, but I didn’t like any.

Do programming in other languages than C# or JavaScript

Total fail. I tried to start learning F# and didn’t get it past few simple “hello world” apps.

Take part in at least one programming contest

SRM at TopCoder, but this probably cannot be considered a “contest”, therefore fail.

Visit at least one conference (even small one)

Visited .concat() in Salzburg

Write at least 26 blog posts

17 blog post written.

Increase community visibility by contributing more on github, tweeting, commenting on blogs

Subjective, but fail.

Improve health by exercising and attending swimming pool for at least 1 month

Rather success than fail. I didn’t attend swimming pool, but I ran for couple of months and will start again when it gets warmer.

Make at least 2015 euro profit on new investments in 2015

Success and fail at the same very time. I didn’t set this goal properly as I didn’t know much about investing. I was up and down as much few times during the past volatile year. I have some very small realized profit, but I’m not so keen on being active investor as it only makes brokers rich. Will tell more when it gets to it.

It is a bit late to say, but I wish you all

HAPPY NEW YEAR!


No comments


Beauty of Open Source in Practice

December 20, 2015 Opinion 2 comments

We found a bug in Internet Explorer. It was acknowledged as such in two months of exhausting e-mail communication and no fix was promised.

We found a bug in open source library. It got fixed over weekend after we raised an issue.

This summarises everything I wanted to share in this post. I have more, so continue reading.

As a disclaimer, I want to say that I don’t attempt to have a comprehensive look at open source versus closed source. This is just an example of what happened in my project.

Closed source code case with Internet Explorer

We use Microsoft technologies wherever possible unless there is no sensible solution to a problem we need to solve. Application we implemented is a large offline capable single page application with tons of controls rendered at once. We noticed that IE crashes after prolonged usage of the app, though we were not experiencing the same in other bowsers. It took us a while to realise that there was a legitimate memory leak in IE. More details on how we tried to troubleshoot the issue are here. Afterwards we started long and boring communication with Microsoft, which ended in them acknowledging a bug in IE. Actually, it was a known bug. They said that attempts to fix this bug caused them more troubles, so it is unlikely that the fix will appear in any of IE11 updates or in Edge browser. We got an approval for our users to use Chrome as it doesn’t have this memory issues and in general is much faster.

Open source code case with Jurassic

The app has plenty of shared logic that we want to execute both on client and server. We decided that we want it to be written in JavaScript. As our backend is .NET we used Jurassic library to compile JavaScript code on the server and then to execute it whenever we needed it. We also tried to use Edge.js, but at the moment we are not happy about its stability when run under IIS.

We stumbled upon an interesting bug. IL code emitted by Jurassic library was causing System.InvalidProgramException on some environments. We narrowed it down to a continue statement used in for loop. We noticed that this was only used in moment.js library. We modified the code of moment.js to avoid using continue statements. This fixed the issue so were already covered by open source since we could modify it. Of course, we didn’t stop there and posted a bug on Jurassic’s forum. The guy had a look over weekend and fixed the issue for us.

Conclusion

Of course, this is just one example where using open source proved to be a nice way to go. It doesn’t always work like that and at times it is a wrong choice. I mainly wanted to share this as it was such a striking and contrasting difference for me personally.


2 comments


Book Review: JavaScript: The Good Parts

November 29, 2015 Book Reviews, JavaScript No comments

TheGoodPartsBook“JavaScript: The Good Parts” is the book I’ve read too late.

I understand that reading a book on JavaScript is not required as there are zillions of free tutorials, StackOverflow, and online documentation.

But because, JS is the language so popular and where it is so easy to start without reading anything, this is how most of developers start. This ends up in painful discoveries, gotchas that took ages to come to and production bugs no one knows how to reproduce.

I, actually, had a half year formal educational course on JavaScript. Unfortunately, I didn’t take it seriously. Code looked similar to C++, so I wrote few functions here and there and it was working.

Earlier this year I went to a conference where Douglas Crockford had a key note. I decided, I’ve got to read his book on JS.

Review

“JavaScript: The Good Parts“ is a quite short book. You can manage to read it in a full day, even with JS Bin open for trying things out. I’ve read it in two sessions like that.

I think if Douglas had only left the good parts of his book then it would be a really great even shorter book on JS.

Most of the book are good parts. I really liked explanations behind certain language behaviour and design decisions. Especially, I liked Appendixes A “Awful Parts” and B “Bad Parts”

In my own opinion, not so good parts are: pointless Shakespeare quotes at the beginning of chapters, redundant code in examples like a loop for creating cat doing ‘r-r-r-r’, few places where something non-JS specific is explained like RegEx, few places where something self-centric was mentioned like “Beautiful Features” chapter.

Conclusion

It is a really good book, but if you have few years of experience in JS and some more in other languages you will find very little to learn from the book.

If you are going to read any book on JavaScript at all, this one definitely has to be in you priority list.



No comments


Book Review: C# in Depth

November 27, 2015 .NET, Book Reviews, C# No comments

C# in Depth, 3rd EditionI’ve been writing C# code for more than 10 years by now and yet had a lot to learn from the book.

The book is written by Jon Skeet (the guy Number One at StackOverflow) and is a purely about the C# language. It distances itself from the .NET framework and libraries supplementing the framework.

Structure of the book follows C# language versions. This isn’t particularly useful if you are trying to learn the language by reading this book after some other introductory book. But for software professionals, though, it could be a joy, since it takes you through your years of experience with the language. It tends to remind you about times when something wasn’t possible and later it became possible. Kind of nostalgia, I would say.

First chapters could be somewhat boring. I read the book cover to cover, since I didn’t want to miss on anything, but probably it isn’t the best way to read the book.

Jon is very pedant when it comes to defining anything. This, of course, is double sided: very good when you have strong knowledge and understand components of the definition, but, unfortunately, it complicates understanding. There were some places in the book which I had to read few times to completely understand. Just for instance, in a chapter about Covariance and Contravariance:

[…] the gist of the topic with respect to delegates is that if it would be valid (in a static typing sense) to call a method and use its return value everywhere that you could invoke an instance of a particular delegate type and use its return value, then that method can be used to create an instance of that delegate type.

Jon Skeet. C# in Depth. Kindle Edition.

On the other hand, I found it very important that details are not omitted. I was reading the book for the depth of it. So details and preciseness is exactly what I was expecting, even though they come with the price of slower comprehension.

You may have different background than I do, but if you are a .NET developer with some years of experience, chances are the only chapters with new and difficult information will be those that are not reflecting everyday practical usage of C# language. For example, all of us use LINQ these days, but very few of us would need to know how it works internally or need to implement their own LINQ provider. Very few of us would dig into DLR or how async/await is working.

Almost in each and every chapter there was something where I could add to my knowledge. For me the most important chapter to read was “Chapter 15. Asynchrony with async/await”, since I have very limited experience in this feature.

Conclusion

In my opinion, the best two books ever for C# programmers are “CLR via C#” and “C# in Depth”, meaning that I just added one to this list.

“C# in Depth” is a great, precise, and thorough book to complement and enrich your knowledge.

I highly recommend reading it.



No comments


Four sci-fi books I’ve read this year

November 9, 2015 Book Reviews No comments

This year I did some science fiction reading. This is something not particularly helpful for software developers in their professional life. Nevertheless, I’ve read four sci-fi books and I would like to share my thoughts on them.

The Dune

Now I understand what is meant when people say “sci-fi classics”. This is really a book that ages very slowly. It is written in nicely phrased English but not too much overcomplicated for non-native speaker.

I remember when I was studying in university, one of my friends would go on and on about some game he was playing. There were huge sand worms and some people called fremen. It is only now that I can refer to this. Even if you are not much into reading sci-fi literature, you must have seen a picture of giant worm in Sahara-like desert somewhere, at least in Facebook with some funny text on it.

I was really surprised to know that this story was written in 1965, it continues in 18 books and many credit it for influencing such things like Star Wars and other great works in sci-fi world.

A top rated quote from the book at goodreads, which I also enjoy, goes like this:

I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past I will turn the inner eye to see its path. Where the fear has gone there will be nothing. Only I will remain.

The Ender’s Game

A quick to read and enjoying story. Just recently I had a chat about world sport champions. Most of us, discussing, have very young children 1+ 2+ 2+ years old. We all agree that for someone to become a world champion a training is needed starting from age of 3 years. One of us told that this is effectively stealing of childhood. Well, probably.

If you want to read about stealing of childhood, Ender’s Game is the right book. Target audience for the book is probably boys 12+, but it reads very well by adults as well. Plus the book somehow manages to bring some big questions into picture.

The Hyperion Cantons

There is probably something wrong with me or with the book or with me reading this particular book. I didn’t enjoy it much. The book is organized in six stories told by six people on a journey to mysterious planet Hyperion. Out of six stories told I liked only two or three. A lot of techno-mambo-jambo was something I extremely didn’t like about the book. The author was just making things up that are no close to existence or in correlation with the science.

This is an actual quote from the book:

To be a true poet is to become God. I tried to explain this to my friends on Heaven’s Gate. ‘Piss, shit,’ I said. ‘Asshole motherfucker, goddamn shit goddamn. Cunt. Pee-pee cunt. Goddamn!’ They shook their heads and smiled, and walked away. Great poets are rarely understood in their own day.

I’m probably one of those who doesn’t understand this. I’m not trying to say that the book is so bad. I was really gripped by the Father’s story. I’m just not sure if the book is something that everyone can enjoy.

The Martian

A have a separate post on “The Martian” available here. “The Martian” is mostly kept within hard science boundaries. And since it is about one of my favourite topics I greatly enjoyed reading it. I also went to see the movie. It was good as well, but as per me the book conveyed many more interesting details. Probably something not so easy to convey into a movie, otherwise it would become extremely boring super long one.


No comments


What is the point of the ‘event’ keyword in C#?

October 31, 2015 .NET, C# No comments

Do you know what a delegate and event are in C#? Can you clearly explain in one-two sentences what the difference between these two is?

It might sound simple as we, .net developers, use these quite frequently. Unfortunately it isn’t that straight forward, especially when you want to be precise. Just try it now aloud.

First difficulty is when you try to differentiate between the delegate type and an instance of a delegate. Next difficulty is when you try to explain events. Your explanation may mention subscribing and unsubscribing to an event. But, hey, you can do exactly the same with a delegate instance by using exactly same “+=” and “-=”. Have you thought about this? The real difference is that with an exposed event it’s about all your external code can do. Instead with an exposed delegate instance external code can do other things like changing the whole invocation list by using “=” or invoking a delegate right away.

An event is nothing more than encapsulation convenience over delegate provided by C# language.

On a conceptual level, an event is probably much more than just some convenience, but that’s beside the point in this post.

To feel the difference all you need is to write some code. Nothing helps to understand things better than writing code and reading quality resources.

Please see below my try on understanding the difference between events and delegates. I added plenty of comments in a try to be explanatory.

Click here to see the gist

Person’s sickness event triggering is responsibility of a person’s internals (stomach, in this example) and it is correct to be encapsulated in the Person’s class, otherwise external code would be able to make a person sick (I like this double-meaning).

Next step is to understand what C# compiler generates when you use the ‘event’ keyword and how else you can declare an event other than in a field-like style. I don’t describe it in this post, I’ve only read about these details, but they are quite interesting as well.

Proficiency in programming language comes with a deep understanding of the basics. I’m proving this to myself every now and then.


No comments