Uncategorized – Rantings in the dark https://kinsey.no/blog Because I want to be like the cool kids too Mon, 21 Jun 2021 22:49:10 +0000 en-US hourly 1 https://wordpress.org/?v=5.8.18 Moving to San Francisco, and feeling great. https://kinsey.no/blog/index.php/2011/10/03/moving-to-san-francisco-and-feeling-great/ https://kinsey.no/blog/index.php/2011/10/03/moving-to-san-francisco-and-feeling-great/#comments Mon, 03 Oct 2011 21:40:48 +0000 http://kinsey.no/blog/?p=336 So, it turns out I’ve accepted a position with Facebook and will be moving to San Francisco as soon as my H1-B clears (should be in not too many weeks). And a few weeks ago, a friend of mine told me about

The last six years spent with BRIK has been wonderful and I’ve grown both as a human and as a developer. I’ve worked on a lot of fun projects, some of which has grown quite large, and some not so fun ones. I’ve worked with every aspect of development, from working with clients to drawing technical flowcharts only to throw them away moments later. I’ve worked solo and I’ve acted as CTO for my own, and other companies. I’ll still have an interest in the company as member of the Board, and as an owner, but if everything goes as planned, the company will carry on, and continue to grow even without me as we’ve got some great people on board, and hopefully more will join us (want in on the action?).

Time will tell what I’ll be doing at Facebook, but with the people I’ve met there, the atmosphere and the culture, I can promise you it’s going to be awesome! I have great expectations, to the company as a whole, but most to Facebook as a platform for a new generation of socially enabled (and driven) applications.

As you can probably understand, I’m really thrilled about joining the company, and to add to that, it has caused some publicity here in Norway in both regional and nation wide newspaper (printed and online).
Although most of the content is correct, and as expected, some of it comes across a bit out of context and without reference, which really isn’t to my liking. But I guess that is to be expected..
Anyway’s, just to make it clear; statements such as “I’m the best in the world” are taken completely out of context (and proportions) (I am one of the best on my specific field), and I did not make comments about certain people not knowing what they were doing, rather that they weren’t fully in control of that specific field.

But it’s getting late now, and in about 5 hours, I’ll be on my way to the airport to spend two weeks in San Francisco doing som RnR and some apartment scouting – if you know something suitable in the Mission are, do give me a shout!

]]>
https://kinsey.no/blog/index.php/2011/10/03/moving-to-san-francisco-and-feeling-great/feed/ 4
Using WCF/svc’s automatically generated javascript proxies _without_ ASP.NET AJAX https://kinsey.no/blog/index.php/2009/10/28/using-wcfsvcs-automatically-generated-javascript-proxies-_without_-asp-net-ajax/ https://kinsey.no/blog/index.php/2009/10/28/using-wcfsvcs-automatically-generated-javascript-proxies-_without_-asp-net-ajax/#comments Wed, 28 Oct 2009 17:11:05 +0000 http://kinsey.no/blog/?p=133 Most of my web based projects consist of WCF driven webservices at the backend and a javascript UI using ExtJS, and for access to the WCF webservice I like to use its automatically generated proxies as this abstracts away the feeling of working with XMLHttpRequests, actually it abstracts it to a level where you can call the server side method ‘directly’, specifying only a callback function that should receive the response. These proxies are dynamically generated and will always reflect the serverside methods signature.

To use the proxies all you need to do is (as long as the correct bindings are in place) access the .svc file with either ‘/js’ or ‘/jsdebug’ appended, and you will get the generated proxies.
By the way, if you use any objects, either as an argument or as a return type, these will also be created as javascript ‘classes’, the same with any enumerations – its all wery nice.

Using both ASP.NET AJAX and ExtJS on the same page does not create any serious problems (I think there might be a couple of collisions on the Date object), but it does mean that you have quite a bit of overhead.

Removing the ASP.NET AJAX framework does not work initially as the generated proxy code needs this to work, so if we remove the ASP.NET AJAX framework, well, then we are going to need to replace it with something that caters to the proxy codes needs without the extra overhead of loading the entire ASP.NET AJAX framework. And here it is – this is the minimum of code needed to bootstrap the automatically generated proxy code, and to tie it into the ExtJs framework. If you want to use it with a different framework then it should not be a difficult task to exchange the Ext dependencies.

// Extend Functions prototype
Function.prototype.initializeBase = function(instance, baseArguments){
};
Function.prototype.registerClass = function(typeName, baseType, interfaceTypes){
    if (baseType) {
        for (var name in baseType.prototype) {
            this.prototype[name] = baseType.prototype[name];
        }
    }
};
Function.prototype.registerEnum = function(name, flags){
};

