Archive

Posts Tagged ‘how-to’

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.

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: ,

Gnome CPU Frequency Scailing Monitor Govoners

February 2nd, 2009 Dominic Baranski View Comments

If you’ve ever used the GNOME CPU Scaling Monitor before you will know that it does not allow the switching of stepping speeds or governors off the bat.

Thanks to Carthik it is only a matter of entering one command in your console and selecting the option ‘Yes’ to enable said scaling:

sudo dpkg-reconfigure gnome-applets

enjoy :)

Categories: Ubuntu Tags: , ,

Ubuntu 8.10: HAL .fdi files replace xorg.conf

February 2nd, 2009 Dominic Baranski View Comments

With the release of Ubuntu 8.10 comes a relatively radical change from the norm; The obsolescence of the xorg.conf file!

The xorg.conf file is now replaced with the use of .fdi files that can be “plugged” and “unplugged” without the need to restart the computer.  More information on the usage of these fdi files can be found on Ubuntu’s wiki site. Overall they provide more flexibility then the previous xorg.conf syntax, make use of XML, and allow for “matching” or “pairing” if the system has enabled components.

Here’s a .fdi file I whipped up for my touchpad that I called touchpad.fdi and placed in the /etc/hal/fdi/policy folder as per the wiki’s instructions.

<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
  <device>
    <match key="input.x11_driver" string="synaptics">
      <merge key="input.x11_options.SendCoreEvents" type="string">true</merge>
      <merge key="input.x11_options.Device" type="string">/dev/psaux</merge>
      <merge key="input.x11_options.Protocol" type="string">auto-dev</merge>
      <merge key="input.x11_options.HorizEdgeScroll" type="string">0</merge>
      <merge key="input.x11_options.SHMConfig" type="string">on</merge>
      <merge key="input.x11_options.FingerLow" type="string">7</merge>
      <merge key="input.x11_options.FingerHigh" type="string">8</merge>
      <merge key="input.x11_options.MinSpeed" type="string">0.60</merge>
      <merge key="input.x11_options.MaxSpeed" type="string">1.10</merge>
      <merge key="input.x11_options.AccelFactor" type="string">0.030</merge>
    </match>
  </device>
</deviceinfo>
Categories: Ubuntu Tags: , , ,

Ubuntu workarounds for HP dv4000 laptops

January 31st, 2009 Dominic Baranski View Comments

I enjoy using Ubuntu as my OS of choice.  But there are always a few quirks to work out to make things “just right”.  Here’s a short list of changes I’ve done to make Ubuntu work better for me.

Wireless light

The wireless light always remains turned off.  My laptop (and probably most other dv4000′s) uses the ipw2200 wireless card made by Intel.  This card is actually supported very well in the open source community thanks to Intel releasing the driver code.  Here is the command to get this working:

$ sudo echo "options ipw2200 led=1" >> /etc/modprobe.d/ipw2200

Mute light

The Mute LED never worked on my laptop.  The muting itself worked fine, but the light never turned on.  Here\’s a fix to solve this problem.

$ sudo echo "options snd-intel8x0 ac97_quirk=mute_led" >> /etc/modprobe.d/options

More information on different quirk options is available on this forum topic.

More information to follow as I remember / do it!

Categories: Ubuntu Tags: , , ,