<?xml version="1.0" encoding="US-ASCII" ?>
<?xml-stylesheet type="text/xsl" href="xslt.xsl"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Javod's Blog</title>
        <description>A programmer relating his adventures with coding, and the politics of technology</description>
        <link>http://www.javod.com/blog/</link>
        <atom:link href="http://www.javod.com/blog/atomblog.php" rel="self" type="application/rss+xml" />
	<image>
	<url>http://www.javod.com/blog/images/rss.jpg</url>
	<title>Javod's Blog</title>
	<link>http://www.javod.com/blog/</link>
	</image>

<item><title>How to add your personal private/protected Twitter account to Drupal</title>
	<description>&lt;p&gt;(Note: In this post I use the terms private and protected interchangeably.)&lt;/p&gt;&lt;p&gt;There are times you may want to have your protected Tweets available on your site. Perhaps protected Tweets are available to your members but not necessarily the world at large. Non-private accounts are easy enough to pull: These feeds are easily accessible using the &lt;a href=&quot;https://dev.twitter.com/docs/api&quot;&gt;Rest API&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;However, to access protected accounts we must create a Drupal module that authenticates through OAuth. Let's go through this process step by step.&lt;/p&gt;&lt;p&gt;1) First, in Drupal, create a new Content Type.&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;&lt;strong&gt;Name:&lt;/strong&gt; Tweet &lt;br /&gt;&lt;strong&gt;Type:&lt;/strong&gt; tweet &lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt; This content type pulls our protected tweets from our twitter account.&lt;/p&gt;&lt;p&gt;2) Next, we need to create a twitter app:&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;a) Go to &lt;a href=&quot;https://dev.twitter.com/&quot;&gt;dev.twitter.com&lt;/a&gt;&lt;br /&gt;b) Sign in using the protected twitter account you will be using.&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;&lt;img src=&quot;/blog/images/tw1.jpg&quot; alt=&quot;&quot; width=&quot;600&quot; height=&quot;400&quot; /&gt;&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;c) Click on Create an app.&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;&lt;img src=&quot;/blog/images/tw2.jpg&quot; alt=&quot;&quot; width=&quot;600&quot; height=&quot;400&quot; /&gt;&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;d) Fill in your app info, agree to the TOS, and submit.&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;&lt;img src=&quot;/blog/images/tw3.jpg&quot; alt=&quot;&quot; width=&quot;600&quot; height=&quot;400&quot; /&gt;&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;e) Go to the details tab for your newly created app and make note of the highlighted fields below. (Consumer Key, Consumer Secret, Access Token, Access Secret.)&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;&lt;img src=&quot;/blog/images/tw4.jpg&quot; alt=&quot;&quot; width=&quot;532&quot; height=&quot;241&quot; /&gt;&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;&lt;img src=&quot;/blog/images/tw5.1.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;&lt;p style=&quot;padding-left: 30px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;3) Now we need a way to authenticate our app with our soon to be created module. We must use the OAuth method, and we have the option of writing our own OAuth validator, or using the wonderful &lt;a href=&quot;http://classes.verkoyen.eu/twitter_oauth&quot;&gt;Twitter with OAuth class &lt;/a&gt;which does 99% of the work for us (As of this post the current version is 2.1.2). The rest of this tutorial assumes you have downloaded the class, but if you're a purist and want to write your own, have at it!&lt;/p&gt;&lt;p&gt;4) Unzip the downloaded file and inside should be a file named '&lt;strong&gt;twitter.php&lt;/strong&gt;'. We will include this file in our module.&lt;/p&gt;&lt;p&gt;5) Now we will create our module. Inside your Drupal's modules folder, create a new folder called '&lt;strong&gt;twitter_private&lt;/strong&gt;'.&lt;/p&gt;&lt;p&gt;6) Inside this new folder create two files: '&lt;strong&gt;twitter_private.info&lt;/strong&gt;' and '&lt;strong&gt;twitter_private.module&lt;/strong&gt;' files.&lt;/p&gt;&lt;p&gt;7) Make sure to drop the '&lt;strong&gt;twitter.php&lt;/strong&gt;' file into the '&lt;strong&gt;twitter_private&lt;/strong&gt;' folder as well. You should now have three files in the folder.&lt;/p&gt;

&lt;p&gt;8) Your info file should look something like this:&lt;/p&gt;
&lt;pre class=&quot;brush: php&quot;&gt;
; $Id$
name = Private Twitter App 
description = Retrieves @myaccount tweets for inclusion in site.
core = 6.x
&lt;/pre&gt; 

&lt;p&gt;9) Your module file should look something like this (Replace all ALL-CAPS variables with your info):&lt;/p&gt;
&lt;pre class=&quot;brush: php&quot;&gt;
// We're creating a cron hook that will check the tweets. 
// This will check every time you have a cron job set to run.