// Add Type and Type.registerNamespace
var Type = {
    registerNamespace: function(ns){
        var va = window;
        ns = ns.split(".");
        for (var i = 0, len = ns.length; i < len; i++) {
            va = va[ns[i]] = {};
        }
    }
};

// Create the Sys.Net.WebServiceProxy object
Type.registerNamespace("Sys.Net");

Sys.Net.WebServiceProxy = function(){
    //empty constructor
};

Sys.Net.WebServiceProxy._generateTypedConstructor = function(type){
    return function(properties){
        if (properties) {
            for (var name in properties) {
                this[name] = properties[name];
            }
        }
        this.__type = type;
    };
};


Sys.Net.WebServiceProxy.prototype._invoke = function(path, action, useGet, params, onSuccess, onFailure, userContext){
    // Use Ext.Ajax to perform the xhr call
    Ext.Ajax.request({
        url: path + "/" + action,
        method: useGet ? "get" : "post",
        jsonData: params,
        success: function(data){
            onSuccess(Ext.decode(data.responseText).d);
        },
        failure: function(data){
            onFailure(Ext.decode(data.responseText).d);
        },
        scope: userContext
    });
};
Sys.Net.WebServiceProxy.prototype.set_path = function(path){
    this._path = path;
};
Sys.Net.WebServiceProxy.prototype.get_path = function(){
    return this._path;
};

]]>
https://kinsey.no/blog/index.php/2009/10/28/using-wcfsvcs-automatically-generated-javascript-proxies-_without_-asp-net-ajax/feed/ 2
Running NokiaSoftwareUpdaterSetup on Windows 7 https://kinsey.no/blog/index.php/2009/10/27/running-nokiasoftwareupdatersetup-on-windows-7/ https://kinsey.no/blog/index.php/2009/10/27/running-nokiasoftwareupdatersetup-on-windows-7/#comments Tue, 27 Oct 2009 21:05:57 +0000 http://kinsey.no/blog/?p=128 Today I needed to upgrade the software on my Nokia N97, and was prompted by the Nokia software to download and run NokiaSoftwareUpdaterSetup_en.exe.

The only thing was, this just exited with a message saying unsupported platform or something. I quickly tested if the exe file was an archive and discovered I could unpack it with 7-Zip online live dealer blackjack. Inside the resulting directory, in a folder named Installer, I found a file called Configuration.icf, and in this a line with the string

TargetOSs=winXP,winVista

I added ‘,win7’ on a hunch and ran Installer.exe, and what do you know, it worked 🙂

]]>
https://kinsey.no/blog/index.php/2009/10/27/running-nokiasoftwareupdatersetup-on-windows-7/feed/ 20
easyXSS https://kinsey.no/blog/index.php/2009/06/24/easyxss/ https://kinsey.no/blog/index.php/2009/06/24/easyxss/#comments Wed, 24 Jun 2009 16:39:38 +0000 http://kinsey.no/blog/?p=44 Please see easyXDM for updated info!

I’ve just completed the first version of my cross-site scripting library easyXSS. It is available at http://code.google.com/p/easyxss/ under a MIT-license.

As it is now it supports simple messaging between windows of different domains, but it also supports proxying method calls and results between them making it well-suited for creating API’s.

I’ve prepared several examples and demo’s at http://code.google.com/p/easyxss/ and look forward to getting feedback!

To show you a quick example, here is the code needed to have a method ‘doMagic’ that is located on domainA available in a window from domainB.

This is placed in the document api.html at domainA

var channel = easyXSS.createChannel({
onReady: function(){
remote = easyXSS.createInterface(channel, {
local: {
doMagic: _privateMethodDoingMagic
}
});
}
});

and this is placed in the document at domainB

var remote;
var channel = easyXSS.createChannel({
local: &quot;/hash.html&quot;,
remote: &quot;http://domaina.com/api.html&quot;,
onReady: function(){
remote = easyXSS.createInterface(channel, {
remote: {
doMagic: {}
}
});
}
});

The medhod doMagic can now be called from domainB using

remote.doMagic('argument1',2,'three',function(result){
// Consume the result
});
]]>
https://kinsey.no/blog/index.php/2009/06/24/easyxss/feed/ 12
Ext Calendar https://kinsey.no/blog/index.php/2009/02/27/ext-calendar/ https://kinsey.no/blog/index.php/2009/02/27/ext-calendar/#comments Fri, 27 Feb 2009 14:39:31 +0000 http://kinsey.no/blog/?p=42 I just remembered that I had made a decent Ext based calendar (extending Ext.Panel).

