Mackie MR5 Main Driver Replacement

Filed in Studio Leave a comment

Here is a step by step guide on how to replace the main driver in a Mackie MR5 speaker enclosure.

 

01. Take out the 6 perimeter screws on the back

Step 1

 

02. Remove the back plate

Step 2

 

03. Unplug connector at CN2 that has 1 red and 1 black wire
04. Unplug connector at CN5 that has 1 blue and 1 white wire
05. Unplug connector at CN4 that has 2 white wires (I used needle nosed pliars)

Steps 3, 4, 5

 

06. Remove bass port
07. Take out the 8 perimeter screws on the inner baffle
08 Slide out the inner baffle catty cornered horizontally and then lay it down partially inside
because the wires are too short and glued to the baffle to remove it all the way.

Step 8

 

09. Looking through the back at the back side of the front face locate the 6 screws remove them with a very long phillips head

Step 9

 

10. There are two more screws on the inner surface of the top of the box. Remove them with a very short phillips head

11. Slide the inner baffle back in so the wires dont stretch when you take off the front face

12. Carefully slide the front face off. The tweeter wires and “on” light are connected through the face so will only get about an inch off the box.

13. Rotate the front face carefully so you can lay it on the top of the box

Step 13

 

14. Remove the four screws holding the driver.

15. Carefully pull out the driver

16. Unplug the red wire from the positive terminal.

17. Unplug the black from the negative terminal and remove the driver

Step 15

 

Reverse order to put it back together. Make sure to snug the screws without over tightening.

 

,

RSA Token Generator

Filed in Dev Tools | Development Leave a comment

I recently switched my desktop OS to CentOS 6 from Windows 7. One of the issues I ran into was generating an RSA token. I followed these instructions:
http://www.flowerchild.org.uk/archive/2011/01/13/getting-the-rsa-software-key-working-on-android.aspx

They worked great but I could only get the token converter to work on CentOS 5. It had something to do with the linker but I did not investigate to much further once I got it working. You only have to do it once so I was not that concerned.

jQuery Datatables Plug-in

Filed in jQuery Leave a comment

I had to create some editable datatables and decided to give Datatables.net a try. It has tons of functionality and some great features. I read the documentation and tried a couple of test implementations and it seemed to work quite well. However, and this may be because of the way I think, it seemed to be missing a crucial concept when it comes to have many datatables. I DONT want to have to write an initialize block for every datatable that may happen to appear in my application. Thats a totally crap way of coding in my opinion.

You need to install the Datatables and Jeditable plugins for jQuery.

Here is how I defined the solution:

A table should become editable simply by adding some CSS classes and a couple of special attributes. The reason for all this is that I want to be able to define all the stuff for the table in one place.

  1. The table must have a unique ID
  2. The table must have a custom attribute off  ’editURL’ with a value of the URL where the edit data will be sent
  3. Any column to be edited must have a class of ‘editable’
  4. The row containing the editable column must have an ID that the columns content can be tied to.
  5. The table must have a footer that contains a hidden row which is the template for new rows.

I know that custom HTML attributes can be a problem but I will use them in this case for two reasons. One is that the Datatables plugin adds it’s own and two this is a closed audience application so I have complete control.

Here is an example of the table HTML:

<table id="botnetDomainList" class="editable" editurl="/botnets/edit_domain">
    <thead>
        <tr>
	    <th>Domain</th>
	    <th class="control>Delete</th>
	</tr>
    </thead>
    <tbody>
        <tr id="cheeseburger.com">
	    <td class="editable ">cheeseburger.com</td>
	    <td><div class="deleteRow"></div></td>
	</tr>
    </tbody>
    <tfoot>
        <tr style="display:none;" class="template">
	    <td class="editable" style="">edit</td>
	    <td>
		<div class="deleteRow"></div>
	    </td>
	</tr>
	<tr>
	    <td></td>
	    <td>
	        <div class="addRow"></div>
	    </td>
	</tr>
    </tfoot>
