KBD

Keith Devens .com

Friday, May 16, 2008 Flag waving
There is a rank due to the United States, among nations, which will be withheld, if not absolutely lost, by... – George Washington

Tag: Programming languages

Parents:

Children:

Page 1 →

Daily link icon Monday, May 12, 2008

  1. John Resig - Processing.js (via):

    I've ported the Processing visualization language to JavaScript, using the Canvas element.

    Impressive, to say the least.

       (0) Tags: [Javascript]

Daily link icon Thursday, April 24, 2008

  1. Generator Tricks for Systems Programmers (via). Presentation on Python's generators.

       (0) Tags: [Python]

Daily link icon Wednesday, April 23, 2008

  1. JavaScript: The Good Parts, by Douglas Crockford (via).

       (0) Tags: [Books, Javascript]
  2. Reading binary files using Ajax « nagoon97’s Weblog (via).

       (0) Tags: [Ajax]

Daily link icon Tuesday, April 15, 2008

  1. Javascript getElementsByClass function. I know there's one built into prototype, but I didn't want to include the whole library since I wasn't already using it. This seems to work.

       (2) Tags: [Javascript]

Daily link icon Monday, April 7, 2008

  1. JSLint, The JavaScript Verifier (via).

       (0) Tags: [Javascript]

Daily link icon Thursday, February 14, 2008

  1. JavaScript Kit- DOM Table Object Methods.

       (0) Tags: [Javascript, Web Development]

Daily link icon Wednesday, February 13, 2008

Join a NameValueCollection into a querystring in C#

C# is ugly as heck:

private static string JoinNvcToQs(System.Collections.Specialized.NameValueCollection qs){
    return string.Join("&", Array.ConvertAll<string, string>(qs.AllKeys, delegate(string key){
        return string.Format("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(qs[key]));
    }));
}

In Ruby, this would be (essentially):

e = URI.escape
qs.collect{ |k,v| e(k)+"="+e(v) }.join("&")

Daily link icon Tuesday, January 29, 2008

  1. Faster JavaScript Trim.

       (0) Tags: [Javascript]

Daily link icon Friday, January 11, 2008

  1. ASP.NET AJAX Control Toolkit.

       (2) Tags: [ASP.NET, Javascript]

Daily link icon Monday, December 17, 2007

  1. AppJet: Instant Web Programming (via).

       (0) Tags: [Javascript, Web Development]

Daily link icon Monday, December 10, 2007

  1. Jash: JavaScript Shell (via, via).

       (0) Tags: [Javascript]

Daily link icon Monday, September 24, 2007

  1. 7 reasons I switched back to PHP after 2 years on Rails - O'Reilly Ruby (via). The main reason I'd hope to switch to Rails is not for Rails itself, but to be able to use Ruby. If only PHP used Ruby Smiley frowning

       (0) Tags: [PHP, Ruby, Ruby on Rails]

Daily link icon Wednesday, September 19, 2007

  1. Minimal FORTH compiler and tutorial | Lambda the Ultimate.

       (0) Tags: [Forth]

Daily link icon Thursday, September 13, 2007

  1. ONLamp.com -- An Introduction to Erlang (via). To read.

       (0) Tags: [Erlang]

Daily link icon Wednesday, September 12, 2007

while(<>){...} in Ruby

Re: translate Perl diamond operator to Ruby.

Perl:

while(<>){
  ...
}

Ruby:

ARGF.each do |$_|
  ...
end

At this point I question whether I'd ever use Perl for anything again. Until now, Perl filled a niche where if the code I wanted to write would fit in 10 lines or so, and did a lot of string manipulation, I'd turn to Perl. Otherwise Python. Now I think I'll just use Ruby for everything Smiley

Daily link icon Friday, August 31, 2007

  1. RussellBeattie.com - Java needs an overhaul (via):

    There's something about the Java culture which just seems to encourage obtuse solutions over simplicity.

    I was bemused when Sun changed their ticker to JAVA the other day; it's a name they won't want to be associated with in a few years. Kinda surprised they want to be associated with it now tbh... this isn't 1999.

       (0) Tags: [Java]

Daily link icon Thursday, August 16, 2007

  1. Simon Willison: jQuery for JavaScript programmers. Maybe I'll use jQuery instead of Prototype for future development.

       (0) Tags: [Javascript, Web Development]

Daily link icon Wednesday, August 8, 2007

  1. Emprise JavaScript Charts :: 100% Pure JavaScript Charts.

       (2) Tags: [Javascript]
  2. SproutCore (via):

    Sprout Core is a application framework written in Java Script. It’s designed for creating full applications that run inside the web browser.

    MIT license.

       (0) Tags: [Javascript]

Daily link icon Monday, July 30, 2007

  1. Kathy Kam : .NET Format String 101.

       (0) Tags: [C#]

Daily link icon Friday, July 13, 2007

Javascript toggle functions

Some more handy Javascript (depends on Prototype):

function toggleByClass(id, className, callback){
    // shows the element with id 'id'
    // and hides all other elements with class 'className'
    $A($$('.'+className)).each(function(element){
        $(element).style.display = "none";
    })
    if(id) // call it with a false id to hide all
        $(id).style.display = "block";
    if(callback)
        callback(id, className);
}

function toggleById(id1, id2){
    var a = $(id1).style;
    var b = $(id2).style;
    if(a.display == 'none' || a.display == ''){
        a.display = 'block';
        b.display = 'none';
    }else{
        a.display = 'none';
        b.display = 'block';
    }
}

Daily link icon Thursday, July 12, 2007

The annoying way to .clone() a list in C#

List<Type> temp = list.ConvertAll<Type>(delegate(Type a){return a;});

You'd think a generic type like List would have a useful clone or copy method, but noo. (Type is just a placeholder... insert your type here)

Daily link icon Thursday, July 5, 2007

  1. Matt Raible relays comments from Don Box:

    Richard Monson-Haefel asks "Is there a place for AOP in .NET or is it too sophisticated for your developers." Don's take is "My development platform should allow me to write code w/ a couple of beers in me." He ragged a bit on Java developers and said their main problem is they think they're smarter than they are. He also said that if he could change on thing at MSFT, it would be that Ruby becomes the language of choice.

       (0) Tags: [Java, Microsoft, Ruby]

Daily link icon Friday, June 29, 2007

<select> utility javascript functions

I always wind up needing functions to dynamically populate the options on a <select> list, or select a given item in an existing <select>. So I've finally written them out in a reusable form:

<select id="foo" onchange="alert(this.value)"/>

<script language="javascript" type="text/javascript">
function loadSelectOptions(selectId, keys, values, selectedOption){
    var list = document.getElementById(selectId)
    if(!list)
        return;

    var selectedIndex = 0;
    list.length = 0;

    var found = false;
    for(var i=0,n=keys.length; i<n; i++){
        list.options[i] = new Option(values[i], keys[i]);
        if(selectedOption == keys[i]){
            list.selectedIndex = i;
            found = true;
        }
    }
    return found;
}

function selectSelectOption(selectId, value, runEvent){
    var list = document.getElementById(selectId)
    if(!list)
        return;

    var options = list.options;
    for(var i=0,n=options.length; i<n; i++){
        if(options[i].value == value){
            list.selectedIndex = i;
            if(runEvent)
                list.onchange();
            return true;
        }
    }
    return false;
}

loadSelectOptions("foo",['foo','bar','baz'], ['FOO','BAR','BAZ'],'baz')
var list = document.getElementById("foo")
list.remove(1)
selectSelectOption("foo","baz")
</script>

Daily link icon Thursday, June 7, 2007

  1. Because I'm sure it'll come in handy later, here's a javascript object clone function:

    function clone(obj){
        if(obj == null || typeof(obj) != 'object')
            return obj;

        var temp = {};
        for(var key in obj)
            temp[key] = clone(obj[key]);
        return temp;
    }

    Update: From feedback in the comments, a better version is:

    function clone(obj){
        if(obj == null || typeof(obj) != 'object')
            return obj;

        var temp = new obj.constructor(); // changed (twice)
        for(var key in obj)
            temp[key] = clone(obj[key]);

        return temp;
    }
       (18) Tags: [Code, Javascript]

Daily link icon Monday, June 4, 2007

How to "correctly" format currency in C#

For some reason C#, by default, formats negative currency as "($12,345,678.90)" instead of "-$12,345...". Here's code that lets you change that (wordwrapped for her pleasure):

// set currency format
string curCulture =
    System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
System.Globalization.NumberFormatInfo currencyFormat =
    new System.Globalization.CultureInfo(curCulture).NumberFormat;
currencyFormat.CurrencyNegativePattern = 1;

number.ToString("c", currencyFormat);
// or string.Format(currencyFormat, "{0:c}", number);

C# is retarded.

Daily link icon Wednesday, May 9, 2007

  1. Labnotes » Buildr, or when Ruby is faster than Java:

    Somewhere in my ever expanding list of drafts I’ll never get to finish is another post about the economics of Ruby, and how raw performance is less of a problem when you’re bound by the database, spend less on development, and can optimize in the large. Basically, regurgitating the same justifications I used to explain Java a decade ago.

    But this is not that post.

    Today, I’m going to talk about something else, and share with you an interesting discovery from working on Buildr. There will be no language theologies or abstractions of performance, just the facts.

    Off the bat, we downsized 5,443 lines of XML abuse spread over 52 files, into a single build script weighting a measly 485 lines. It’s amazing what a real language, with proper variables and (gasp!) functions and objects, can do.

    Of course, we’re not measuring raw Ruby against pure Java. We’re comparing one implementation against another, where they both do the same thing. Black box equivalent. That’s a real life benchmark.

    We know the Ruby-based solution performs significantly faster, is much more reliable, requires less work to use and maintain, and took all of 3 months from concept to working release.

    Ruby might be slow, but what you build with it can be devilish fast.

       (0) Tags: [Java, Ruby]

Daily link icon Monday, April 9, 2007

  1. Destroydrop » Javascripts » Tree. dTree has worked great for me so far.

       (3) Tags: [Javascript, Web Development]

Daily link icon Thursday, March 8, 2007

C# Frequently Asked Questions : Why can't I use the same variable as an inner loop does?

C# Frequently Asked Questions : Why can't I use the same variable as an inner loop does?. Language designers, please don't try to protect me from something like this. It's annoying.

But for fun, check out the possibly contradictory compile errors in code like:

public static void Main(string[] args){
   for(int y=0; y<100; y++){}
   Console.Write(y);
   int y = 0;
}

y doesn't exist but yet can't be created.

Page 1 →
May 2008
SunMonTueWedThuFriSat
 123
45678910
11121314151617
18192021222324
25262728293031



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 1 posts

Recent comments XML

"IMDB for music"

IMDB for Music? It looks to be a​couple of years old...​http://MusicTell.co...

Ken Empie: May 14, 9:57pm

Generated in about 0.216s.

(Used 12 db queries)