JavaScript syntax hightlighters

I found some really cool code editors and syntax hightlighters written in JavaScript and I thought I’d share.

The best I’ve found so far is CodePress. It supports many languages, hightlights as you type, adds line numbers, and seems the most reliable.

CodeMirror is another one I found. While it isn’t as polished as CodePress, he describes how he went about creating it which I found helpful and interesting (especially the bit about the maniacal gnome.)

EditArea is another impressive one, but I haven’t looked into it too much.

CodeArea 2 has an example editing html, but I can’t read any of the text around it since it is not written in English. It’s a .cz domain, the Czech Republic, where the speak Czech apparently.

Also, while looking for editors, I stumbled across a vi clone in JavaScript. It is impressively complete. It’s almost as cool as DHTML Lemmings.

Edit 11/2/07 1:33PM: removed funky font tags.

Posted in Software Development | Tagged | Leave a comment

So many JavaScript libraries!

Just looking around for some JavaScript libraries to use in some new code, I came up with all these libraries:

  1. Prototype
  2. jQuery
  3. MochiKit
  4. MooTools
  5. script.aculo.us
  6. Dojo
  7. Ext JS
  8. ASP.NET AJAX Control Toolkit
  9. The Yahoo! User Interface Library (YUI)
  10. SimpleJS

I haven’t been able to find a decent comparison of the different frameworks (what they do, compatibility, download size). I might come up with my own table soon if I can’t find anything.

I have used the ASP.NET AJAX Control ToolkitASP.NET AJAX Control Toolkit with ASP.NET AJAX are two different things btw. I’ve just been calling the whole thing msajax just because the naming is so ambigous, YUI, and Prototype so far. I think those three are compatible, but I’m not sure. (What I should say is nothing has broken from using the three libraries in a single app.)

Does anyone out there have any good comparisons between all the major libraries?

Posted in Software Development | Tagged | 3 Comments

Trying to disprove some .net string memory usage myths

I’ve run into a few string/constants myths repeatedly and I thought I’d try to disprove them. Myth 1: constants use less memory. Myth 2: inline strings are always bad. Myth 3: String.Empty doesn’t create an object while “” does.

I’m just running a bunch of different pieces of code and dumping memory statistics before and after to measure. The trimmed output of sos’s !dumpheap -stat command are included after each line.

Thanks to Pale Musings for the sos memory leaks article.

Contents

Steps to reproduce:

  1. Create console app.
  2. Go to project properties, enable unmanaged debugging.
  3. In main add (changing the first line each time)
  4. string value = "span";
    Console.WriteLine(value);
    Console.ReadKey(true);

  5. Put breakpoints on lines 1 and 2.
  6. Run app with debugger (F5).
  7. In the immediate window type .load sos
  8. In the immediate window type !dumpheap -stat
  9. Run to next breakpoint (F5).
  10. In the immediate window type !dumpheap -stat
  11. Compare output from dumpheap.
  12. Change line 1 and repeat.

Simple inline string

code: string value = "span";

before:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

Enum to lower case string

code: string value = HtmlTextWriterTag.Span.ToString().ToLower();

before:

      MT    Count    TotalSize Class Name
...
790f9244     4825       264628 System.String
Total 4875 objects

after:

 Count    TotalSize Class Name
...
790f9244     4932       267760 System.String
Total 5177 objects

Second enum to string

I thought the above might be unfair. Maybe I was counting memory usage from loading the System.Web assembly or the HtmlTextWriterTag for the first time.

code: span.ToString().ToLower();

before:

      MT    Count    TotalSize Class Name
...
790f9244     4825       264628 System.String
Total 4875 objects

after:

      MT    Count    TotalSize Class Name
790f9244     4932       267760 System.String
Total 5177 objects

Constant defined in the same class

code: string value = span; (span is a constant of the class)

before:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

Using the same string repeatedly inline

code: string value = "span";
string value2 = "span";
string value3 = "span";
string value4 = "span";
string value5 = "span";

before:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

Two different inline strings

code: string value = "span a";
string value2 = "span b";

before:

      MT    Count    TotalSize Class Name
...
790f9244     2039       129828 System.String
Total 2086 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2039       129828 System.String
Total 2086 objects

Appending constants with +

code: string value = span + a;
string value2 = span + b;
(span, a, b are constants)

before:

      MT    Count    TotalSize Class Name
...
790f9244     2039       129828 System.String
Total 2086 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2039       129828 System.String
Total 2086 objects

Quote quote (“”)

code: string value = "";

before:

      MT    Count    TotalSize Class Name

790f9244     2038       129784 System.String
Total 2085 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129784 System.String
Total 2085 objects

String.Empty

code: string value = String.Empty

before:

      MT    Count    TotalSize Class Name
...
790f9244     2037       129764 System.String
Total 2082 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2037       129764 System.String
Total 2082 objects

Conclusion

So: using inline strings is no better than constants as far as memory or performance are concerned. Enums are worse than constants or inline. String.Empty did save me one object instance and a whole 20 bytes.

For readability and maintainability, constants can help. Personally I find code where everything is a constant even if it is only used once annoying, but that’s just me :)

There’s probably other pages on the net that go into exactly why this all is. At the moment I’m too lazy to go searching for them. Go ahead and open the code in reflector to see what it’s getting compiled to if you want.

The actual difference in any of these is probably so small you’ll never notice it, so go with whatever is easiest and most readable for you.

Posted in Software Development | Tagged | Leave a comment

Was looking for some cell phone apps, found a web browser instead.

A while ago I was looking for an application that would run on my phone that I could could use to connect to this blog. I wasn’t planning on using it much, but I thought it’d be useful for jotting down notes for later. I thought there ought to be a few that could connect to a blogging api. I even found a few that claimed to, but I never got them to work.

You know what I found? My phone’s web browser. I finally realized that I could just connect with the browser and have all the same features available as if I were at my desk. I don’t know why it took me so long to realize that, but it did.

And then, just today: I wanted to check the temperature before going out. “There must be a ton of weather apps out there” I thought. I started searching for one. And then I realized something. I could just type 97701 temp into Google and it would give me exacty what I wanted.

Anyway, I’ve just come to realize how I can do most anything online with nothing more than a web browser. Nothing revolutionary, just an observation.

By the way I wrote and posted this entire post from my phone’s browser, just because I can.

Posted in Technology | Tagged | Leave a comment

I Just Fixed an Odd Timeout Error With Our CruiseControl.net/NAnt/WatiN Setup

The problem:

I have this project I’m working on that uses WatiN WatiN is a tool to write tests for web applications by controlling an Internet Explorer window. to test an asp.net site. For some reason some tests would fail with a timeout trying to find an element or waiting for an element to show up after an UpdatePanel postback. It would go through about half the test before stopping, it was able to open the browser, click buttons, type text, etc.

I couldn’t figure it out. I ran the tests from the command line with NAnt, but they all worked then. They all worked when I ran them from localhost. I put [Ignore] attributes on most of the tests, I used MSE MSE: Managed Stack Explorer. It will connect to a .net process and give a stack trace of where it is currently. looking for deadlocks. I couldn’t figure it out for the longest time.

The Solution:

Finally I went to Windows Update on the build server. I thought maybe my workstation has some patch that is not on the server yet. When I got there it told me that due to being on the internet zone, instead of the trusted zone, it couldn’t do it’s stuff. This got me thinking an eventually I went to the url the tests were hitting and that wasn’t in a trusted zone either.

Adding the urls to the local intranet zone fixed all my problems. I’m not sure if the security was restricting WatiN or the msajax library. I’d suspect the ajax stuff just because it seems like WatiN isn’t going to be restricted by IE’s security features.

Posted in Software Development | Tagged | 2 Comments

Some More Pictures (Lightning and Sunset)

So, I’ve been taking more pictures lately. (and some of them even came out nicely.) I thought I’d make a picture post with some of them.

