Continuous Integration Summary

Software Development
Every time that somebody commits any change, the entire application is built and a comprehensive set of automated tests is run against it. If build or tests fail, the development team stops and fixes it immediately. The goal is that the software is in a working state all the time. Check In regularly so that changes keep small and less likely to break the build. Use proper log descriptions on check ins. Never Check In a Broken Build as that breaks the continuous integration. Always run all Commit Tests Locally before Committing or get your CI (Continuous Integration) Server to do it for you. Wait for Commit Tests to pass before moving on. If commits are done frequently any crash should be a small piece to fix, if left unbroken,…
Read More

Introduction to MVC for Web Forms developers

Web programming
Oh yes, there are lots of guides, tutorials and videotutorials out there explaining you (or trying to) what MVC is or how it works, but when you have been for many years developing with Visual Studio and Web Forms you feel like if you are missing something and feel uncomfortable. So I decided to write this guide for Web Forms developers getting into .Net MVC. Breaking the Forms limit First of all, forget it. If WebForms was called WebForms was for a reason, and the reason is (as you know) that it depends a bit too much on web forms. Every page in WebForms has a Form covering all the page, every postback, button, textbox is included into that form and, if you want to use two different forms for…
Read More

Reviewing Impress.js book

Web design
I was given the opportunity a few days ago of reviewing an impress.js's book wrote by Rakhitha Nimesh. As I said a year ago, impress.js is a javascript library that allows you to create impressive presentations like this one. The original idea seems to come from Prezi, but for all of us who like programming, making our own tools and storing our presentations in our own server, impress.js becomes our ally. This book covers an introduction to impress.js, teaches the basics of how to install it, create elements, position them, interact with them and make transitions etc. But goes beyond that explaining you how to create websites using impress.js to totally crash the limits and make the perfect portafolio (something I'm looking forward to try myself!). Also, the book includes…
Read More

Installing a local script with Greasemonkey

Other, Web programming
Though greasemonkey is thought to share your scripts with the community, you may prefer to have some script for personal websites, local applications or just very personal customization of a page. Most greasemonkey tutorials show you how to install a script stored online but forget about how to create your own script and install it in local: Quick guide Install Greasemonkey Click on Greasemonkey icon -> Manage scripts -> New User Script... Create your script following GM rules and save it. If you already have the script, open it with the browser (you can drag and drop the file into the browser or use "Open with...") and the install window will appear immediately (install button has a few seconds wait for security issues though). Writing your own script If you…
Read More

Requesting to C# MVC.Net using jQuery.Ajax