You can view a demo of it here.

The calendar supports loading data through a Ext.data.Store, d’n’d of timespans, events for handling d’n’d, editing etc. I built it mostly to help my folks actually. It’s not exactly happy news to write about, but my parents in their old age started kind of forgetting stuff. We’re pretty sure it’s nothing medical or serious, just old age, which is good. In the meantime however, they keep forgetting to take their medications, go to doctor’s appointments, things like that. I setup this calendar to help them. It didn’t quite work, as the computer never interested them all that much. Thankfully I found a solution. You can hire someone to provide at home care from Home Care Assistance Long Island. I did so and that person was very experienced, there really hasn’t even anything she can’t handle yet. Now I can keep working knowing their being cared for and I have nothing to worry about.

]]>
https://kinsey.no/blog/index.php/2009/02/27/ext-calendar/feed/ 22
Microsoft Chart Controls for the .Net Framework – rendering using a httpHandler https://kinsey.no/blog/index.php/2008/11/13/microsoft-chart-controls-for-the-net-framework-rendering-using-a-httphandler/ https://kinsey.no/blog/index.php/2008/11/13/microsoft-chart-controls-for-the-net-framework-rendering-using-a-httphandler/#comments Thu, 13 Nov 2008 14:51:13 +0000 http://kinsey.no/wp/?p=34 Those of you who have taken a look at the new chart controls might have seen that there are multiple ways of rendering these in ASP.NET.

Since my apps (ajax based, no updatepanels etc) use generic httpHandlers for these kind of things, I went looking for the ‘httphandler way’ of rendering the chart controls – but it does not exist..

So I whipped out reflector and took a look at the chart class, and found the three lines needed for doing this


Imports System.Web
Imports System.Web.Services
Imports System.Web.UI.DataVisualization.Charting
Imports System.IO

Public Class chart
Implements System.Web.IHttpHandler

Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'create the chart
Dim ch As New System.Web.UI.DataVisualization.Charting.Chart
ch.ID = &quot;chart&quot;
ch.Height = 296
ch.Width = 412
ch.ImageType = DataVisualization.Charting.ChartImageType.Png
ch.Palette = DataVisualization.Charting.ChartColorPalette.BrightPastel
ch.BackColor = Drawing.Color.Azure
ch.RenderType = DataVisualization.Charting.RenderType.BinaryStreaming
ch.BorderlineDashStyle = DataVisualization.Charting.ChartDashStyle.Solid
ch.BackGradientStyle = DataVisualization.Charting.GradientStyle.TopBottom
ch.BorderlineWidth = 2
ch.BorderlineColor = Drawing.Color.Blue
ch.BorderSkin.SkinStyle = BorderSkinStyle.Emboss

Dim ser As System.Web.UI.DataVisualization.Charting.Series = ch.Series.Add(&quot;Series1&quot;)
ser.ChartType = DataVisualization.Charting.SeriesChartType.SplineArea
ser.BorderColor = Drawing.Color.CadetBlue
ser.ShadowOffset = 2

ser.Points.Add(New DataPoint() With {.YValues = New Double() {6}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {9}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {3}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {5}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {2}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {7}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {8}})
ser.Points.Add(New DataPoint() With {.YValues = New Double() {1}})

Dim ca = ch.ChartAreas.Add(&quot;Default&quot;)
ca.BackColor = Drawing.Color.Transparent
ca.BorderColor = Drawing.Color.Red
ca.AxisX.IsMarginVisible = False

context.Response.ContentType = &quot;image/png&quot;
context.Response.Charset = &quot;&quot;

'here comes the magic
Dim imageStream As New MemoryStream
ch.SaveImage(imageStream)
context.Response.BinaryWrite(imageStream.GetBuffer)

End Sub

ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class

]]>
https://kinsey.no/blog/index.php/2008/11/13/microsoft-chart-controls-for-the-net-framework-rendering-using-a-httphandler/feed/ 7
A simple reorder list in Ext JS https://kinsey.no/blog/index.php/2008/07/29/a-simple-reorder-list-in-ext-js/ https://kinsey.no/blog/index.php/2008/07/29/a-simple-reorder-list-in-ext-js/#comments Tue, 29 Jul 2008 14:12:26 +0000 http://kinsey.no/wp/?p=20 I’ve been using Ext JS for quite some time now, and I must say, I love it.

There is quite good support for drag’n’drop here, but it lacks one thing; the precious reorder list.
An example of such can be found here

