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"


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:

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)
  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!
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.