function twitter_pivate_cron(){ 
    // require the twitter class
    require_once 'twitter.php';
    
    // create instance MAKE SURE to replace the Consumer key 
    // and Consumer Secret with your settings
    $twitter = new Twitter('CONSUMER_KEY', 'CONSUMER_SECRET');
    
    // set tokens MAKE SURE to replace token and secret with your settings
    $twitter-&gt;setOAuthToken('ACCESS_TOKEN');
    $twitter-&gt;setOAuthTokenSecret('ACCESS_SECRET');
    
    // get users timeline, $count being the number of tweets to retrieve 
    // MAKE SURE to replace the screenName with your Twitter account name 
    //(do not include @ symbol)

    $response = $twitter-&gt;statusesUserTimeline($userId = null, 
                          $screenName = 'YOUR_TWITTER_ACCOUNT_NAME', 
                          $sinceId = null, 
                          $maxId = null, 
                          $count = 10, 
                          $page = null, 
                          $trimUser = false, 
                          $includeRts = false, 
                          $includeEntities = false);
    
    
    // Retrieve the 10 most recent tweets in the node table 
    // and place in title array
    $q = db_query(&quot;SELECT title FROM node WHERE type='tweet' 
                           ORDER BY nid DESC LIMIT 10&quot;);
    while($r = mysql_fetch_assoc($q)){
        $title[] = $r['title'];
    }
    
    // search 10 most recent tweets on twitter 
    // and if it doesn't exist in node table, insert
    foreach($response as $r){
        foreach($r as $k=&gt;$v){
            if($k == 'text'){
                if(!in_array($v, $title)){
                    $node = new stdClass();
                    $node-&gt;title = &quot;$v&quot;;
                    $node-&gt;type = 'tweet';
                    $node-&gt;created = time();
                    $node-&gt;changed = $node-&gt;created;
                    node_save($node);

                }
            }
        }
    }
}
&lt;/pre&gt;

