Network problems with DNS symptoms

March 14th, 2010

If you are having what seems to be DNS problems in your network, but others seem to connect without problems it might not be DNS problems at all, but something to do with your MTU setting, read more here. This solved a problem I’ve had for a long time on a friends network.

Martin Uncategorized

Harvest time tracking widget for Opera

March 14th, 2010

I’ve made a Opera widget that connects to Harvest, a time tracking/invoicing service which is great. The widget is built using only HTML/CSS/Javascript(jQuery) and since I only need to support Opera, I have used technologies like web databases, rounded CSS corners, box shadow etc. Also nice to have the ability to use CSS selectors like :last-of-type to make things easier.

Download it here

Martin Development, HTML5, Software

HowTo: Set google “I’m Feeling Lucky” as default search

October 23rd, 2009

URL’s suck.

When I want to go to Google calendar I want to type just that, or even google cal. Instead of Google dot com slash calendar. When I want to see today’s episode of Colbert report, I should be able to type that in the address bar even though the address is colbertnation dot com.

Enter Google’s “I’m Feeling Lucky” search. Below is a guide to set Google’s “I feel lucky” as default search in various browsers:

Opera:

  • Open Google.com, or your favorite Google page.
  • Right click the search field and select “Add custom search”
  • Click details, in the address field you will see something like this:

http://www.google.com/search?hl=en&source=hp&q=%s&btnG=Google+Search&aq=f&oq=&aqi=

  • Now, change btnG=Google+Search to btnI, so it looks like this:

http://www.google.com/search?hl=en&source=hp&q=%s&btnI&aq=f&oq=&aqi=

  • Finally check “Use this as default search engine”

Chrome:

  • Enter options -> Basics ->Default search section, click manage.
  • Select the already existing Google search, click edit, copy the URL.
  • Close, and add new.
  • Type a name and, leave keyword empty, and paste into the URL that which you copied and add &btnI, it should be something like this:

{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}&q=%s&btnI

  • Click ok, and then set as default.
  • You can still search with Google by typing  the keyword (google.com) and then you’ll see the search appear under the address bar.

Martin Uncategorized, web , , ,

Dragging and resizing windows easily

October 22nd, 2009

My absolute favourite feature of KDE on linux is the ability to move a window by holding down the Alt button and left-clicking ANYWHERE in the window, and also to hold down Alt and the right-click to easily resize the window. (Why do we need huge window edges MS?)

These features I really miss on windows, but I finally found a small program that makes that possible on windows. It has the awesome name of KDE Mover-Sizer :P

Enjoy!

Martin Uncategorized ,

IIS and skype = trouble

October 20th, 2009

Do you have a problem starting a website on your developer machine but you get an error saying something like:

The process cannot access the file because it is being used by another process?

Is your website set to run on port 80?

Then ask yourself, are you running skype? If so, skype is probably the reason for this error. Skype is by default configured to use port 80 and 443 as alternatives to the standard port. Remove that under Settings -> advanced -> connections -> Use port 80 and 443 as alternatives for incoming connections.

I always seem to get that error whenever I do a reinstall of windows etc. but it always take me 5-10 min to realize that is the error :P

Martin web ,

Will Opera reinvent the web?

June 12th, 2009

Recently Opera invited webdevelopers and journalists to a video conference next week, at the 16th of june, 9 AM CEDT.

They also have set up this page http://www.opera.com/freedom/ where they say they will reinvent the web. To be honest, even though I’m a Opera user myself, I do feel like they are setting us up for a disappointment. But that remains to be seen. They sure do use big words though.

If you take a closer look at the source code for that page you can read a story where they are hinting to what this news is. Also they have a meta tag with keywords such as “new browser, beta”.

The other hints, the story, are inserted into the page as comments, they started out with just a few words, now as time goes on they add more and more to the story. I will post here on this site the story as they continue to add to it. This is what we have so far:

We start our little story with the invention of the modern day computer.
Over the years, the computers grew in numbers, and the next natural step in the evolution was to connect them together. To share things.
But as these little networks grew, some computers gained more power than the rest and called themselves servers.
Today, millions of people are connected together in a great web …