</table>

Here is the Javascript that supports the tables. Once again my goal was to have to only write one Datatables Init function for all datatables. It may not cover some edge cases but it should work for majority. Read the comments to get details of what I did and why.

    $.add_field_edit_handlers = function(oTable){
        /*
             * Setup up the editable columns.
             * --The table must have an ID.
             * --The table must have a custom attribute of 'editURL' containing the url of
             *   where to send the edit data.
             * --The columns to be edited must have the class 'editable'
             * --The row containing the editable columns must have some sort of
             *   identifying information.
             */
        $('#' + oTable.attr('id') + ' td.editable').editable($(oTable).attr('editURL'), {
            "callback": function( sValue, y ) {
                /*
                 * Handle return from the server
                 */
                var aPos = $(oTable).dataTable().fnGetPosition( this );
                $(oTable).dataTable().fnUpdate( sValue, aPos[0], aPos[1] );
            },
            "submitdata": function ( value, settings ) {
                /*
                     * Sends to the server
                     */
                return {
                    "row_id": this.parentNode.getAttribute('id'),
                    "column": $(oTable).dataTable().fnGetPosition( this )[2]
                };
            }
        });
    }
    /**
     * Setup a generic editable datatable
     */
    $('table.editable').dataTable({
        "bPaginate": false,
        "bLengthChange": false,
        "bFilter": false,
        "bSort": false,
        "bInfo": false,
        "bAutoWidth": false,
        "fnInitComplete" : function(oSettings, json){
            var oTable = this;
            $.add_field_edit_handlers(oTable);
        }
    });
    /**
     * Add a click event handler to insert the hidden row template in the footer
     * into the tables body. This is sort of a pain in the ass due to the way that
     * the Datatables plugin works. You cant simply add your row. Datatables adds
     * rows by taking an array of cell content, not the cells themselves. This
     * means that our template row's cells lose their classes. So we have to extract
     * the classes and then add them back once Datatables.fnAddData() has added
     * the new row. swright 02-21-2012
     */
    $('.addRow').click(function(){
        // Get the ID of the clicked table
        var oTable = $(this).closest('table');
        // Something to hold the template row
        var template = new Array();
        // Something to hold the styles from each cell in the template row
        var td_class = new Array();
        /*
         * Iterate the TDs in the template row. Add the content for each cell to
         * the template array. Add the CSS class for each cell to the td_class array
         */
        $(oTable).find('tfoot tr.template td').each(function(){
            template.push($(this).html());
            if(typeof($(this).attr('class')) != "undefined"){
                td_class.push($(this).attr('class'));
            }
        });
        // Add the template array
        $(oTable).dataTable().fnAddData(template);
        /*
         * Iterate the new row's TDs and add the classes that we saved in the
         * td_class array.
         */
        $(oTable).find('tbody tr:last td').each(function(index, val){
            if(typeof(td_class[index]) != "undefined"){
                $(val).attr('class', td_class[index]);
            }
        });
        // Added the field edit handlers
        $.add_field_edit_handlers(oTable);
    });

Favorite Linux Tools and Other Stuff

Filed in Dev Tools | Linux Leave a comment

This is just a list of some useful Linux stuff I need to reference from time to time.

Linux Screen is an excellent tool for grouping multiple consoles into one SSH window.

 

Ever have Putty lockup on you? You probably hit CTRL-S while using Screen. Here is the solution.

MongoDB Training

Filed in Development | MongoDB Leave a comment

These are some notes from my recent MongoDB training session with 10gen’s Richard Kreuter.

Lack of Schema

