The need for JavaScript “Frameworks”

This title seems relatively understandable, but I assure you I don’t mean libraries like, JQueries, Dojo, or YUI..  Quite on the contrary. The difference between frameworks and libraries is the pivotal point.

Libraries vs Frameworks

Libraries simply provide functionality. For example, JQuery is an awesome library. It can enhance any website adding interactivity with minimalistic and efficient code. When people think of frameworks on the other hand. Things such as Django and Rails come to mind. The difference might be coming more clear now.

Most importantly, frameworks provide an MVC structure to work on. They provide a structured approach to getting to job done. Good framework will keep your code clean and actually give you less that will “just work” better.

Web application developers generally neglect the use of MVC in highly dynamic web pages when they really shouldn’t. To be specific I believe that the Model (M in MVC) is ignored quite too often.

JavaScript does have frameworks, quite a few in fact, with some of the most notable being SproutCore, Cappuccino, and JavaScriptMVC.  Far too often they are unheard of or unused.  From what I’ve seen it’s simply the complexity level and browser support (slow JavaScript) that really keeps people away.  But as those tides turn it’s time to re-think our front end strategy.

The real divide

Here’s what I suggest all good web apps should look like.  A two-tiered approach.

Front-end MVC

The part of the MVC that gets trampled the most in front-end coding has got to the the Model.  Without it, data has no form of encapsulation and becomes a big pile of variables.  It’s hard to find cohesion between data-sets and the front end becomes complicated to understand.  Models also make it easy to cache previously used data.

Views seem harder to picture but it would be the currently visible portion of the web page.  Currently active and running widgets would account for the View here as well.  Anything dealing with or CRUDing (Create, Read, Update, Delete) HTML.

If you can segregate your JavaScript into logical Models and Views then Controllers will naturally be responsible for handling the actions and events.  And JavaScript is really good with that stuff :)

Cleaner Code Ahead!

Always think of web applications as two separate tiers (which they are!) and you will realize that the browser deserves good object design as well.

http://cappuccino.org/

Canvas Art and Data Visualization

I just keep running across neat stuff on the web.. Here’s two newer sites that might impress:

Harmony

Cool HTML5 Canvas drawing pad.  A neat take on new technology.  I expect much more artsy stuff like this to come out in the near future.

Prezi

Need a presentation but worried it will bore your audience to death?  Try out this new and inventive way to get your ideas across.  It’s free and hosted online.

Installing Git on CentOS 5

March 25th, 2010 Dominic Baranski View Comments

This technique requires the “Extra Packages for Enterprise Linux” repo.. So this is not a .rpm install from some untrusted site. It’s from the RedHat repos themselves.

Firstly, install the EPEL package. More information on EPEL is available from their site. Then, install git and you’re done!

su -c 'rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm'
yum install git

See the EPEL FAQ for more details.

Categories: CentOS Tags: , , ,

Slow SSH Logins on CentOS 5

March 24th, 2010 Dominic Baranski View Comments

Following any of the usual how-to’s didn’t leave me with a successfully speedy login.. I eventually tracked down the problem to a particularly monumental bug in RedHat’s OpenSSH server (apparently fixed up stream.. it does us all now no good)..

The fix

  1. edit /etc/ssh/sshd_config
  2. Find and change the lines (or add if missing):
    GSSAPIAuthentication yes
    ...
    #UseDNS yes

    to

    GSSAPIAuthentication no
    ...
    UseDNS no
  3. Enjoy

Side Note

If you use CentOS you’re probably unable to reboot your SSH server and you don’t know it.

I also experienced this problem while attempting to restart the ssh server. Everything seemed to work but when checking the logs it showed serious errors. It complained about being unable to bind to port 22. To see if you have the same problem follow these steps..

/etc/init.d/sshd reload
tail /var/log/secure

If you find something like the following:

sshd[20213]: Server listening on :: port 22.
sshd[20213]: error: Bind to port 22 on 0.0.0.0 failed: Address already in use.

then you’ve got problems.. It’s basically saying that the localhost IPv6 address (represented as “::”) is hogging port 22 instead of 0.0.0.0 (means ANY IPv4 address). If that’s what you want, then great! If not..

edit

/etc/ssh/sshd_config

and change it to look as follows from

#ListenAddress 0.0.0.0
#ListenAddress ::

to

ListenAddress 0.0.0.0
#ListenAddress ::

Hope this helps!

References

Categories: CentOS Tags: , ,

JSON Data Wrappers

March 19th, 2010 Dominic Baranski View Comments

Many people use JSON nowadays to output information. Its lightweight and awesome! So why not. But I find that people neglect to maintain an appropriate syntax, if you will, while writing JSON output.

Now, what I mean by “wrappers” is that most examples I’ve seen send back a JSON list. This list should always be wrapped with additional server information in case of internal server errors (500 errors) or the need for other clarifications (errors, total item counts, etc).

A basic example wrapper