&lt;p&gt;10) Now activate the module in your Drupal admin panel, run the cron manually to get started, and you are all set. Just figure out how you would like to use the tweet content type (you can create a new block, or have it feed into a page, or whatever you'd like)&lt;/p&gt;</description>
	<link>http://www.javod.com/blog/how-to-add-your-personal-private-protected-twitter-account-to-drupal</link>
	<comments>http://www.javod.com/blog/how-to-add-your-personal-private-protected-twitter-account-to-drupal#comments</comments>
	<guid>http://www.javod.com/blog/how-to-add-your-personal-private-protected-twitter-account-to-drupal</guid>
	<pubDate>Wed, 28 Dec 2011 13:02:30 -0700</pubDate></item>

<item><title>Using the Firefox Tilt plugin for an unconventional purpose</title>
	<description>&lt;p&gt;
    &lt;a href=&quot;http://blog.mozilla.com/tilt/&quot;&gt;Tilt&lt;/a&gt; is self described as a &quot;Firefox extension focused on creating a 3D visualization of a webpage, drawn using WebGL. Since the DOM is essentially a tree-like representation of a document, this tool layers each node based on the nesting in the tree, creating stacks of elements, each having a corresponding depth and being textured according to the webpage rendering.&quot;
&lt;/p&gt;
&lt;p&gt;
    The plugin is pretty amazing, and it does help find nested elements very quickly, however there is a novelty to it that seems to wear out after &quot;tilting&quot; a few websites.
&lt;/p&gt;
&lt;p&gt;
   After playing with Tilt, it occurred to me that there was potential for 3D modeling that could be added to a website. 
&lt;/p&gt;
&lt;p&gt;
    &lt;div style=&quot;text-align: center&quot;&gt;&lt;a href=&quot;http://javod.com/blog/files/tilt_building.php&quot;&gt;&lt;img src=&quot;images/willis_web.jpg&quot; alt=&quot;Wills Website&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
    &lt;a href=&quot;http://javod.com/blog/files/tilt_building.php&quot;&gt;The website above&lt;/a&gt; is a very simple example of how one might go about this. I thought it would be neat to have a page about a famous skyscraper, and when the Tilt plugin was applied, the actual skyscraper would be built.
&lt;/p&gt;
&lt;p&gt;
    &lt;div style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;images/willis_tilt.jpg&quot; alt=&quot;Willis Website viewed with Tilt&quot; border=&quot;0&quot; /&gt;&lt;/div&gt;
     I've done the calculations to make sure that the skyscraper is indeed to scale, so if you are viewing it you will have to zoom out all the way to get a good view. A cool little side-project, and a fun easter-egg.
&lt;/p&gt;
&lt;p&gt; 
    I don't know how practical this would be for real modeling, but I could see how an architectural firm might use this technique as a simple &quot;wow&quot; factor in a pitch.
&lt;/p&gt;</description>
	<link>http://www.javod.com/blog/using-the-firefox-tilt-plugin-for-an-unconventional-purpose</link>
	<comments>http://www.javod.com/blog/using-the-firefox-tilt-plugin-for-an-unconventional-purpose#comments</comments>
	<guid>http://www.javod.com/blog/using-the-firefox-tilt-plugin-for-an-unconventional-purpose</guid>
	<pubDate>2011-12-06 00:00:00</pubDate></item>

<item><title>Drupal 6: Running Batch via Cron</title>
	<description>&lt;p&gt;Looking through the Drupal documentation, a person is led to believe that automating a Batch script is tantamount to moving Mount Fuji 10 feet to the left with a wooden spoon. The general consensus seems to be that all Batch scripts should be converted to use the Queue API. Sometimes this is an acceptable solution, but when you're running a very large script that makes extensive use of the Batch $context variable, it becomes a daunting task.&lt;/p&gt;

&lt;p&gt;The big issue (or at least the issue I ran into) with Batch and cron, is that the Batch API was really written to be used in conjunction with the browser, so there are calls made to update the progress bar that just don’t jive when running in cron.&lt;/p&gt;

&lt;p&gt;The solution that worked for me was a bit of a hack, but only a small one. If we look over the batch_process() documentation, there’s a telling bit of information: &quot;Unless the batch has been marked with 'progressive' = FALSE, the function issues a drupal_goto and thus ends page execution.&quot; That sounded positive, and from what I could tell it bypasses the progress bar and executes the batch in one pass.&lt;/p&gt;

&lt;p&gt;Now the problem is that even though we are given this information, there’s no parameter to change this variable. It looks like an oversight by the developers. Instead of hacking the core though, what we can do is create a reference to batch_get and turn off the progressive option.&lt;/p&gt;

&lt;pre class=&quot;brush: php&quot;&gt;
// create a reference to batch_get()
// this is called directly in the core batch_process() function
$batch =&amp; batch_get();
// Using the reference, we turn progressive off
// which prevents the redirect to the standard Batch API progress bar
$batch['progressive'] = FALSE;
// Because we are not using the form to trigger the batch, we run batch_process('')
batch_process('');
&lt;/pre&gt;

&lt;p&gt;So let’s take a look at how this would work:&lt;/p&gt;

&lt;pre class=&quot;brush: php&quot;&gt;
hook_cron(){
    hook_my_function();
}
hook_my_function(){
    batch_set(array(
      'title' =&gt; My Title',
      'operations' =&gt; array(
        array(‘hook_another_function_to_run’, array($info))
      ),
      'progress_message' =&gt; 'Processing...',
    ));
   
    $batch =&amp; batch_get();
    $batch['progressive'] = FALSE;
    batch_process('');
}
&lt;/pre&gt;

&lt;p&gt;Now there may be some issues with this implementation that I am unaware of, but I am running a rather large Batch script and have yet to come across any.&lt;/p&gt;

&lt;p&gt;Hope this helps someone!&lt;/p&gt;
</description>
	<link>http://www.javod.com/blog/drupal-6-running-batch-via-cron</link>
	<comments>http://www.javod.com/blog/drupal-6-running-batch-via-cron#comments</comments>
	<guid>http://www.javod.com/blog/drupal-6-running-batch-via-cron</guid>
	<pubDate>Wed, 11 Nov 2011 18:52:30 -0700</pubDate></item>

<item><title>jQuery: Disable right click and drag on images</title>
	<description>&lt;p&gt;Sometimes you get a client that just wants to do what they want to do no matter the reasons they shouldn't.&lt;p&gt;
&lt;p&gt;In the case of disabling right click the short answer is: Don't.&lt;/p&gt; 
&lt;p&gt;The long answer is there is no way to prevent someone from taking images off your site. You can slightly thwart users, but it is against the very principles of the way the internet works, and is considered bad practice. Typically only websites that are either unprofessional or shady use these techniques.&lt;/p&gt;
&lt;p&gt;Now, with that, sometimes you'll get a person who says, &quot;just do it anyway.&quot; So here is some jQuery to make this an easy job for you.&lt;/p&gt;

&lt;pre class=&quot;brush: javascript&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

    $(document).ready(function(){

// Here we are getting all images and turning off the context menu. 
// return false is the same as calling .preventDefault() and .stopPropagation()
        $('img').bind(&quot;contextmenu&quot;,function(e){
            return false;
        });

// Here we disable default behaviors for mousedown which include the drag options.
        $('img').bind(&quot;mousedown&quot;,function(e){
            return false;
        });
    });

&lt;/script&gt;
&lt;/pre&gt;</description>
	<link>http://www.javod.com/blog/jquery-disable-right-click-and-drag-on-images</link>
	<comments>http://www.javod.com/blog/jquery-disable-right-click-and-drag-on-images#comments</comments>
	<guid>http://www.javod.com/blog/jquery-disable-right-click-and-drag-on-images</guid>
	<pubDate>Wed, 17 Nov 2010 10:46:31 -0700</pubDate></item>

<item><title>Dante's Theme - Piano Cover FMA</title>
	<description>Something a little different: A video of me playing Dante's Theme from Fullmetal Alchemist.

&lt;object width=&quot;640&quot; height=&quot;385&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/c_9h7lOXVSw?fs=1&amp;amp;hl=en_US&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;http://www.youtube.com/v/c_9h7lOXVSw?fs=1&amp;amp;hl=en_US&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;640&quot; height=&quot;385&quot;&gt;&lt;/embed&gt;&lt;/object&gt;</description>
	<link>http://www.javod.com/blog/dantes-theme-piano-cover-fma</link>
	<comments>http://www.javod.com/blog/dantes-theme-piano-cover-fma#comments</comments>
	<guid>http://www.javod.com/blog/dantes-theme-piano-cover-fma</guid>
	<pubDate></pubDate></item>

<item><title>zeroclipboard: Get javascript events firing after AJAX request</title>
	<description>&lt;p&gt;An interesting problem I came across recently was trying to get &lt;a href=&quot;http://code.google.com/p/zeroclipboard/&quot;&gt;Zero Clipboard&lt;/a&gt; to work in an AJAX loaded div. Zero Clipboard is pretty much the only way to copy text to the user's clipboard that works across browsers. There is no native way to do this, so it floats an invisible movie on top of a DOM element. Yes, your users need to have Flash installed for this to work.
&lt;/p&gt;
&lt;p&gt;The issue is as follows: &lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;We need zeroclipboard available on a page that is loaded via ajax inside a div.&lt;/li&gt;
  &lt;li&gt;Javascript events are not bound in an ajax call unless specifically loaded by an onclick, onload etc...&lt;/li&gt;
  &lt;li&gt;The scripts themselves need to exist outside of the ajax loaded page to be loaded during page load.&lt;br /&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;At the time of this writing zeroclipboard is on version 1.0.7&lt;/p&gt;
&lt;p&gt;As the documentation notes, the ZeroClipboard.swf file  by default  is sought for in the same directory as the webpage, and this tutorial assumes that it is. &lt;/p&gt;
&lt;p&gt;Let's say we have two pages: index.html and ajaxload.html&lt;/p&gt;
&lt;p&gt;The default example for zeroclipboard:&lt;/p&gt;
&lt;pre class=&quot;brush: html&quot;&gt;
&amp;lt;html&gt;
	&amp;lt;head&gt;
		&amp;lt;style type=&quot;text/css&quot;&gt;
			#d_clip_button {
				text-align:center; 
				border:1px solid black; 
				background-color:#ccc; 
				margin:10px; padding:10px; 
			}
			#d_clip_button.hover { background-color:#eee; }
			#d_clip_button.active { background-color:#aaa; }
		&amp;lt;/style&gt;
	&amp;lt;/head&gt;
	&amp;lt;body&gt;
		&amp;lt;script type=&quot;text/javascript&quot; src=&quot;ZeroClipboard.js&quot;&gt;&amp;lt;/script&gt;
                
		Copy to Clipboard: &amp;lt;input type=&quot;text&quot; id=&quot;clip_text&quot; size=&quot;40&quot; value=&quot;Copy me!&quot;/&gt;
        
		&amp;lt;div id=&quot;d_clip_button&quot;&gt;Copy To Clipboard&amp;lt;/div&gt;
        
		&amp;lt;script language=&quot;JavaScript&quot;&gt;
			var clip = new ZeroClipboard.Client();
                        
			clip.setText( '' ); // will be set later on mouseDown
			clip.setHandCursor( true );
			clip.setCSSEffects( true );
                        
			clip.addEventListener( 'load', function(client) {
				// alert( &quot;movie is loaded&quot; );
			} );
                        
			clip.addEventListener( 'complete', function(client, text) {
				alert(&quot;Copied text to clipboard: &quot; + text );
			} );
                        
			clip.addEventListener( 'mouseOver', function(client) {
				// alert(&quot;mouse over&quot;); 
			} );
                        
			clip.addEventListener( 'mouseOut', function(client) { 
				// alert(&quot;mouse out&quot;); 
			} );
                        
			clip.addEventListener( 'mouseDown', function(client) { 
				// set text to copy here
				clip.setText( document.getElementById('clip_text').value );
                                
				// alert(&quot;mouse down&quot;); 
			} );
                        
			clip.addEventListener( 'mouseUp', function(client) { 
				// alert(&quot;mouse up&quot;); 
			} );
                        
			clip.glue( 'd_clip_button' );
		&amp;lt;/script&gt;
	&amp;lt;/body&gt;
&amp;lt;/html&gt;
&lt;/pre&gt;
&lt;p&gt;For our purposes we're going to make a couple of changes.&lt;br /&gt;
index.html:&lt;/p&gt;
&lt;pre class=&quot;brush: html&quot;&gt;
&amp;lt;html&gt;
	&amp;lt;head&gt;
		&amp;lt;style type=&quot;text/css&quot;&gt;
			#d_clip_button {
				text-align:center; 
				border:1px solid black; 
				background-color:#ccc; 
				margin:10px; padding:10px; 
			}
			#d_clip_button.hover { background-color:#eee; }
			#d_clip_button.active { background-color:#aaa; }
		&amp;lt;/style&gt;

       &amp;lt;!-- We're moving the main javascript file to the head section --&amp;gt;
       &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;ZeroClipboard.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
		&amp;lt;!-- We're also taking the following code and wrapping it in a function to call later --&amp;gt;
		&amp;lt;script language=&amp;quot;JavaScript&amp;quot;&amp;gt;
		function clipit(){
			var clip = new ZeroClipboard.Client();
                        
			clip.setText( '' ); // will be set later on mouseDown
			clip.setHandCursor( true );
			clip.setCSSEffects( true );
                        
			clip.addEventListener( 'load', function(client) {
				// alert( &amp;quot;movie is loaded&amp;quot; );
			} );
                        
			clip.addEventListener( 'complete', function(client, text) {
				alert(&amp;quot;Copied text to clipboard: &amp;quot; + text );
			} );
                        
			clip.addEventListener( 'mouseOver', function(client) {
				// alert(&amp;quot;mouse over&amp;quot;); 
			} );
                        
			clip.addEventListener( 'mouseOut', function(client) { 
				// alert(&amp;quot;mouse out&amp;quot;); 
			} );
                        
			clip.addEventListener( 'mouseDown', function(client) { 
				// set text to copy here
				clip.setText( document.getElementById('clip_text').value );
                                
				// alert(&amp;quot;mouse down&amp;quot;); 
			} );
                        
			clip.addEventListener( 'mouseUp', function(client) { 
				// alert(&amp;quot;mouse up&amp;quot;); 
			} );
                        
			clip.glue( 'd_clip_button' );
		}
		&amp;lt;/script&amp;gt;

	&amp;lt;/head&gt;
	&amp;lt;body&gt;
		&amp;lt;!-- We're adding the div where we will load our ajax file --&amp;gt;
		&amp;lt;div id=&amp;quot;loadPageHere&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;	
	&amp;lt;/body&gt;
&amp;lt;/html&gt;
&lt;/pre&gt;

&lt;p&gt;ajaxload.html:&lt;/p&gt;
&lt;pre class=&quot;brush: html&quot;&gt;
Copy to Clipboard: &amp;lt;input type=&quot;text&quot; id=&quot;clip_text&quot; size=&quot;40&quot; value=&quot;Copy me!&quot;/&gt;
&amp;lt;div id=&quot;d_clip_button&quot;&gt;Copy To Clipboard&amp;lt;/div&gt;

&amp;lt;!-- Here's the tricky part --&amp;gt;
&amp;lt;!-- We need to load our function after the ajax call, but we can't use a body tag, and divs don't allow the onload attribute --&amp;gt;
&amp;lt;!-- The hack here is to use a 1px x 1px image  and use the onload function available in the img tag to load our function --&amp;gt;
&amp;lt;img src=&amp;quot;blank.gif&amp;quot; onload=&amp;quot;clipit();&amp;quot; /&amp;gt;
&lt;/pre&gt;
&lt;p&gt;So that's the way to use zeroclipboard in an AJAX call. Please note that I did not include the ajax code that actually loads ajaxload.php in the index's div. I assume if you're having this problem you've probably  already come that far. If you do need help with that though, just ask!&lt;/p&gt;
&lt;p&gt;If you have any questions, problems or suggestions feel free to leave a comment.&lt;/p&gt;</description>
	<link>http://www.javod.com/blog/zeroclipboard--get-javascript-events-firing-after-ajax-request</link>
	<comments>http://www.javod.com/blog/zeroclipboard--get-javascript-events-firing-after-ajax-request#comments</comments>
	<guid>http://www.javod.com/blog/zeroclipboard--get-javascript-events-firing-after-ajax-request</guid>
	<pubDate>Tue, 25 May 2010 21:08:54 -0700</pubDate></item>

<item><title>The art of learning: How I want to be taught</title>
	<description>&lt;p&gt;
While I was at university, there was a professor in the Computer Science college who was known as incredibly difficult. Dr. D was unquestionably bright, having two doctorates, one in Mathematics and one in Computer Science. He knew his material, and while his Chinese accent was at times difficult to understand, it wasn't a major hindrance to learning the material.
&lt;/p&gt;
&lt;p&gt;
I had Dr. D for 2 classes: Discrete Mathematics, and Computer Science II. I had never worked so hard for a B in my life. Dr. D was not as some may imagine lacking in the spirit of teaching. Quite the contrary, he loved his job, and he cared and encouraged his students. He often complained that not enough students came to his office hours. Sometimes when our class needed a respite from the non-stop barrage of ideas that Dr. D issued forth, we would (and often did) get him talking about his research on number theory and the rest of the class period would be lost to tangential discussion.
&lt;/p&gt;
&lt;p&gt;
What made Dr. D so difficult was the way he taught us. He taught all his undergraduate classes as if we were graduate students. Instead of giving us concrete examples, we got lots of theory. Maybe I'm just not smart enough, but the bridge from theory to practice has always been difficult for me. The concept of mathematical induction seems easy enough, but when applying it to a problem, unless I've seen something similar, it becomes a major struggle. I understand the means behind the methods: Learn how to learn. That's all fine and dandy, but before I can learn to learn, I need to understand. 
&lt;/p&gt;
&lt;p&gt;
Mark Guzdial wrote an &lt;a href=&quot;http://cacm.acm.org/blogs/blog-cacm/45725-how-we-teach-introductory-computer-science-is-wrong/fulltext&quot;&gt;excellent article&lt;/a&gt; for the ACM discussing just this issue. He brings to light a 1985 paper which is very telling, and coincides with my own personal experiences:
&lt;/p&gt;
&lt;blockquote&gt;
The original 1985 Sweller and Cooper paper on worked examples had five studies with similar set-ups.  There are two groups of students, each of which is shown two worked-out algebra problems.  Our experimental group then gets eight more algebra problems, completely worked out. Our control group solves those eight more problems.  As you might imagine, the control group takes &lt;strong&gt;five times&lt;/strong&gt; as long to complete the eight problems than the experiment group takes to simply read them.  Both groups then get new problems to solve. &lt;strong&gt;The experimental group solves the problems in half the time and with fewer errors than the control group.&lt;/strong&gt; Not problem-solving leads to better problem-solving skills than those doing problem-solving. That's when Educational Psychologists began to question the idea that we should best teach problem-solving by having students solve problems.
&lt;/blockquote&gt;

&lt;p&gt;
Why then, if there is such a significant statistical difference, are teachers still insisting on teaching by theory alone? If seeing worked out problems has a better chance of teaching students how and why things work, then let's push that. I know that this certainly works for me. The more I see of a problem worked out, the more I begin to understand the mechanics of it, so when I do come across a problem that is slightly different, my understanding is greater, and my chances of solving are greater as well. This isn't to say that theory should never be taught, of course it should. Guzdial simply states, and I agree, that theory and problems without samples shouldn't be the way to start learning a subject.
&lt;/p&gt;</description>
	<link>http://www.javod.com/blog/the-art-of-learning--how-i-want-to-be-taught</link>
	<comments>http://www.javod.com/blog/the-art-of-learning--how-i-want-to-be-taught#comments</comments>
	<guid>http://www.javod.com/blog/the-art-of-learning--how-i-want-to-be-taught</guid>
	<pubDate>Sun, 28 Mar 2010 13:41:43 -0700</pubDate></item>

<item><title>Creating a horizontal drop-down menu with CSS</title>
	<description>There are a ton of examples on how to create vertical drop-down menus, but hardly any on how to create a completely horizontal drop-down menu. I messed around with this quite a bit until I got what I was looking for, and then, once again, I stripped it down to a minumum to make it easy to understand. Just wrap an unordered list with a div tag using id=&quot;hmenu&quot;.
&lt;br /&gt;&lt;br /&gt;
From there you can add your own css styles to give it a nice look.
&lt;br /&gt;&lt;br /&gt;
Following is the HTML and CSS code required to do it. 
&lt;br /&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.javod.com/blog/files/horizontal_menu_demo.html&quot;&gt;Demo of Horizontal Drop-Down Menu&lt;/a&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;
&amp;lt;div id=&quot;hmenu&quot;&gt;
&amp;lt;ul&gt;
	&amp;lt;li&gt;&amp;lt;a href=&quot;example.com&quot;&gt;Home&amp;lt;/a&gt;
		&amp;lt;ul&gt;
			&amp;lt;li&gt;&amp;lt;a href=&quot;example.com&quot;&gt;About Us&amp;lt;/a&gt;&amp;lt;/li&gt;
			&amp;lt;li&gt;&amp;lt;a href=&quot;example.net&quot;&gt;About Me&amp;lt;/a&gt;&amp;lt;/li&gt;
		&amp;lt;/ul&gt;
    &amp;lt;/li&gt;
    &amp;lt;li&gt;&amp;lt;a href=&quot;index.php&quot;&gt;MoBlog
    	&amp;lt;ul&gt;
        	&amp;lt;li&gt;&amp;lt;a href=&quot;example.com&quot;&gt;Today's Pics&amp;lt;/a&gt;&amp;lt;/li&gt;
            &amp;lt;li&gt;&amp;lt;a href=&quot;example.net&quot;&gt;Month's Pics&amp;lt;/a&gt;&amp;lt;/li&gt;
            &amp;lt;li&gt;&amp;lt;a href=&quot;example.org&quot;&gt;Year's Pics&amp;lt;/a&gt;&amp;lt;/li&gt;
        &amp;lt;/ul&gt;
    &amp;lt;/li&gt;
    &amp;lt;li&gt;&amp;lt;a href=&quot;example.com&quot;&gt;Quotes
    	&amp;lt;ul&gt;
        	&amp;lt;li&gt;&amp;lt;a href=&quot;example.com&quot;&gt;Funny&amp;lt;/a&gt;&amp;lt;/li&gt;
            &amp;lt;li&gt;&amp;lt;a href=&quot;example.org&quot;&gt;Serious&amp;lt;/a&gt;&amp;lt;/li&gt;
            &amp;lt;li&gt;&amp;lt;a href=&quot;example.net&quot;&gt;Introspective&amp;lt;/a&gt;&amp;lt;/li&gt;
        &amp;lt;/ul&gt;
    &amp;lt;/li&gt;
&amp;lt;/ul&gt;
&amp;lt;/div&gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;

&lt;pre class=&quot;brush: css&quot;&gt;
/* Written by: Javod Khalaj */

/* 	'list-style: none' removes the bullets, 
	margin and padding can be adjusted to desired quantities, but zero is a good starting point
	'width:100px' is used because otherwise any mouse-over interaction with the width of the page would cause the menu to display
*/
#hmenu ul {
	margin: 0px;
	padding: 0px;
	list-style: none;
	width:100px;
}

/*	line-height separates the main navigation a specified distance. 
	Otherwise the navigation will be very tight against each other.
	'position: relative' helps line up the second navigation next to the corresponding first navigation.
*/
#hmenu ul li {
	line-height:30px;
	position: relative;
	float:none;
	width:auto;
}

/*	'left: 100px' pushes the second ul structure (secondary navigation) 100px away from the main ul (main navigation).
	'display: none' removes the visiblity of the secondary navigation (The element will generate no box at all).
	'position: absolute' lines up the second navigation next to the corresponding first navigation.
	'width: 600px' is the width for the second navigation. If it is made too small, the text will wrap.  
*/
#hmenu ul li ul {
	position: absolute;
	left: 100px;
	top:0px;
	display: none;
	width:600px;
}

/* 	this will change the display from none to block.
	essentially this makes the secondary navigation visible on mouseover.
*/
#hmenu li:hover ul { 
	display: block; 
}

/*	'padding-left:20px' separates the secondary menu from running into each other
*/
#hmenu ul li ul li{
	padding-left:20px;
	margin:0px;
	float:left;
	width:auto;
	text-align: center;
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
	<link>http://www.javod.com/blog/creating-a-horizontal-drop-down-menu-with-css</link>
	<comments>http://www.javod.com/blog/creating-a-horizontal-drop-down-menu-with-css#comments</comments>
	<guid>http://www.javod.com/blog/creating-a-horizontal-drop-down-menu-with-css</guid>
	<pubDate>Sun, 13 Sep 2009 15:20:23 -0700</pubDate></item>

<item><title>Recent websites</title>
	<description>Here are a few simple websites I've worked on in the past month or so:&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;&lt;a href=&quot;http://www.brushcreekbulldogs.com/&quot;&gt;&lt;img src=&quot;http://javod.com/blog/images/web1.jpg&quot; alt=&quot;Brushcreek Bulldogs&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.rockingeboarding.com/&quot;&gt;&lt;img src=&quot;http://javod.com/blog/images/web2.jpg&quot; alt=&quot;Rocking E Boarding&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div align=&quot;center&quot;&gt;&lt;a href=&quot;http://www.yalepd.com/&quot;&gt;&lt;img src=&quot;http://javod.com/blog/images/web3.jpg&quot; alt=&quot;Yale PD&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://www.provalue.net/&quot;&gt;&lt;img src=&quot;http://javod.com/blog/images/web4.jpg&quot; alt=&quot;ProValue.net&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</description>
	<link>http://www.javod.com/blog/recent-websites</link>
	<comments>http://www.javod.com/blog/recent-websites#comments</comments>
	<guid>http://www.javod.com/blog/recent-websites</guid>
	<pubDate>Tue, 04 Aug 2009 21:38:01 -0700</pubDate></item>

<item><title>Sanitize PHP input for MySQL queries</title>
	<description>&lt;p&gt;Sanitizing data in PHP is nothing short of an art form. I love the language, don't get me wrong, and while some people rail (see &lt;a href=&quot;http://en.wikipedia.org/wiki/Ruby_on_Rails&quot;&gt;ruby&lt;/a&gt; ::wink wink::) against the non-conformity of naming conventions, and auto casting of variables as evidence of poor design, I think there's no better language for beginners to start producing viable code quickly.&lt;/p&gt;
&lt;p&gt;I wanted to present a simple easy to understand sanitizing function for PHP strings that will be inserted into a MySQL database. This particular function serves a very specific purpose: it escapes the user input, strips out html tags except for those we specify, and then attempts to find any malicious code within our allowed html tags.&lt;/p&gt;
&lt;p&gt;If any code is found that we don't want, we can either exit out, or insert some generic message into our database. I explain my reasons why I don't just simply strip out malicious code in the comments of the code block. Many of the sanitize functions you'll see online recommend using htmlentities() to remove the risk of malicious code running, and that's fine if you don't want to have any usable tags for an end user. Otherwise, it doesn't do us much good, because when we decode the entities, the scripts will remain.&lt;/p&gt;
&lt;pre class=&quot;brush: php&quot;&gt;

	// sanitize helps clean a given variable before it is passed to a mysql query, with allowable tags
	
	function sanitize($var){
		// First let's escape the content. Because we are using mysql_real_escape_string() 
		// we need to make sure that we santize our variable AFTER we have connected to 
		// our database. Otherwise we will get an error. We are prepending backslashes
		// to a certain subset of characters here.
		$var = mysql_real_escape_string($var); 
		
		// Let's strip out any tags we don't want, and leave the ones 
		// that are okay for the user to place in. (This call is yours to make)
		$var = strip_tags($var, '&amp;lt;p&amp;gt;&amp;lt;a&amp;gt;');
		
		// There's a weakness in strip_tags that we need to address. If we allow
		// any tags, there's a chance that a malicious user could use XSS to exploit 
		// the code. We search the string for malicious code and kill the input if 
		// found. Some people choose to strip the offending material and still insert, but
		// my thoughts on the subjet are: if someone is trying to inject XSS, why
		// would we want them to post anything? 

		if(preg_match(&quot;/(&amp;lt;.*?(javascript|script|style|onmouseover|onmousedown).*?&amp;gt;)/i&quot;, $var)){
        	$var = &quot;Illegal input, data removed&quot;;
			
			// Instead of 'return $var', we can also exit, preventing our script from running any further.
			// We simply uncomment the following line:
			// exit();
			return $var;

        }
		else{
        	return $var;
        }	
	}&lt;/pre&gt;
    &lt;p&gt;Let's take a quick look at the REGEX statement in preg_match() to see what we're doing.&lt;/p&gt;
&lt;pre class=&quot;brush: php&quot;&gt;
  /(&amp;lt;.*?(javascript|script|style|onmouseover|onmousedown).*?&amp;gt;)/i
&lt;/pre&gt;
&lt;p&gt;First, we're looking for a &amp;lt; in the submitted variable.&lt;br /&gt;
  Then, using .*? we basically ignore everything inside the tag UNLESS it contains javascript OR script OR style OR...&lt;br /&gt;
We ignore anything following those keywords, and check for a closing tag.&lt;br /&gt;
/i means that we're ignoring case. So if someone types JAVAscript of javaScRiPt, we don't care.
&lt;/p&gt;
&lt;p&gt;Let's look at an examle:&lt;/p&gt;
&lt;pre class=&quot;brush: php&quot;&gt;
	// Remember, we need to connect to our database first because we use mysql_real_escape_string().
	mysql_connect($host,$user,$pass) or die(&quot;Could not make a connection&quot;);
	mysql_select_db($database_name) or die(&quot;Could not select database&quot;); 	
	
	// In this example, we've saved our sanitize function in a separate file called sanitize.php
	include (&quot;sanitize.php&quot;);
	
	// We declare our first variable with offending code.
	$var1 = &quot;&amp;lt;a href=\&amp;quot;http://www.javod.com\&amp;quot; onmousedown=\&amp;quot;javascript:alert('XSS');\&amp;quot;&amp;gt;XSS Attack Alert!&amp;lt;/a&amp;gt;&quot;;
	
	// Our second variable 
	$var2=&quot;&amp;lt;a href=\&amp;quot;http://www.javod.com\&amp;quot;&amp;gt;No XSS here!&amp;lt;/a&amp;gt;&quot;;
	
	// Display our variables before sanitizing.
	echo &quot;$var1 - (var1 before sanitizing)&quot;;
	echo &quot;$var2 - (var2 before sanitizing)&quot;;
	
	// Display our variables after sanitizing.
	$var1 = sanitize($var1);	
	echo &quot;$var1 - (var1 after sanitizing)&quot;;
	
	$var2 = sanitize($var2);
	echo &quot;$var2 - (var2 after sanitizing)&quot;;&lt;/pre&gt;
 &lt;p&gt;This will output the following:&lt;/p&gt;
 &lt;blockquote&gt;
&lt;a href=&quot;http://www.javod.com&quot; onmousedown=&quot;javascript:alert('XSS');&quot;&gt;XSS Attack Alert!&lt;/a&gt; - (var1 before sanitizing)&lt;br /&gt;
&lt;a href=&quot;http://www.javod.com&quot;&gt;No XSS here!&lt;/a&gt; - (var2 before sanitizing)
 &lt;p&gt;Illegal input, data removed - (var1 after sanitizing)&lt;br /&gt;
   &lt;a href=&quot;http://www.javod.com&quot;&gt;No XSS here!&lt;/a&gt; - (var2 after sanitizing)&lt;/p&gt;   
&lt;/blockquote&gt;
&lt;p&gt;Is this impenetrable... ABSOLUTELY NOT! This function is a good start, and gives an idea of what we're needing to do, but by no means is it unbreakable. Once again, feel free to leave any questions or comments you have.&lt;/p&gt;</description>
	<link>http://www.javod.com/blog/sanitize-php-input-for-mysql-queries</link>
	<comments>http://www.javod.com/blog/sanitize-php-input-for-mysql-queries#comments</comments>
	<guid>http://www.javod.com/blog/sanitize-php-input-for-mysql-queries</guid>
	<pubDate>Mon, 06 Jul 2009 22:21:42 -0700</pubDate></item>

</channel></rss> 