MongoDB does not impose or require any schema for the documents you store in a collection. The application must enforce any schema requirements, for instance when inserting a user record you may require the presence of at least a username field. The application must validate this before writing the record. Its possible to add and subtract elements from the document as the application’s needs change over time. This is both good and bad. Compared to an RDMS adding columns is a snap, but your application must be able to deal with the fact that it may get documents in different formats from the same collection. An excellent way to deal with this is to use a version number field in your documents. The application will know what document version number its dealing with and you can add routines to upgrade any documents you find while doing other work such as reads, and or updates. Or you could just have a little worker program that upgrades documents to the newest specs in the background. The point is you have lots of flexibility but that comes with some management overhead.

Document Padding

Document padding is the idea of adding extra blank data to your documents. For instance if you have User document that contains an array of Roles that the User is assigned to. When store the document initially the User may only have one Role and so you store an array of one item. As the User gets more Roles the document’s array will grow. The problem is that the documents are stored on disk. If the document grows beyond the size allocated on the disk the document must be moved to a larger space. This is an expensive operation. A good strategy is to pad the Roles array to a reasonable size with empty values to reduce the possibility of disk relocation of the record.

To Join or not to Join

In an RDMS that has been normalized to contain no duplicate data you have to join your tables together in order to get a document. This means you dont have to worry about maintaining duplicate values. In MongoDB you generally want to store to documents as you would want to see them which means you may (probably will) have duplicate values. Take for instance the idea of a collection of IP addresses that contain domain information and a collection of domains that contain IP information. You would have both collections because you would want to index on different fields and quickly fetch data from both points of view but you would also have duplicate data. You also have the possibility that in between writing your domain info and then writing your IP info the DB dies in some ugly way. This would leave you in the bad position of having out of sync data. A good strategy to handle this is to create a third collection that holds a sort of “transaction”. Its not a transaction in the sense of an RDMS transaction, but I dont have a better term at the moment because my coffee has not kicked in yet. So what you do is create this third collection and store a document that describes what action you want to perform, add, update, or delete, the data you want to do it with, and a timestamp. Then your application can attempt to “play” the action as many times as it has to, hopefully once, to fulfill the original request. Once it completes successfully you remove the record from the “transaction” collection.

Replication and Sharding

To be clear, a replica set is a group of mongod processes that all contain the same document data whose purpose is to prevent data loss. At least one of the processes acts as a writeable server at any one time and is known as the primary node. In general you would run each replica on a separate piece of hardware. There’s not much point to having them reside on the same box excepting a development deployment and even then, VMs would be a better option. But failing that, each replica must have it’s own data directory, log file and unique tcp port to communicate on. Any modifications made to the replica set config file must be made on the primary node.

The OpLog

Every data manipulation query sent to a mongod process is collected in the op log. Once you have setup your replica sets you will see a collection in the local database called oplog. By default the oplog is 5% of the available disk space. However you can change this when starting mongod like so:

mongod --oplogSize 200 // in MB

So why would you want to do this? The OpLog is a capped collection which makes it work like queue. Once the collection gets to the cap size the oldest records are removed one by one as new records come in. Depending on the amount of write operations your database is handling and the speed at which the replicas can pick up those changes its possible, although unlikely, that your oplog would roll off stale data before the replicas had a chance to write the data. The replicas would no longer be able to sync after that point. A more likely scenario is that for some reason your replicas lose connectivity for some period of time that is greater than the period of time recorded in the oplog. When the replica comes back online it will not be able to sync. So its better to err on the side of a bigger oplog within reason.

Sharding

 (that joke is not as funny as you think)

Sharding is used to spread data and writing operations around. Its that simple. Well ok not really. Sharded clusters consists of several, at least 1, shards each of which is a replica set. I’ll say it again, a single shard is a replica set. There are some rules about shards that may or may not be intuitive given what you know about Mongo.

  1. In a sharded system every document in a collection must contain the same fields.
  2. You are required to have exactly 3 config servers that store the metadata and routing information for the cluster.
  3. You must have at least one but usually more mongos processes running. MongoS is the name of the binary not multiple mongo.
  4. This is what your application will connect to and it also does not have to reside on the database server. In fact I think its better if its resides on the application server.
  5. A shard key’s value is immutable! The only way to change the value is pull the document, make the change and then insert it as a new document a and delete the original.
  6. Shard key values dont have to be unique in a collection. This means that if you want to update a specific document you must include some other identifying field in addition to the shard key.
