onsdag 6 november 2013

TFS cloud setup with auto-publish to Arvixe

I just finished setting up an CI with TFS in da cloud (tfs.visualstudio.com) with auto-publish to my team's web host. Pheeew!

Well, the first part was quite easy. Setting up a TFS is easy as pie. Just go to http://tfs.visualstudio.com/ and setup your account. I choose Git as version control. There was an easy guide to send your repo to your TFS server. Then there was a good guide to set up a build. But, then the tricky part came when I was going to set up a web deploy to the web host.

The web host is Arvixe and they have a pretty desent hosting environment. To allow Web Deployment you just go to the site's configuration and to the tab "Publishing" and enable. Then you can download the publish profile and import it in Visual Studio 2012. But to make the publishing successful you have to tell the publishing operation to not touch the folder and files permissions. Since you are in a hosting environment you are not admin and are not allowed to do so. This is easy as pie. Follow these instructions from this website:

  1. In the same directory as your project create a file with the name {ProjectName}.wpp.targets (where {ProjectName} is the name of your Web application project)
  2. Inside the file paste the MSBuild content which is below this list
  3. Reload the project in Visual Studio (VS caches the project files in memory so this cache needs to be cleared).
{ProjectName}.wpp.targets
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <IncludeSetAclProviderOnDestination>false</IncludeSetAclProviderOnDestination>
  </PropertyGroup>    
</Project>
Then, the local publish is good to go. But, there is one thing left to do to make the TFS build to publish the output to your server, making a Web Deployment. In the the edit section of the build, go to the tab "Process" and the section "Advanced" and add following to the "MSBuild arguments": 

/p:DeployOnBuild=True
/p:DeployTarget=MsDeployPublish
/p:MSDeployPublishMethod=WMSVC
/p:AllowUntrustedCertificate=true
/p:CreatePackageOnPublish=True
/p:DeployIisAppPath="Your Website URL"  
/p:MsDeployServiceUrl=allium.arvixe.com
/p:username=youraccount_dploy
/p:password=MyPassword@1234

These sites help me find the correct arguments:

After this your good to go. Keep up the coding!

torsdag 5 september 2013

Nya Zeeland dumpar mjukvarupatent

Nya Zeeland går före och gör något som förhoppningsvis alla länder kommer göra snart, och vad de kommer behöva gör inom en snar framtid.

De har tagit bort datorprogram från saker som kan patenteras.

En av patents främsta syfte är att främja innovation. De som har hängt med de senaste åren vet att det är inte så det används. Uppenbarligen behövs ett rejält nytänk inom detta juridiska område, men idag har tyvärr de ledande politikerna gått i säng med de stora etablerade krafterna.

Det behövs fler politiker som i Nya Zeeland som tänker på folket i första hand och inte företagen!

torsdag 29 augusti 2013

The magic of today


I really love devloping software. What I find most amazing is when you take time of and step back and think about what it is your doing. These are not new thoughts about technology, but I think it is important not to forget how empowering our current situation is.

I have helped my girlfriend get ahead of her collegues in the race to sign up to vacant work shifts. I built this web service that crawls her work website, using her credentials, to look for new shifts posted online. The web service is equal to her logging in to the website, navigating to the correct page and looking if a new interesting entry is made.

Here is the freaky part. I am writing a bunch of words in a document (the code) on a computer in Sweden. I send the code to a server in USA which will tell a computer to control a swedish server. The swedish server will return information to USA that will sort it and store it in a database.

To automate the process further I have written script on my Raspberry Pi in my living room in Sweden. It regulary contacts the server in USA and asks for the latest results. If the results are interesting it will go back to USA and contact Google and ask them to send a mail to my girlfriend which will read the email on her smartphone in Sweden.

Imagine this process without the Internet we know of today. This whole process takes a couple of seconds. This was unbelievable a couple of decades ago. This was unthought of a couple of hundred years ago. It is godlike compared to a couple of thousend years ago. Everybody today weilds power greater than any man or creature before us on this earth, It is important to not take it for granted.

It is easy to forget that the technologies we have today wasn't around a couple of years ago.It makes
us historyless and makes us forget why we have this advantage that we have today. To continue to advance we have to continue to use technology to better ourselves which will benefit everyone around us.

fredag 9 augusti 2013

Starta Development Server manuellt

