AndreiR23

Stories submitted by AndreiR23

Improving your Visual Studio experience : MetalScroll(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 6 months ago

I've heard of RockScroll from Scott Hanselman a while ago in his blog entry. The Visual Studio plug-in basically replaces the vertical scroll bar with a real time thumbnail of the code. Plus it highlights words if you double-click them. It's niiiiceee!! I've soon downloaded it and used since then (more than a year). However lacking the ease of using the window split, having parasyte double click highlightings and desynchronizing when you collapse a region of code annoyed me for a while... Until today!! Scott did it again and twitted about a good replacement for RockScroll : MetalScroll. It does all RockScroll does plus : * double-clicking the scrollbar brings up an options dialog where the color scheme and scrollbar width can be altered. * the widget at the top of the scrollbar which splits the editor into two panes is still usable when the add-in is active. * you must hold down ALT when double-clicking a word to highlight all its occurrences in the file. RockScroll highlights words on regular double-click, which can be annoying when you actually meant to use drag&drop text editing, for example when dragging a variable to the watches window. ... read more...

add a comment |category: |Views: 31

tags: another

200 Page Manual on Inversion of Control (plus or minus 199)(blog.wekeroad.com)

submitted by AndreiR23AndreiR23(75) 2 years, 7 months ago

Very nice and simple explanation of DI / IoC with an example in ASP.NET MVC. read more...

add a comment |category: |Views: 18

tags: another

A Configuration Section for inline unconstrained XML in .config file(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 8 months ago

In case you need to include a portion of an XML in your app.config or web.config file use this :) read more...

add a comment |category: |Views: 7

tags: another

Creating a reusable class - with all the goodies - Final analysys(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 8 months ago

I've decided to write a class that would model a SSN-like personal identification number used in Romania. It should be useful both in production code and as a learning material for my readers. In the first part I've shown a preliminary analysys and further analysys in the second part. Validation logic and what interfaces to implement is what is left for this part. Let's see the fragments that can be validated so we'll see how to model the validation flow. The first digit (the fragments can be seen in the first part) can have values from 1 to 9 so all possible values are valid. Nothing to validate here. The second fragment is the year. Also all possible values (00 to 99) are valid so nothing to validate here. The fun starts at the next fragment, the month. Only 01 to 12 values are valid anything outside (00, 13, 14, ..., 99) are invalid as they don't represent a valid year. The dating fun gets even hotter at the day. Although 00, 32, 33 and so on values are obviously invalid, some values are valid only in some months or some years. 29th of february is valid in 2008 but not in 2009. 31 is valid in January but not in April. 30 is valid in April but not in February and so on. Next, the county has a list of predefined values as shown here, in the specs, so their validations should be piece of cake. The Enum.IsDefined (remember from the previous part that I've decided to use an enum for the county) should be a snap :) The index value must only not be 000 any other value is valid. This brings us to the final check : the check digit. The algorithm is moderately complex (as in not really 1+1 but something close) as seen in the specs : You take the PNC without the last (check) digit and put it next to the predefined value 279146358279. Next you multiply the first digit of the PNC to be validated to the first digit of this special validation value. Then you store it. Then you take the 2nd digit of your PNC and the 2nd digit of the special value and multiply it and you add it (the product) to the previously stored number and so on until you finish. In the end you have a sum of products that you will modulo by 11 and have a result : for 0..9 this is the final result. For 10 the result will be 1. This is the check digit. Enough theory, let's test it on my PNC : My PNC : 1810623420056 The validation value : 279146358279 1 x 2 = 2; Partial-result (PR) : 2 8 x 7 = 56; PR : 56 + 2 = 58 1 x 9 = 9; PR : 67 0 x 1 = 0; PR : 67 read more...

add a comment |category: |Views: 5

tags: another