Mongos (n)
Shard 1 Shard 2 Shard 3
RS1
Primary
Secondary
Secondary
RS2
Primary
Secondary
Secondary
RS3
Primary
Secondary
Secondary

Following the replica set rules, each member of the replica sets should ideally reside on separate hardware. So in the example above you would have 9 physical pieces of hardware.

Picking a shard key is something you must consider carefully. While its possible to change a shard key in a running database its an incredibly painful process that will effectively require shutting down your database which is not easy in a production situation.

One reasonable strategy is to generate a hash and store that in the document as your shard key. Something else to watch out for are keys that are monotonic in nature. Because shards are split up in ranges based upon the values of the shard keys if you have a monotonic shard key you will end up always writing to one shard which means you lose write balancing in your cluster.

Assume your shard key is an integer and you have 3 shards. The shards will balance the number of records by splitting the data over the shards
based upon the values of the key.

Shard 1 Shard 2 Shard 3
key range: 1-10 key range: 11-20 key range: 21->infinity

So one of the shards is always going to contain the higher range of keys and because your key values are always increasing mongos is always going to write to that shard. At some point the data will split and balance but you will always be writing to one shard. So beware of monotonic keys.

This is an excellent reference source.

RabbitMQ, PHP, Centos5

Filed in Dev Tools | Development Leave a comment

Trying out RabbitMQ as a messaging system for modules written in different languages. The installation is a little bit tricky.  The target  is running in Virtual Box. I started with:

  • Centos 5.6 (64bit)
  • PHP 5.2.10
  • Rabbit MQ Server 2.6.1

The PHP module ampq is picky about which version of PHP it runs against. Centos 5 comes with PHP5.2 which ampq wont run compile with, So my first step was to upgrade PHP to the right version. Since I like to try and use yum for package management whenever possible I found a repo with the versions I was looking for. I added the repo by creating the following file:

/etc/yum.repo.d/webtatic.repo

And then adding the following content to it:

[webtatic]
name=Webtatic Repository
baseurl=http://repo.webtatic.com/yum/centos/5/x86_64/
gpgcheck=0

Once that is done you can then update the PHP version. I updated to the latest version that Webtatic had available which at the time was 5.3.8

yum update php*

The PHP update pooched my php.ini file and was incompatible with my Mongo module. The php.ini file no longer allows “#” as a comment marker anymore. To upgrade the Mongo module simply use PECL:

pecl upgrade mongo

Now you can finally install the ampq module:

pecl install amqp

Make sure to add a link to the amqp.so file

extension=amqp.so

MongoDB Sharding

Filed in Development | General Leave a comment

Today I had to create a MongoDB sharding setup on 4 VM servers.  One of the servers would be the primary shard and also contain the MongoS process and the MongoD configdb process. You can find out more about Mongo sharding here. There were some things that are not spelled out in the documentation and were not obvious to me so I figured I would list them here for reference.

Continue Reading

PHP class autoloader

Filed in Development | General Leave a comment

I have been working on a version of the PHP class autoloader. I have a config file that sets up the path information for the program. Generally you would want to include the config and the includes file in the entry point of the program. Continue Reading

Phantom JS on Centos5

Filed in Dev Tools | Development | General 1 Comment

I spent the last 3 hours jumping through burning hoops of Linux fun to get Phantom JS installed on my Centos5 (64) system running in Virtual Box. Continue Reading

,

MongoDB and Node.js

Filed in Dev Tools | General Comments Off

MongoDB and Node.js together is better than peanut butter and chocolate. In order to use MongoDB with Node.js you need to install the mongodb module. To do this use the Node.js package manager or npm for short. I had to install that separately, but its quite simple: http://npmjs.org/ to do. Continue Reading

,

TOP