Web programming
Basic Call Let's just make a call to the server to get a single value: We'll call this JS function, for example, using a button like <input type="button" onclick="SingleCall();"/>: [sourcecode language="js" wraplines="false"] function SingleCall() { var url = '@Url.Action("AJAXRequest", "AJAX")'; jQuery.ajax({ url: url, success: function (data) { console.log('Returned data is: ' + data); //Note: Remember though data is an int it's returned as a string, // so if you want to get it as int you need to use parseInt() } }); } [/sourcecode] And have this simple Controller (I've created a Controller called AJAX, but you can use any Controller for these requests). [sourcecode language="csharp" wraplines="false"] public partial class AJAXController : Controller { public virtual int AJAXRequest() { return 5; } } [/sourcecode] Adding parameters to our call The…
Read More

SQL Server Quick statements

Web programming
Change Table name [sourcecode language="sql" wraplines="false"] EXEC sp_rename 'OriginalName', 'NewName' [/sourcecode] Change Column name [sourcecode language="sql" wraplines="false"] sys.sp_rename 'TableName.ColumnName', 'NewColumnName' [/sourcecode] Add Foreign Key [sourcecode language="sql" wraplines="false"] ALTER TABLE dbo.[TableName] ADD CONSTRAINT FK_Table1Name_Table2Name FOREIGN KEY (Table1ForeignColumnName) REFERENCES dbo.[Table2Name](ID) ON UPDATE NO ACTION ON DELETE NO ACTION GO [/sourcecode] Note: The name of the constraint "FK_Table1_Table2" should have the name of the table with the foreign key first, and the table with the main id second as a standard. Removing Foreign Key Constraint As these constraints normally have a standarized name we should be able to do this: [sourcecode language="sql" wraplines="false"] ALTER TABLE tablename DROP CONSTRAINT ConstraintName -- Normally ConstraintName is FK_Table1Name_Table2Name where Table1 references Table2 Primary Key [/sourcecode] In case you want to get the constraint name programatically: // TODO…
Read More

Removing constraints programatically in SQL Server

Web programming
Default Constraint [sourcecode language="sql" wraplines="false"] declare @key nvarchar(200); select @key = c.name from sys.all_columns a inner join sys.tables b on a.object_id = b.object_id inner join sys.default_constraints c on a.default_object_id = c.object_id where b.name='tablename' and a.name = 'columnname' exec('alter table tablename drop constraint ' + @key) // in case you wanted to remove the column alter table tablename drop column columnname [/sourcecode] Foreign Key Constraint [sourcecode language="sql" wraplines="false"] SELECT KCU.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU WHERE KCU.TABLE_NAME = 'Message' AND KCU.COLUMN_NAME = 'MaintenanceID' [/sourcecode]
Read More

Improving your website’s performance

Software Architecture, Web programming
Using Cache One of the best ways to improve your website's performance is by using cache. That way you can save lots of db requests and server processing time. Using Cache for static data Let's start by caching all those reference tables with user roles, categories, error messages, cities, countries, etc. Normally this uses minimal cache and saves thousands of db requests, probably the best improvement possible. Caching often requested dynamic data Imagine you have a real state website for the UK with thousands of possible requests on it (as there are thousands of cities, towns, combinations of filters, etc. But you notice that due to peaks of population requests for London, Manchester, Liverpool and a few more take like 30% of all the overall requests. Of course there are…
Read More

Be care with default values on Foreign Keys!

Web programming
Today I was creating a constraint in my DB using this statement: [sourcecode language="sql" wraplines="false"] ALTER TABLE dbo.[Cars] ADD CONSTRAINT FK_Cars_Users FOREIGN KEY (UserId) REFERENCES dbo.[Users](ID) ON UPDATE NO ACTION ON DELETE NO ACTION [/sourcecode] And got this weird error message: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_Cars_Users". The conflict occurred in database "MyDatabaseName", table "dbo.Users", column 'ID'. The problem came as I didn't realized I had set a default value for FK UserId to 0, and primary key in Users was autoincrmental starting at 1, so there would never be a UserId=0 in User table and SQL complained about it. [sourcecode language="sql" wraplines="false"] ALTER TABLE Cars ADD UserID int NOT NULL DEFAULT 0 [/sourcecode] Good someone helped me finding the problem, I was blind! So…
Read More

System networking tricks

Other
Quick accesses Open Commands Window: Execute: cmd Open IIS: Execute: inetmgr Change PC hosts Open this with notepad: c:\windows\system32\drivers\etc\hosts Now, you can set an ip and its host setting the ip and the dns separated by at least one space in the same line. Example: 15.140.114.22 myprivateserver.com That will make requests to 15.140.114.22 go to myprivateserver.com, and viceversa, requests to myprivateserver.com will go to 15.140.114.22. Check where a dns is pointing IN YOUR PC Open cmd, ping the host dns and see which real ip is requesting. Alternatively, open the hosts file at c:\windows\system32\drivers\etc\hosts
Read More

Setting .Net Framework version in IIS 7

Other
When upgrading from an older version of .Net to a new one you are going to need to set this into IIS7 so that it knows which engine to use when handling a website (it will not check this on the webconfig as, to start with, it doesn't know there is a webconfig without knowing the engine to handle that website). Inside IIS 7, notice you have a node with the server/PC under which you can find "Application Pools" and "Sites". Under Sites you will have configured your websites, but under Application Pools you need to configure the engine each of them is using. So we go to Application Pools > Choose the one your website is using > double click > change .Net Framework version > accept. If you…
Read More

Restoring DB in SQL Server executing a query command

Web programming
I was having a problem trying to restore a DB from a backup with the error message "Error 3154: The backup set holds a backup of a database other than the existing database.". I finally found how to make it executing a manual query instead than trying to use SQL Server menu options. To execute the query you need to open a Query and execute it from Master, not from the db to restore. [sourcecode language="sql" wraplines="false"] ALTER DATABASE MyDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE RESTORE DATABASE MyDatabaseName FROM DISK = 'MyDatabaseName.bak' WITH REPLACE [/sourcecode] The fix consists on using that "WITH REPLACE" sentence. Note: The page where I got the query sets the backup file using "c:/Filename.bak" but my SQL Server was configured to look into C:/Program Files/SQL Server/.../backups/…
Read More

Handling brute force attacks with Umbraco

Web programming, Web security
If we want our Umbraco website to block users in case there is a brute force attack for an id we can do this: Add 2 properties to your member type: locked [true, false] and failedLogins [Numeric]. Add the following properties to your UmbracoMembershipProvider key inside webcofig (notice the values are the same as the aliases of the properties we just created): umbracoLockPropertyTypeAlias="locked" umbracoFailedPasswordAttemptsPropertyTypeAlias="failedLogins" maxInvalidPasswordAttempts="3" passwordAttemptWindow="30" Your webconfig should look something like this: [sourcecode language="xml" wraplines="false"] <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="MyMemberType" passwordFormat="Hashed" umbracoLockPropertyTypeAlias="locked" umbracoFailedPasswordAttemptsPropertyTypeAlias="failedLogins" maxInvalidPasswordAttempts="3" passwordAttemptWindow="30" /> [/sourcecode] The rest is handled by Umbraco. You also have a couple of properties to set how many times before a block and how much time the user is blocked. You can use the property defaultMemberTypeAlias to set your memberType alias…
Read More

Guide for using GridViews in .Net

Web programming
Giving it a source of data to display: DataSource property To make GridViews show some data, you need to feed them with a source with that data first. That source is called DataSource and the GridView has a property to bind it: [sourcecode language="csharp" wraplines="false"] gridProducts.DataSource = getSomeSourceFromAroundThere(); [/sourcecode] The source can be a Data type using ADO like a DataReader or a DataTable in a DataSet, but it can also be a group of objects like an Array of Strings or a Collection (List, Dictionary, ...) of objects, even IEnumerables can be used. I'm going to try to show most of the examples using an ADO source and a Collection source: [sourcecode language="csharp" wraplines="false"] //Using DataReader IDataReader rd = MyNamespace.Users.getUsersReader(); gridUsers.DataSource = rd; gridUsers.DataBind(); //Using ADO DataTable DataTable tb…
Read More

Association relationships between objects

Software Architecture
An Association relationship between two objects can have different levels of dependency. In some situations, an object just knows about the existance of another and works with it while in other scenarios it may be the one in charge of all its lifetime. Depending on how much dependency there is between those objects we can define 3 types of Association Relationship: Composition: The owner controls the child lifetime. Aggregation: The main object has inside of it the other but doesn't control its lifetime. Delegation: The main object just knows about the existence of the other one. Composition This is a has-a relationship, meaning the main object has a child object type inside of it. With Composition, the life-cycle of the objects that compose an object ends when the main object…
Read More
Close Bitnami banner
Bitnami