All of the pictures are from Bend. The lightning is from the big storm we had almost a month ago and the sunset is from a few days ago.

lightning

lightning

sunset

sunset

Posted in Bend | Tagged | Leave a comment

Some Pics From the Black Butte Ranch Fire Last Weekend

Got some pictures of the fire from last weekend. These are actually pictures I took unlike my post from last year.

Here’s a few of them (there’s more in the gallery):

Posted in Bend | Tagged | Leave a comment

Looking For a Web Application Speed Testing Tool

I’m not sure if anyone will notice this, it’s been over a month since my last post…

Anyway, I’m looking for a tool to test a web application’s performance. Specifically I’m looking for something with these features:

  • Give it a url of a page and it will load the page, images, css, javascript, css images, and flash files in the order that a browser would.
  • Hit the server just like a browser: only 2 connections per user, only 1 javascript file at a time, supports gzip compression.
  • Can optionally use the Last-Modified, If-Modified-Since, ETag, and Expires headers on subsequent requests from each user.
  • Reports on average time to load the full page.
  • Outputs to a basic format like csv or simple xml that I could load into Excel for example.
  • Appents to the log so that I could run this once a day and gather stats.
  • Can be run from the command line so I could set up an automated process or integrate into the build server.

Things that would be just sweet, but not absolutely required:

  • Reports on the time it takes for the user to see a partial page; i.e. layout, links and have loaded, but not necessarily all images or scripts at the end of the page.
  • Specific browser independent or can simulate different browsers.
  • Simulate many users for stress testing.
  • Report total file size of page.
  • Open source or at least free.
  • Server independent: can test IIS or Apache or Tomcat or whatever.

I’ve been looking around and I haven’t found a lot. A lot of what I’ve found has been incomplete open source projects without any updates since around 2001 and there’s quite a few that are proprietary and won’t even list a price (probably way too expensive.)

Most tools seem to be either throwing as many requests at a server as possible (Microsoft’s ACT), or integration/logic testing (Selenium, WatiN). While these tools are useful and I’ve used them all before, none quite fit what I’m looking for. I also understand the Visual Studio tester edition (or whatever it’s called) has some new tool to replace ACT, but I don’t have that version because apparently I’m just a developer, not a “tester” according to Microsoft.

YSlow‘s stats is close to what I’m looking for, I’d like to be able to record the stats and automate it. ACT can almost do this, but it only records what IE does once, so if I remove a javascript file, or change the modification date, etc. I have to recreate the test. Plus it records requests per second, when I’m more interested in average page load time.

Anyway, I figured I’d just throw the question out there. If I can’t find anything, I may start a small command line C# project to do it.

Posted in Software Development | Tagged | 3 Comments

A Useful Article on MSAJAX and UpdatePanels

I found this article on UpdatePanel tips and tricks useful. The official site at http://ajax.asp.net has loads of documentation, but I haven’t found it too useful other than for the very basic stuff.

The feel I got from the ajax.asp.net documentation was that you weren’t supposed to write any JavaScript to use with UpdatePanels. This article showed how to trigger JavaScript before and after an UpdatePanel updates and how to bypass the UpdatePanels altogether.

Also, Firebug has been very useful in debugging this since you can see the full request and response for all the communication back to the server. The logging ability is also much nicer than having alert boxes everywhere.

Posted in Software Development | Tagged | Leave a comment

Viewstate & Search Engines Update

Continuing my viewstate tests to if it has any affect on search rankings. My test pages for viewstate aren’t showing up in Google yet. The index page is there and Palehorse’s page is there. I don’t care if the test pages beat any other pages on the net, I just want to compare them relative to each other.

I figure I’d try linking to each page directly from here. Also, I removed the test word from the index page and added links to all six test pages on each test page. Here’s the links: Edit: removed since I’m long done with the test and tired of seeing file not found errors. :P

  • test
  • test
  • test
  • test
  • test
  • test
Posted in Software Development | Tagged | 1 Comment