Since doing the google didn’t return anything like this I ended up implementing it my self.

I started out with the example given here, but this only implements basic d’n’d of elements, not the reordering.
So with the following html:

&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;../lib/ext/resources/css/ext-all.css&quot; temp_href=&quot;../lib/ext/resources/css/ext-all.css&quot;&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;../lib/ext/adapter/ext/ext-base.js&quot; temp_src=&quot;../lib/ext/adapter/ext/ext-base.js&quot;&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;../lib/ext/ext-all-debug.js&quot; temp_src=&quot;../lib/ext/ext-all-debug.js&quot;&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;custom.js&quot; temp_src=&quot;custom.js&quot;&gt;
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;Ext.onReady(Tutorial.dd.init, Tutorial.dd);
&lt;/script&gt;
&lt;title&gt;Custom Drag &amp;amp;amp;amp;amp; Drop Tutorial&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;

.dd-item {
height: 18px;
border: 1px solid #a0a0a0;
background-color: #c4d0ff;
vertical-align: middle;
cursor: move;
padding: 2px;
z-index: 1000;
}

.dd-ct .dd-item {
margin: 2px;
width:200px;
}

.dd-proxy {
opacity: 0.4;
-moz-opacity: 0.4;
filter: alpha( opacity = 40 );
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;dd-ct&quot; id=&quot;dd1-ct&quot;&gt;
&lt;div class=&quot;dd-item&quot; id=&quot;dd1-item1&quot;&gt;
Item 1.1
&lt;/div&gt;
&lt;div class=&quot;dd-item&quot; id=&quot;dd1-item2&quot;&gt;
Item 1.2
&lt;/div&gt;
&lt;div class=&quot;dd-item&quot; id=&quot;dd1-item3&quot;&gt;
Item 1.3
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

and the following Javascript in index.js:

Ext.BLANK_IMAGE_URL = '../lib/ext/resources/images/default/s.gif';
Ext.namespace('Tutorial');
Ext.override(Ext.dd.DDProxy, {
startDrag: function(x, y){
var dragEl = Ext.get(this.getDragEl());
var el = Ext.get(this.getEl());
dragEl.applyStyles({
border: '',
'z-index': 2000
});
dragEl.update(el.dom.innerHTML);
dragEl.addClass(el.dom.className + ' dd-proxy');
},
onDragEnter: function(e, targetId){
var target = Ext.get(targetId);

if (target.dd instanceof Ext.dd.DDProxy) {
this._target = target;
this.updateTargetPosition();
}
},
updateTargetPosition: function(){
var _box = this._target.getBox();
this._crossOver = {
x: (this._target.getLeft() + (_box.width / 2)),
y: (this._target.getTop() + (_box.height / 2))
}
},
onDragOver: function(e, targetId){
if (this._target) {
var el = Ext.get(this.getEl());
if (el.id != this._target.id) {
if (this._placement == &quot;before&quot;) {
el.insertBefore(this._target);
}
else {
el.insertAfter(this._target);
}
this.updateTargetPosition();
var xy = e.getXY();
this._placement = (xy[1] &lt; this._crossOver.y) ? &quot;before&quot; : &quot;after&quot;;
}
}
},
endDrag: function(){
var el = Ext.get(this.getEl());
el.applyStyles({
position: '',
width: ''
});
this._target = null;
this._placement = null;
this._crossOver = null;
}
});

Tutorial.dd = function(){
return {

init: function(){
var dz1 = new Ext.dd.DropZone('dd1-ct', {
ddGroup: 'group'
});

var dd11 = Ext.get('dd1-item1');
dd11.dd = new Ext.dd.DDProxy('dd1-item1', 'group');
var dd12 = Ext.get('dd1-item2');
dd12.dd = new Ext.dd.DDProxy('dd1-item2', 'group');
var dd13 = Ext.get('dd1-item3');
dd13.dd = new Ext.dd.DDProxy('dd1-item3', 'group');

}
};
}
();

we suddenly have what we need.
For now this only supports non-floating block elements, but I will extend it to also support floats.

UPDATE 1
This demo is now available at http://kinsey.no/examples/reorderlist/

UPDATE 2
I now have a version supporting float ready and will publish this when I have the time.
There is also a reorderview available using a reading and updating from a standard datastore.

]]>
https://kinsey.no/blog/index.php/2008/07/29/a-simple-reorder-list-in-ext-js/feed/ 2
“This page contains both secure and nonsecure items.” https://kinsey.no/blog/index.php/2008/05/26/this-page-contains-both-secure-and-nonsecure-items/ https://kinsey.no/blog/index.php/2008/05/26/this-page-contains-both-secure-and-nonsecure-items/#respond Mon, 26 May 2008 13:51:55 +0000 http://kinsey.no/wp/?p=15 With one of my larger webapps I have recently been struggling with the following Security Information message in Internet Explorer:

This page contains both secure and nonsecure items.

Do you want to display the nonsecure items?

This, in general, has to do with mixing of content from different security zones in IE, for example Internet and Local, or http and https.

I’ve had my go at Google and there are indeed loads of sites where this, and solutions to it has been brought up, but none of these applied to my application.
To sum it up, most solutions consists of checking the following

  • That all URL’s are either consistent (http or https, not a mix) or relative URL’s
  • That all iframes or frames written in markup has a src set
  • That all iframes or frames created with javascript and added to the DOM has a src set prior to adding
  • That all resources resolve and do not generate a 404, (the 404 page is considered local zone)

After checking all of these off, my application was still throwing the same error, and something I had read a long time a go bubbled up.
IE will treat all images that has a relative src set with hormone therapy Scottsdale through the DOM as an insecure element!
Therefor my solution was to create a resourceBase variable that I use to prefix all the previously relative paths with.
The simplest way to do this is by:

var resourceBase=window.location.protocol + &amp;quot;//&amp;quot; + window.location.host +&amp;quot;/resources/&amp;quot;;

Following is a quick example of a function converting a relative path to an absolute one:

function relativeToAbsolute(_urlToResolve){
if (_urlToResolve.substring(0, 1) == &amp;quot;/&amp;quot;) {
_urlToResolve = _urlToResolve.substring(1);
}
var _documentURI = document.location.href.substring(window.location.protocol.length + 2, document.location.href.lastIndexOf(&amp;quot;/&amp;quot;));
var _lastIndexOf = null;
while (_urlToResolve.substring(0, 2) == &amp;quot;..&amp;quot;) {
_urlToResolve = _urlToResolve.substring(3);
if ((_lastIndexOf = _documentURI.lastIndexOf(&amp;quot;/&amp;quot;)) != -1) {
_documentURI = _documentURI.substring(0, _lastIndexOf);
}
}
return window.location.protocol + &amp;quot;//&amp;quot; + _documentURI + &amp;quot;/&amp;quot; + _urlToResolve;
}
]]>
https://kinsey.no/blog/index.php/2008/05/26/this-page-contains-both-secure-and-nonsecure-items/feed/ 0
Javascript function overloading https://kinsey.no/blog/index.php/2007/11/15/javascript-function-overloading/ https://kinsey.no/blog/index.php/2007/11/15/javascript-function-overloading/#comments Thu, 15 Nov 2007 08:00:18 +0000 http://kinsey.no/wp/?p=11 I was reading a post yesterday about function overloading in javascript, and the suggested solution had quite a performance overhead when used with multiple signatures.
In addition, it only used the number of arguments, and not their types and order to distinguish between the signatures.

For some reason I woke up early this morning with a solution to this.
The following code will do all of the above and has the same overhead for all number of signatures.

//returns an overloadable method
Function.CreateOverloaded = function(){
    var overloads = [];
    //creates the overloaded method
    var func = function(){
        var sign = [];
        for (var i=0;i < arguments.length; i++) {
            sign.push(typeof arguments[i]);
        }
        sign = sign.join();
        var func = overloads["(" + sign + ")"];
        if (!func) {throw "No matching signature";}
        return func.apply(this, arguments);
    };

    //method for adding a function with a spesific signature
    func.AddSignature = function(func, sign){
        if (overloads["(" + sign + ")"]){throw "Duplicate signature"};
        overloads["(" + sign + ")"] = func;
    };
    return func;
}

To test it you can use the following code

var myFunc = Function.CreateOverloaded();
myFunc.AddSignature(function(){
    alert("test1");
}, "");
myFunc.AddSignature(function(var){
    alert(var);
}, "string");
myFunc.AddSignature(function(integer){
    alert(integer + "x 5 = " + (integer * 5));
}, "number");
myFunc.AddSignature(function(int1, int2){
    alert(int1 * int2);
}, "number,number");
myFunc.AddSignature(function(string, int){
    alert(string + " equals " + int);
}, "string,number");

myFunct();
myFunc("test2")
myFunc(3);
myFunc(3, 5);
myFunc("five", 5);
]]>
https://kinsey.no/blog/index.php/2007/11/15/javascript-function-overloading/feed/ 4