How the internet is changing the classroom – math, science, physics, and history resources for students

I just watched a video about the Kahn academy, which is a project started by Sal Kahn a triple graduate from MIT and Harvard. The creator of Jquery, John Resig holds the position of Dean of Open Source. You can start to imagine where this is going, you get a top notch open source software that tracks your students, delivering statistics and metrics that can turn learning into a competitive sport. Remember, this is all done via the internet, effectively turning any computer into a ‘world class learning institution’. The video below was recorded for TED and explains the motivation behind the Kahn Academy, and gives you a quick overview of the features that are built into the software.

Help my grid’s remote sorting (remoteSort:true) is not working after moving to Extjs 4

It’s always the little things that seem to catch you by surprise! Here’s a new one that may pop up when migrating your application from extjs3 to extjs4, and it has to do with server side behavior, so it will not be apparent on the front end. It looks like remote sort which used to pass the parameters ‘sort’ and ‘dir’ to the server has been changed to pass the parameters in an array object with the name ‘sort’ just like this instead:

[{"property":"field_name","direction":"ASC"}]

If you would like to change the sort call to the same format as Extjs 3 in order to transfer your applications just set the following parameter, simpleSortMode:true, in the proxy of the store and it will revert to the ‘old’ way of passing the parameters.
My sample remotely sorted store

Remote_sort_store_example = new Ext.data.Store({
		model: ‘Remote_sort_store_’,
		remoteSort:true,
		pageSize:50, 
		proxy: {
			type: 'ajax',
			actionMethods: {
				create : 'POST',
				read   : 'POST',
				update : 'POST',
				destroy: 'POST'
			},
			simpleSortMode:true,			
			url: 'learnsomethings.com/somethings/',
			reader: {
				type: 'json',
				root: 'data',
				totalProperty: 'results'
			}
		},
		autoLoad: false
	});

A quick and dirty server side solution written in cold fusion is below, it’s your choice.


<cfset sort_array =  ListToArray(form.sort) />
<cfset sort = replaceNoCASE(sort_array[1], '[{"property":"', "", "all") />
<cfset sort = replaceNoCASE(sort, '"', "", "all") />

<cfset dir = replaceNoCASE(sort_array[2], '"direction":"', "", "all") />
<cfset dir = replaceNoCASE(dir, '"}]', "", "all") />

A borrowed collection of javascript string manipulation functions – all in one place

Capitalize the first letter of a string
The code:

String.prototype.capitalize = function() {     return this.charAt(0).toUpperCase() + this.slice(1); }

Example:

var abraham_lincoln_quote = 'how many legs does a dog have if you call the tail a leg? Four. Calling a tail a leg doesn't make it a leg.'
abraham_lincoln_quote.capitalize();

Add the ‘left’ function from sql that we all love and miss so much to javascript

The Code

String.prototype.left = function(n) {     return this.substring(0, n); }

Example:

Abraham_lincoln_quote.left(23); // get the 23 characters to the left of the string

Add the trim function to javascript
The Code

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/,''); }

Getting the bar series segment as well as category and value in an Extjs 4 stacked bar chart

The tricky part of the stacked bar chart is the ability to get the segment, category, and value back from the users’ interaction with the bar. Two out of three are easy, and covered well in the documentation, however, the third item, the segment of the category is a little more difficult to access. The following method below expands on my first post which was largely a hunch and needed further exploration to avoid any ‘hard coded’ values being used to determine the segment; fortunately this is a totally dynamic solution.

You will need a function for finding the index of an Array based on a value. I used the following function found on Kumar S’s blog [http://www.guyfromchennai.com/?p=26]….

Array.prototype.findIndex = function(value){
var ctr = "";
for (var i=0; i < this.length; i++) {
// use === to check for Matches. ie., identical (===), ;
if (this[i] == value) {
return i;
}
}
return ctr;
};
 

And Steve Hansell’s capitalization method. [http://stackoverflow.com/users/171490/steve-hansell]

String.prototype.capitalize = function() {     return this.charAt(0).toUpperCase() + this.slice(1); }

Now using the Extjs stacked bar chart example that can be found in the folder ‘examples/charts/’ when you download Extjs 4, so that we can all start on the same page implement the following steps to change this to a stacked bar with access to all of the elements in the chart, including segments.

You will notice that the axis code is the following:

axes: [{
                type: 'Numeric',
                position: 'bottom',
                fields: ['comedy', 'action', 'drama', 'thriller'],
                title: false,
                grid: true,
                label: {
                    renderer: function(v) {
                        return String(v).replace(/000000$/, 'M');
                    }
                },
                roundToDecimal: false
            }, {
                type: 'Category',
                position: 'left',
                fields: ['year'],
                title: false
            }],

Here you can see that the film genres are all in an array and placed inside the fields property of axis. The first step is to take the fields and place them in an array outside of the chart object so for this example we will insert the line below above the chart object.

var display_fields = ['comedy', 'action', 'drama', 'thriller'];

Next we will need an array to hold all of the colors that are generated when the chart is rendered, since they will match the legend and are easily accessible, this is the only sure way to determine what segment the users mouse is over without some challenging x,y calculations on the chart space itself. Of course, this array should have the same length as the display_fields array, so go ahead and place the code below under the array you just created.

var series_colors = new Array( display_fields.length );

No on to the series section of the code, you should see the same genre array in the series yField property, replace this with the display_field array. Now we need to add a listener that will fire after the chart is rendered and populate the array of colors with the colors that Ext has assigned to the segments of the bar. We will use the method getLegendColor() so that we don’t have to know or care what the color is beforehand. The code for this listener is below:

listeners: {
afterrender : function(){              
for ( i=0; i <= display_fields.length; i++ )
{             
                series_colors[i] = this.getLegendColor(i);                                                                                             
  }
                }
},

To gethe association between the segment name and the color just add the following function under the seriesColors array definition.

function return_segment(color){
        var tidx = series_colors.findIndex(color);
                                return display_fields[tidx];
}

Finally, we want to do something with the new functionality right? So we will display the segment name in the tooltip as follows:

                tips: {
                    trackMouse: true,
                    width: 165,
                    height: 48,
                    renderer: function(storeItem, item) {
                        this.update( '<b>' + return_segment(item.attr.fill).capitalize() + '</b> - ' + String(item.value[1] / 1000000) + ' M');
                    }
                }

Truth in advertising – predicting the future 30 seconds at a time.

Ok, there is some truth in all of the advertisements depicting future uses for products, even those product placement advertisements in show such as the Microsoft / Chevrolet heavy Hawaii 5-0 series. I recently came across a series of AT&T commercials from the early 90’s that highlighted their big ideas for the future of telecommunications, take a look and see if you can recognize anything that you take for granted on a daily basis.

The funny thing is the older you get the shorter times gets, let me explain, anyone in their 40s can appreciate the ‘brick’ phone, that was so heavy calling it mobile was somewhat of a stretch, yet when reminded it seems just like yesterday that it was the next big technological breakthrough. Even if there are no obvious uses to the technology in the ads that jump out at you at least they serve to educate us on the possibilities that exist.

Think about the things that you take for granted that didn’t exist even 5 years ago, 10 years ago, 15 years ago (aka be or before the internet).