Du behöver inte starta igång Visual Studio om du ska testa ditt projekt! Ibland vill man visa upp sitt projekt för någon annan eller bara ha igång det i bakgrunden utan att man aktivt jobbar på det. Självklart kan man lägga upp det i IIS:en, men detta ger ett alternativ till det.

Det räcker med följande kommando i cmd:
"C:\Program Files\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.exe" port:1337 /path:"C:\MyProjectFolder"

Förklaring

Du ska köra .exe-filen: WebDev.WebServer.exe med växlarna:
port - Den port du vill använda (valfritt - default är 80)
path - Mappadress till ditt projekt

Läs mer här:
http://blogsandip.wordpress.com/2008/04/05/starting-aspnet-development-server-manually/
http://stackoverflow.com/questions/286995/launch-asp-development-server-manually
http://blogs.msdn.com/b/irenak/archive/2006/11/30/sysk-250-how-to-start-asp-net-development-server-without-visual-studio.aspx

onsdag 7 augusti 2013

Post Antiforgerytoken manually

When you use the helper @Html.AntiForgeryToken() in a view this is the actual HTML result:
<input name="__RequestVerificationToken" type="hidden" 
value="{ long cryptic code }">
This input field is normally inside your <form>-element which means it will be attached to the request if you submit that form.
The problem occurs when this input field is outside of your form or if you are not submitting a form. Have no fear, there is a solution for this. The attribute [ValidateAntiForgeryToken] tells the server to look for a key with the name: "__RequestVerificationToken". Let's give the server what it wants!
First, get that value!
var antiforgeytoken = $('input[name=__RequestVerificationToken]').val();
Second, attach it to your AJAX-request (I use jQuery)
$.ajax({
  url: 'something/something',
  type: 'POST',
  contentType: 'application/x-www-form-urlencoded; charset=UTF-8', // Default
  data: { 'somekey': 'someval', 
          '__RequestVerificationToken', antiforgeytoken }
});
Now your server is happy, and you are too!
Update:
The content type is important because of how the MVC Binder validates the request. If you want to use another content type this solution How can i supply an AntiForgeryToken when posting JSON data using $.ajax? proposes to separate the antiforgery token and the postdata in two different parameters.

fredag 5 juli 2013

ORM jag hatar dig

En vecka senare har jag besegrat NHibernate och lyckats få en tabell i en databas att bli en användbar entitet i ett C# projekt. Kalla mig seg, men varför ska det vara så krångligt? Jag är uppenbarligen ny till ORM, men jag har tidigare använt Microsofts Entity Framework och tycker att den funkar som det borde funka.

När man jobbar med NHibernate och måste manuellt själv skriva ut alla kopplingar mot tabellerna istället för att skriva SQL kod måste man fråga sig om det är värt det. Om man istället låter det ske automagiskt likt Entity Frameworks lösningen tycker jag att det är värt det. Antagligen finns det liknande lösningar för NHibernate.

Det jag vill komma till är varför man, år 2013 fortfarande, måste bry sig om hur man sparar data i en databas?

Jag har börjat pilla med Node.js och ramlade över ett ramverk som heter Meteor.js. Det använder sig av MongoDb som är en NoSQL databas. Du skriver din data objekt i JSON, du sparar det i JSON, och hämtar det i JSON. Du behöver inte hålla på och konvertera, mappa, och bry dig om datatyper. Du använder dina entiteter hela vägen.

För mig känns detta helt naturligt att det är så här det borde funka. Jag tror att många som jobbat i branschen är inrutade på SQL-databaser och ORM. Det är så man har jobbat och det är så det funkar. Det är naturligt.

Det som jag tycker är det stora problemet med SQL och ORM är att så mycket tid går åt att göra saker som inte ger någon direkt nytta. Att göra så att databasen och applikationen kan prata med varandra är dötid. Det ger inget värde till beställaren. Fördelen med SQL är bättre prestanda. Men, det är på bekostnad av krånglighet. Jag tror att de allra flesta systemutvecklingsprojekten inte är beroende av den typen av prestanda som SQL ger. NoSQL är redo och har en en bra prestanda. Jag tror användaren kan vänta några extra millisekunder om de sparar pengar och tid på deras projekt!

torsdag 23 maj 2013

HTTP Headers

Hittade en grym sida som beskriver HTTP Headers

http://www.mobify.com/blog/beginners-guide-to-http-cache-headers/