My quess is they will release some kind of P2P interaction between users of Opera, and probably other browsers if they release it as an open standard. But time will show :)

Final story:

We start our little story with the invention of the modern day computer.
Over the years, the computers grew in numbers, and the next natural step in the evolution was to connect them together. To share things.
But as these little networks grew, some computers gained more power than the rest and called themselves servers.
Today, millions of people are connected together in a great web. But now we want to do more than sharing.
We want to collaborate, get together, look at the same things and be united in new ways.
We want our computers to be able to do more things than the servers.
At Opera, we want to put YOU on the web, so that you can interact directly with who you want. How you want.
A serverless and cloudless interaction. Direct, fast and private.
Welcome to Opera Unite. The next version of the web.

Turns out I was right, not that hard to guess though. Opera unite is not that interesting in the fact of the existing services that are there, Opera even says those might be removed for the final version. The interesting fact is that developers can create services that users can take advantage of. Head over to the dev section for opera unite to read more.

Opera unite is trending 2nd on twitter at the moment, only second to #IranElection, but I think Opera would be wise to release opera unite as an open source project allowing implementation into other browsers. Just change the name ofc :) Because Opera’s market share is so small the whole idea of “reinventing the web” and changing the structure of the web could fail because of that.

But I guess we’ll just have to wait and see. Opera has had a good year, money wise, and their mobile products is doing better that ever. So I do not think they are hoping to take over the market share this way, but it might give them an increase.

Martin web

Community server REST API cache bug

June 2nd, 2009

I’ve been working with the community serverAPI lately and came across this bug:

It seems when doing a request for users with search parameters it does not cache correctly on all input parameters.  Specifically the id parameter.

I try doing the following request:

GET /api/membership.ashx/users/?id=2100,2200,2201

This gives me the user with id 2100, 2200 and 2201

But if you try something similar again before 30 sec (the time it cache the results), with different userids, then you get the same result as the first query returned:

GET /api/membership.ashx/users/?id=2101,3000,3001 returns the same

So what is up with that?

The bug is not in the client library (since I did this in fiddler), and neither the server side API component it seems. Using reflector I found that the  problem is in the generation of the cachekey in the UserQuery object in CS itself:


public string Key
{
get
{
return string.Format("PI{0}PS{1}SB{2}SO{3}ST{4}SUN{5}S{6}H{7}SID{8}RID{9}SEN{10}JD{11}JC{12}PD{13}PC{14}SCO{15}UN{16}EP{17}", new object[] {
this.PageIndex.ToString(), this.PageSize.ToString(), this.SortBy.ToString(), this.Order.ToString(), this.SearchText, this.SearchUsername.ToString(), this.Status.ToString(), this.IncludeHiddenUsers.ToString(), CSContext.Current.SettingsID.ToString(), this.RoleID.ToString(), this.SearchEmail.ToString(), this.JoinedDate.ToString(), this.JoinedDateComparer.ToString(), this.LastPostDate.ToString(), this.LastPostDateComparer.ToString(), this.SortClauseOverride,
(this.Usernames == null) ? "" : string.Join(",", this.Usernames), this.ExtendedParameters.ToString()
});
}
}

The ID’s aren’t included. I have posted at the community server forums, and they have confirmed the problem, so let’s hope it is fixed in the next version.

For now if you want several users, you have to either request by name/email i.e.
If you have to use the ID, you just have to hit the endpoint GET /api/membership.ashx/users/[userid] for each user.

Or if you don’t need the pagesize component (if you want all anyway) you could supply that uniquely for the 30 sec period of the cache, thus giving you fresh data. This is not completely safe though. See my post over at the community server forums for my suggestion.

Martin asp.net, c# , ,

Responsive webservice caching using threads

April 23rd, 2009

I worked on a project where I needed to have a user control that got data from a web service, this would slow down the site without proper caching. Usually when I get data from the database I do the caching every  5 minutes, and the person doing the request at that 5 min mark will get a small hit, but this is not a big hit so it’s acceptable.