Creating a reusable class - with all the goodies - Further analysys(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 8 months ago

In the first part we've layed out the basic requirements and had a glance of the data the class would model. In short it would model a SSN-like identificator for romanian citizens. Let's see what properties and methods the class should expose and what interfaces should be implemented and how. Basic data : Sex Foreigner or native Resident Birth date Birth county Index Check digit Extra information : The raw value A list of violations (if any) A boolean to quickly see if the instance is valid or not Let's make a quick range check and see what data type we could choose for the underlying (raw) value : The smallest valid PNC could be 1010100010011 (male, January 1st, 1900, born in Alba, first born in that day and the last digit, the check digit I am too lazy to compute it - we'll see later and - its value won't change the calculations much). The largest valid could be 9311299529999 (non-resident foreigner born on December 31st, 1999 and so on..). The range would be 9311299529999 - 1010100010011 = 8,301,199,519,988 Now this is larger than Int32's (2 billion and something) and UInt32's (4 billion and something) maximum values so Int64 is the smallest numeric data type that could fit the raw value. It also fits the value without using an offset (having the raw value stored as a difference between a minimum value and the actual value) which simplifies the storage logic. Having it fit in an Int64 is reassuring that at least on 64bits OSs + CPUs the operations on it will be fast. Let's go back to the public properties now. The sex property could have been a simple boolean and set up a convention to set true for one sex and false for the other (I won't go in deep phylosophical discussion whether men or women are "true" :P ). However value 9 for the first digit screws things up as it does not specify the sex. Sure, a nullable boolean could be in order but I will choose an enum over this one. Let's call it PersonBirthSex and assign three values for it : Male, Female and Unknown (for 9'ers). The Foreigner property can very well be a bool just like Resident. The BirthDate will be a DateTime. For the county of birth an enum will fit the bill. Index is always positive and has values from 1 to 999 inclusive. So the nicest fit will be the UInt16 (ushort) type. The check digit is from 1 to 9 inclusive so a byte should do the trick. Having settled on the public properties, their types and the raw value type we read more...

add a comment |category: |Views: 7

tags: another

Creating a reusable class - with all the goodies - Preliminary analysy(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 8 months ago

I always wanted to build a class that could have some value in the real life and that could serve as an example for some (good) practices. It seems that I have the opportunity right now. In every country, mine included, there is some sort of identification number, unique for all its citizens. In the US there is the SSN and in Romania there is a PNC (CNP spelled in romanian) which stands for Personal Numeric Code. Some applications (web sites and other kinds) may require you, at some point, to specify a valid PNC. These apps usually validate it (lightly most of them) and none of them I've seen to take advantage of the info the PNC conveys for pre-filling certain fields. This sparked me the idea to write a dedicated class for this. The specifications for this romanian SSN (the PNC) can be found on Wikipedia : translated to english version and romanian (original version). In short there are 13 digits like so : S YY MM DD CC III X S represents the sex and the century of the birth date. Odd digits for males and even digits for females. 1 and 2 for 20th century, 3 and 4 for 19th century, 5 and 6 for 21st century, 7 and 8 for resident foreigners and 9 for non-resident foreigners YY represents the two-digit version of the birth date's year MM the same for the month DD the same for the day of the month CC represents the two-digit code of the county of birth III represents an index number - unique per county per day and finally X represents the check digit Not very complicated, isn't it? Let's take mine for example : 1810623420056 So: I am a male, born in the 20th century (1) I was born in 1981 .. in June on the 23rd day in the 42 county (that is Bucharest, 2nd district) The fifth in the birth center and the check digit is 6 What I would like from a class that models this entity : To have a parameterless (default constructor) so it can be easily serializable To not throw exceptions in the other constructors if the data is bogus but rather to sum up a list of violations (for example the day is 32) To be bind friendly in Winforms, WPF, ASP.NET Web forms and ASP.NET MVC To expose a read/write property (we'll call it "Value") to enable easy binding with the ASP.NET MVC's default binder The XML serialization should take minimal space (only relevant data should be serialized and elements and attributes should have short names - but still understandable) The same for binary serialization It should implement ICo read more...

add a comment |category: |Views: 4

tags: another

How to write unmaintanable code - anti patterns(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 8 months ago

Let's get started : Be Abstract In naming functions and variables, make heavy use of abstract words like it, everything, data, handle, stuff, do, routine, perform and the digits e.g. routineX48, PerformDataFunction, DoIt, HandleStuff and do_args_method. Abstract notions : Programmers are lulled into complacency by conventions. By every once in a while, by subtly violating convention, you force him to read every line of your code with a magnifying glass. You might get the idea that every language feature makes code unmaintainable — not so, only if properly misused. Naming conventions seem to be a mantra : Bedazzling Names Choose variable names with irrelevant emotional connotation. e.g.: marypoppins = (superman + starship) / god; This confuses the reader because they have difficulty disassociating the emotional connotations of the words from the logic they’re trying to think about. Reuse of Global Names as Private Declare a global array in module A, and a private one of the same name in the header file for module B, so that it appears that it’s the global array you are using in module B, but it isn’t. Make no reference in the comments to this duplication. Something that I thought people should go to jail for : Overload new Overload the “new” operator - much more dangerous than overloading the +-/*. This can cause total havoc if overloaded to do something different from it’s original function (but vital to the object’s function so it’s very difficult to change). This should ensure users trying to create a dynamic instance get really stumped. You can combine this with the case sensitivity trickalso have a member function, and variable called “New”. ... If by now you are not convinced that this is an article worth reading I assure you the samples shown by me here don't cover more than 10% of the material there. read more...

add a comment |category: |Views: 20

tags: another

[Humor] Smart mom / SQL Injection(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 8 months ago

Did you really named your son Robert'); DROP TABLE Students; -- ? read more...

add a comment |category: |Views: 9

tags: another

Using ADO.NET Data Servics in Silverlight 3 and eager loading parent e(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 9 months ago

We decided (well my boss decided :P ) that in our Silverlight app that we develop we should not waste time writing WCF services manually to interact with data. So we turned to ADO.NET Data Servics. I created a small Web App to host the ADO.NET Data Service which exposed the Entity Framework Model. All fine and dandy, being a bit pedant I created a very small console application just to add a service reference and test the data retrieval. All went well. Then I put the querying logic in the Silverlight app. Something like var employees = (from e in GetFreshContext().Employees select e).ToArray(); But upon running in Silverlight (in the console app it ran great) I get thrown with this exception : System.NotSupportedException: Specified method is not supported. read more...

add a comment |category: |Views: 12

tags: another

Solving automatic properties compile problems when migrating ASP.NET 2(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 9 months ago

I've recently migrated/adapted a web site built on ASP.NET 2.0 (.NET Framework 2.0) to .NET Framework 3.5. Oh the goodies of .NET Framework 3.5 : LINQ, lambdas, automatic properties and so on. At first I just set the build option to .NET Framework 3.5 : Everything fine and dandy till I ran the site : WTF? I mean it is set to use the .NET Framework 3.5... read more...

add a comment |category: |Views: 6

tags: another

Carefully test your sensitive code(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 9 months ago

am also working on a site that will handle real money. I was having a little hard time determining why the users don’t get their money back if the bet (a bets site) is cancelled In the CancelBet stored procedure (T-SQL) : .. UPDATE Account SET Amount = Account.Amount + BB.Amount FROM BetBettings BB INNER JOIN BetOutcomes BO ON BB.BetOutcomesId = BO.BetsId WHERE BO.BetsId = @BetId AND Account.UserId = BB.UserId … The bold-underlined text fragment should have been "BO.Id". A very small slip-up but enough to not trigger any automatic checking in Microsoft SQL Server Management Studio 2008 and enough to have the users cry out loud : “FRAUUUD”. The site is not live yet, so no user has been hurt during the experiment. However anyone wouldn’t have believed me that this error in favor of the site was not intentional … they would have said something like “how convenient…”. read more...

add a comment |category: |Views: 5

tags: another

LINQ to SQL NullReferenceException gotcha(blog.andrei.rinea.ro)

submitted by AndreiR23AndreiR23(75) 2 years, 9 months ago

In my DAL (Data Access Layer) assembly (a LINQ-to-SQL centric assembly) I used to insert object into the database like this public void CreateMessage(MyApp.Entities.Message message) { Message m = new Message(); // this is the LINQ-to-SQL generated Message class not the business entity class m.UserId = message.UserId; //... set all the properties accordingly DataContext ctx = new DataCo... read more...

add a comment |category: |Views: 16

tags: another