Mina anteckningar:



cache-control

Exempel
Cache-control: private, max-age=0, no-cache

Förklaring
Nuvarande standard för att uppge cache egenskaper

Private | public
För specifik användare eller inte
max-age
tid att cachas i sek
s-maxage
samma som ovan, men delat cache
(används av CDN:er)
no-cache
ska ej cachas
no-store
ska ej lagras
no-transformation
ingen auto-formatering eller enkodning
för att spara bandbredd

expires

Exempel
Thu, 01 Dec 1983 20:00:00 GMT

Förklaring
Det gamla sättet att uppge sluttid för cache. Bra att ha för bakåtkompabilitet.

vary

Exempel
vary: User-Agent

Förklaring
Bestämmer vilka av headers som ska kontrollera cache emot

pragma

Exempel
pragma: no-cache
Samma sak som: cache-control: no-cache

Förklaring
Gammal. Används inte längre

etag

Exempel
ETag: "e6811cdbcedf972c5e8105a89f637d39-gzip"

Förklaring
Kort för "entity-tag". En ID-tag för en rersurs för att se om det är samma version


tisdag 14 maj 2013

Batch-tips

Några schyssta batch-tips:


Pausa skriptet i x antal sekunder
PING 1.1.1.1 -n 1 -w 15000 > NUL

Köra SQL-kommandon
osql eller sqlcmd (om SQL server)

Kolla om en parameter är NULL, och sätt ett defaultvärde
IF dummy==dummy%1 (
SET param1="Mitt default värde"
) ELSE (
SET param1=%1
)


Finns mer från källan:
http://weblogs.asp.net/jgalloway/archive/2006/11/20/top-10-dos-batch-tips-yes-dos-batch.aspx

och här:
http://www.robvanderwoude.com/batchfiles.php

måndag 13 maj 2013

En bakåtpil/-knapp i CSS!

Äntligen har jag hittat en schysst bakåtknapp i CSS som liknar iPhones och som stödjer CSS gradients!

Koden finns här:
http://lab.jeffbatterton.com/iphone-back-button/




måndag 25 februari 2013

YUI - Yahoo UI Compressor

Yahoo! UI Library: YUI Compressor for .Net

YUI - Yahoo UI Compressor.
Ett väldigt bra verktyg för att komprimera och slå samman CSS-filer och JS-filer.
Jag har hållit på med komplicerade .bat-filer tills jag upptäckte detta verktyg som kan bygga de filer som jag behöver och göra de minified.

Hämta det här:
http://yuicompressor.codeplex.com/documentation

lördag 2 februari 2013

Testa webappen på alla enheter!

Hittade denna sjukt coola och användbara sida genom Code Project:

DeviceAnywhere

Det är en sida där du kan fjärrstyra ett antal olika aktuella mobiler för att se hur din hemsida ser ut och beter sig på de olika modellerna och operativen. Det är inte alltid man har tillgång till de olika intressanta mobilerna som ens sida/webapp ska anpassas till. Med detta verktyg kan man få sig en bra uppfattning om vad som är rätt och vad som är fel. Det bästa är att det är gratis! Iallafall grundfunktionalitet och begränsad tidsomfattning.
Detta är definitivt något som ska pitchas till chefen för att få honom att lägga in några slantar.


tisdag 22 januari 2013

Installationsfil för ASP.NET-projektet

Jag har äntligen hittat en bra guide för att skapa ett "Web Setup"-projekt. Jag har envisats med att välja Visual Studios inbyggda lösning för att skapa ett installationspaket. Vad jag förstått finns det tredjepartsprogram som fungerar jättebra enligt utsagor, men jag har valt att inte sätta mig in i det. 

Geoffrey Vandiest presenterar en bra guide där han även tar med hur man kan köra "Custom Actions". Jag ville manipulera några filers innehåll beroende på vad användaren väljer under installationen. Detta går mycket bra att göra genom en vanlig klass om man importerar vissa .NET-klasser.


onsdag 16 januari 2013

iOS WebApp + AppCache = Problem

Då och då har jag fått problem med min webapp på iPhone. Den funkar via Safari, men som webapp blir det problem när jag startar den. Jag har förstått att det är fel på appcache, men har inte vetat hur jag ska lösa det, utan att ta bort den.


1. Ta bort webapp
2. Rensa cache i Safari
3. Stäng Safari