When dealing with web services though, you will never know how long the request will take, and what about if the service is down? Here is how I did it:

In this first code block I check if the cache is in memory and if it is, then just get the object and everything is fine. If not I start a thread and let it  fetch the data for me.


//Get date from cache or insert in cache
if (Page.Cache.Get(fullCacheKey) == null)
{

//Make sure we just execute 1 thread, so we insert a threadlock value in cache, with a timeout of 1 minute
if (Page.Cache.Get(threadActiveCacheKey) == null)
{
//Set the threadlock
Page.Cache.Insert(threadActiveCacheKey, true, null, DateTime.Now.AddMinutes(1), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null);

//Start a thread to fetch the webservice data, and insert it into cache.
Thread thr = new Thread(delegate() { DoSomeLongstuff(); });
thr.Start();
}

//In the meantime show the old cache
if (Page.Cache[backupCacheKeyPrefix + fullCacheKey] != null)
{
someObject = Page.Cache[backupCacheKeyPrefix + fullCacheKey];
}

}
else
{
someObject = Page.Cache[fullCacheKey];

//Remove the old cache here
Page.Cache.Remove(backupCacheKeyPrefix + fullCacheKey);
}

//Now databind or do whatever you want with the object

This means the very first user will not get the user control displayed, in my case that just means me, as this just happens whenever I shut down the server or app-pool. (or if the slidingcache later explained expires) This is acceptable in my case, if not you would have to make sure the very first request waits for the thread with Thread.Join.

Next up is the code that takes a while (probably under a sec, but still adds to the load time of the page).

What I do here is the web service call, I have removed that part for this example. But at the end I insert the result into memory with a 5 minute absolute expiration. I also remove the “threadlock” set earlier, I put this in so that I will not have several requests initiating their own thread trying to accomplish the very same thing.


private void DoSomeLongstuff()
{
//Do your Webservice call here, the part that takes time

//Create a CacheItemRemovedCallback to be called when the "real" cache is removed
CacheItemRemovedCallback onRemove = new CacheItemRemovedCallback(InsertIntoSafetyCache);

//Insert the result object into cache and remove the "threadlock"
Page.Cache.Insert(fullCacheKey, someObject, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Low, onRemove);
Page.Cache.Remove(threadActiveCacheKey);
}

Notice also the last parameter of the Cache.Insert method, this is what get’s called whenever the cache is deleted, in other words every 5 minutes.

This simply insert the very same cache that was deleted into memory again, with another key. I have set this to a 30 minute sliding expiration. So if it is accessed at least once every 30 minutes it is kept alive.


private void InsertIntoSafetyCache(String cacheKey, Object obj, System.Web.Caching.CacheItemRemovedReason reason) {
//When the "real" cache is removed, insert the object into cache again, but with a different key and different expiration. Used here is sliding expiration of 30 minutes.
Page.Cache.Insert(backupCacheKeyPrefix + cacheKey, obj, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(30), System.Web.Caching.CacheItemPriority.Low, null);
}

This is what happens:

  • When the 5 minutes are up I still have the object in memory, but with another name.
  • I show the old cache while the new one is fetching it’s new data.
  • When the new one has data, I delete the old one.
  • If the web service is down I will have data in memory for a long time, so I will at least show something. 30 minutes, and long after that because it is refreshed at each access.
  • At each request I will try to access the web service again (well as long as I don’t have a thread running)
  • When the web service is up again, I will get it’s data and delete the old cache

So what do you think?

Martin asp.net, c#, caching

Dual screen flash fullscreen fix

April 21st, 2009

If you have 2 monitors connected to your PC you have probably tried to look at youtube, or any other flash based video site, in fullscreen on the one monitor and then do something else on the other monitor. If you try this then flash exits fullscreen. Bummer.

But do not despair, here is a youtube video that shows you how to fix that.

You would need to know what a HEX editor is and how to use it, if not leave me a comment and I’ll elaborate.

This is great!

Martin flash