{
"status": "ok",
"message": "",
"resultCount": 10,
"resultOffset": 3
"resultSet" : ["one", "two", "three"]
}

Using this Style of wrapper I know:

  • There were no problems on the server side (the status entry)
  • There are 10 results in total for whatever I want (the resultCount entry)
  • The results are offset by 3 (the resultOffset)
  • I have 3 results to display to the end user (the resultSet entry)

Note that some of these parameters could be optional (like offset).  But make sure that whoever is writing the JavaScript knows this!  It could otherwise cause unrecoverable JavaScript errors.

Server Error handled gracefully

{
"status": "error",
"message": "Database Error",
"resultCount": 0,
"resultSet" : []
}

Here’s an example of a server 500 that, despite being completely unrecoverable, still gracefully displays JSON as to not cause execution errors in the browser.  Note that I omitted resultOffset as I am using this parameter optionally.  I do return an empty resutSet though.  JUST in case someone forgot to program any error handling in the JavaScript.

Looking Forward

This is only a simple example of what your wrapper should include, feel free to add other information like a timestamp for when it was served or other important data.  To get you started look at some examples from Google or Yahoo for ideas.

Rebooting the Blog

February 23rd, 2010 Dominic Baranski View Comments

Well, It’s been some time since I’ve posted anything in my blog (about a year) and I figured it was time to do some spring cleaning.  I’ve dumped Drupal in exchange for WordPress now since it fits my needs better and it far easier to maintain.

If anyone came to this site from a link or Google search I will make the old blog available shortly for archival purposes.

Categories: Site News Tags:

No Bluetooth on Ubuntu because of Bluesoleil

For quite some time I simply couldn’t get Ubuntu to recognize my bluetooth adapter! I knew it worked because when I got the adapter and tried the provided software (Which just happened to be Bluesoleil) everything worked. After deciding not to use the proprietary software i removed it and the adapter stopped working.

Running the general command to start up bluetooth only gave a cryptic message..

$ bluetoothd -d -n
Can't open HCI socket: Address family not supported by protocol (97)

After googling around lead me to the fact that some kernel modules wern’t loaded for bluetooth. “Heh” I though since it WAS working fine before. So I tried to enable the missing modules as per some other instructions:

$ sudo modprobe bluetooth
FATAL: Could not open '/lib/modules/2.6.27-9-generic/kernel/net/bluetooth/bluetooth.ko': No such file or directory

again.. more head scratching.. so after going to where the missing bluetooth.ko file should be located i find bluetooth.ko.bak instead. since there is no bluetooth.ko file I just removed the .bak extension and retried modprobe again.

$ sudo modprobe

Success! As to why it was a .bak file I had NO idea until i googled it. I found another user with the same .bak file which commented on bluesoleil doing the move. So I finally find the culprit of my bluetooth despair!

Categories: Ubuntu Tags: ,

Running Zend Studio on 64 bit Ubuntu

April 24th, 2009 Dominic Baranski View Comments

If you’re trying to install Zend Studio on a 64 bit install of Ubuntu you will run into trouble unless you install the libc6-i386 and ia32-libs. Here is the command you need:

sudo apt-get install libc6-i386 ia32-libs

(This information came from the ubuntu forums)

Categories: Ubuntu Tags: , ,

Pidgin MSN Spam

February 5th, 2009 Dominic Baranski View Comments

For some reason the Pidgin messaging program that comes with Ubuntu seems to think users want to receive messages from the entire world. That’s not necessarily a bad thing but there are too many spam bots out there to make this particular feature quite annoying.

Luckily it’s a simple fix to turn off said spam (thanks to Techtites article)

  1. Run pidgin and open the buddy list window.
  2. Go to Tools > Privacy.
  3. Choose the account that’s bothering you with spam (in my case MSN) and select the desired contact options (again, in my case it was Allow only the users on my contact list)
  4. Enjoy spam free living.
Categories: Ubuntu Tags: , ,

SRCDS Linux auto-update fix

February 2nd, 2009 Dominic Baranski View Comments

The Problem

For some reason the Linux version of the dedicated server does not auto-update properly. It will simply fail to find the srcds bin file and have you do it manually for every update which gets very frustrating.

The problem originates from the introduction of a new subdirectory for all “new” source engine games. Luckily, this can be fixed with just two new “cd” lines in the script file!

The Fix

  1. Find and open the file srcds_run for editing (It will be a script file). It can be found in the game directory like /orangebox or /l4d
  2. search for the line update(). It can be found around line number 295.
  3. Make it look like this:
    update() {
        PWD=pwd
        cd ..
        updatesingle
        cd $PWD
    }

This should update any “new” srcds server by going back one directory, running srcds, and returning to the previous directory.

Notes
I suggest saving this new copy of srcds_run as something else like “srcds_run_tf2″. This will prevent the file from ever being overwritten by an update and will keep the original file if ever needed again.

Updated: Nov 26th
- Made this how-to more generic for any game like l4d

Categories: SRCDS Tags: ,