Being Away Thu, 3 Sep 2009 12:58:07 -0400

Sorry for the emptiness, I have been quite busy lately. Having relocated the family to Berea, Kentucky has been very taxing on my time and energy. I have some cool stuff I'm working on in erlang and I hopw to be able to make a post about that soon. As well as maybe a C network event driven library for TCP/UDP over IPv4 and IPv6 soon.

0 comments. More...
Getting Around ODBC slow connection pooling in Erlang Mon, 10 Aug 2009 10:32:03 -0400

If your like me you use SQL quite a bit, or least for some form of data source. One of the most portable methods for SQL interfacing is to use some form of abstraction, this adds portability as well as some support (sometimes). In this case I'm using Erlang to query a bunch of data out of a database and I want to do this very very quickly and efficiently

I've read only that ODBC v3 is supposed to support connection pooling by default, however on my PC (ubuntu hardy) is slow as heck and has a long latency time for initializing connections. However I was able to come up with a way around this by creating a process that does nothing but SQL functions. The below example should be all you need to start using this yourself.


-module(fetcher).
-author("Brian Smith").
-export([start, loop0/0, loop0/1, query/1]).

-define(DSN, "dsn=myodbc3").

start() ->
    register(fetcher_pid, spawn(?MODULE, loop0, [])).

loop0() ->
    {ok, DbConn} = odbc:connect(?DSN, []),
    loop0(DbConn).
loop0(DbConn) ->
    receive
        {sql, From, SqlStmt} ->
             From ! odbc:sql_query(DbConn, SqlStmt),
             loop0(DbConn);
        quit ->
             odbc:disconnect(DbConn),
             quit
    end.

query(SqlStmt) ->
   fetcher_pid ! {sql, self(), SqlStmt},
   receive
        _Results ->
                 _Results
   end.

To use you just need to run fetcher:start().. I'm still trying to figure out how to block the pid for receiving SQL queries until odbc:connect() is complete, so any ideas on this is appreciated.

1 comments. More...
DJB2 String Hashing Algorithm Implemented in Erlang Wed, 29 Jul 2009 15:53:45 -0400

Erlang is a very interesting functional programming language that has been receiving a fair amount of attention lately. So I've been playing with it off and on as my little fun project for educating myself. So to give back here is a simple DJB2 hashing algorithm implemented in Erlang.

Something I have had problems with before when implementing DJB2 in those languages (such as Python) is the native infinite precision integers of those languages. However by bitwise AND logic the result of the hash against the maximum value of a C unsigned long negates that by truncating the result buffer so we remain using the proper number of bits for the hashing.


-module(djb2).
-author('Brian Smith http://www.modernninja.com/').
-export([hash/1, djb2/2]).

-define(INIT_HASH, 5381).

hash(String) -> djb2(String, ?INIT_HASH).

djb2([], Hash) -> Hash;
djb2([Head|Rest], Hash) -> djb2(Rest, (((Hash bsl 5) + Hash) + Head) band 16#FFFFFFFF).

14 comments. More...
OMG I HATE Javascript, JQuery to the Rescue! Thu, 23 Apr 2009 20:22:24 -0400

Okay so as web developers we often run into issues. Okay lets call it like it is, we have to deal with IE. Well today I was working on the dreaded issue with making a menu that will close when you click or focus anywhere else on the page. This one is special because I have a text input field in the menu that is used in conjunction with AJAX to resort/filter the menu items by what is being typed. This would be relatively easy with jquery and an UNDERSTANDING browser.


function openMenu() {
    $('#menu').toggleOn();
    $(document).one('focus', function() {
        $('#menu').toggleOff();
    });
}

See how simple that is? It amazes myself, but that really is all it takes. Then you introduce IE, which only adheres focus to form elements. But aha! I found a way around it, this technique could be duplicated in other frameworks like MooTools, Prototype and plain jane Javascript.


function openMenu() {
    $('#menu').toggleOn();
    $('#menuFilter').one('blur', function() {
        $('#menu').toggleOff(150);
    }
    $('#menuFilter').focus();
}

The 150 timeout on the toggleOff gives time for any events, such as an anchor clicked to process.

0 comments. More...
Migrating Servers Mon, 20 Apr 2009 14:41:45 -0400

Okay, so I'm nearing a transition in life. Not only is my first baby due 1 month from yesterday, but I also have to migrate one of the largest site's I've ever managed. I can't give any details atm for what it is, or why. But I am moving everything to a cluster of servers configured in Amazon's EC2 Cloud using a few parts of their technologies, which will hopefully expand to some others, that should end up totally rockin, and way cheaper. Currently the binary database for this system is approaching 100 gigabytes. And there are other migration issues at hand in regards to the nature of the network and the data it maintains, but sufficient to say that there is some new data being imported at least every 10 minutes or less.

Each day has shown increase in load, as well to the fact that the imported data stands around 20 million records a day currently and that now we will expand the abstraction of said data from 1 table to 250+ tables. Thank goodness with EC2 I can quickly throw up more instances to handle any load and scale horizontally.

TBH this is probably the first technology that I've been really impressed with in a long time, now the only question is if it can stand up to it's promise.

This isn't my first time messing with the concept of shared resource processing networks. When I was 16 I built a beowulf cluster using computers that were being thrown away by my high school. Mostly Pentium's and 486, but considering I didn't have anything better and the electric bill was paid by my parents at the time I enjoyed the challenge. Granted I never was able to find a use for the network. Then a couple of years ago with 3tera launching their grid I began to research and came up with a couple of theories of how they had done this. I concluded they used a set of common GNU tools, the names of which have long escaped me. C'mon it was like 3 years ago!

Anyway, it's very cool and change is a comin so you better get ready for it!

0 comments. More...
  • Disclaimer
  • The ideas and opinions expressed here are mine.
  • I'm a Linux and BSD user, and lean heavily toward the use of OSS vs certain other commercial solutions.

View the Ninja's profile on LinkedIn

:= RSS =: