Skip to main content

Posts

How to convert JavaScript Date without time stamp

 At some point when setting pika date min date I had to use JavaScript date variable without time stamp. When you try JavaScript new Date() in browser console, you can see date with time stamp. To remove time stamp what I did was use new Date with year , month and day parameters. new Date(new Date().getFullYear(),new Date().getMonth() , new Date().getDate())

.Net C# match a UK postcode with a regular expression

UK postcode Validation in C# [ RegularExpression (@" ^(([a-zA-Z]{1,2}[0-9][A-Z0-9]?|ASCN|STHL|TDCU|BBND|[BFS]IQQ|PCRN|TKCA) ?[0-9][a-zA-Z]{2}|BFPO ?[0-9]{1,4}|(KY[0-9]|MSR|VG|AI)[ -]?[0-9]{4}|[a-zA-Z]{2} ?[0-9]{2}|GE ?CX|GIR ?0A{2}|SAN ?TA1)$ ", ErrorMessage = "Invalid Post Code.")] public string PostCode { get; set; } Refer -  https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom

Setting attributes of a property in partial classes / Is it possible to add an attribute to a property in a partial class?

Question I have an employee class generated by the  Entity Framework  (EF). public partial class employee { private string name; public string Name { get{return name;} set{ name = value;} } } Now I want to put a required attribute in the name property to use in for MVC3 validation in another employee partial class which is written by me in order to extend the one which is generated by EF so that I don't have to rewrite my code if I refresh the model generated by EF. My written partial class is in the same assembly and namespace. public partial class employee { // What should I write here to add required attribute in the Name property? } Answer It is actually possible only through buddy class but it is not recommended way. You should keep your validation in the custom view model because often you need different validations for different views but your entity can keep only a single set of validation attributes. Examp...

Create and Configure a User in MSSQL

This article will show you how to create and configure a user in MSSQL. Open SQL Server Management Studio (SSMS). Connect to SQL Server using your log in information. In the left-hand panel, expand  Security > Logins . Right click  Logins  and select  New Login  from the drop-down menu. Assign a Login name and select the authentication method and default database/language. Note:  Only Domains can use Windows Authentication. If you are using SQL authentication you will need to enter an initial password and choose the enforcement options for password policy and expiration as well as whether or not the user will need to change their password when they log in. In the left-hand panel, click  Server Roles  to assign any server roles you want this user to have, including  bulkadmin ,  dbcreator ,  public , and so on. In the left-hand panel, click  Securables  and then click  Search . The Ad...

Typescript - Self-Executing Anonymous Functions

/** * Self executing anonymous function using TS. */ (()=> { // Whatever is here will be executed as soon as the script is loaded. console . log ( 'executed' ) })(); I want a built a plugin that may work for Node.js, also for fron-tend as well. In that case you should compile your TypeScript in AMD and use an AMD loader on the frontend, like  http://requirejs.org/docs/start.html On the server side, you would need to use  requirejs  node package as well to load the file. Take a look at this:  http://requirejs.org/docs/node.html Basically there are two ways to compile TS to JS, using AMD, which is browser compliant, or using CommonJS, which is node.js compliant. Loading an AMD script in the browser or in the server needs to use an AMD compliant loader, and *requirejs** is one of them. (the most famous/used I'd say) Ref :  https://stackoverflow.com/questions/30274464/typescript-self-executing-anonymous-functions

TempData keep() vs peek()

When an object in a  TempDataDictionary  is read, it will be marked for deletion at the end of that request. That means if you put something on TempData like TempData [ "value" ] = "someValueForNextRequest" ; And on another request you access it, the value will be there but as soon as you read it, the value will be marked for deletion: //second request, read value and is marked for deletion object value = TempData [ "value" ]; //third request, value is not there as it was deleted at the end of the second request TempData [ "value" ] == null The  Peek  and  Keep  methods allow you to read the value without marking it for deletion. Say we get back to the first request where the value was saved to TempData. With  Peek  you get the value without marking it for deletion with a single call, see  msdn : //second request, PEEK value so it is not deleted at the end of the request object value = TempData . Peek ( "value"...