Easy way to create blocks programmatically?
For Drupal 7: 

Use hook_block_info and hook_block_view hooks in your custom module. hook_block_info defines the block. It will show up in admin > structure > blocks. *hook_block_view* displays the content. See examples below from the Drupal API.   

Example of hook_block_info, where two blocks are defined (titled Syndicate and Recent content):

    &lt;?php
function hook_block_info() {
  // This example comes from node.module.
  $blocks['syndicate'] = array(
    'info' =&gt; t('Syndicate'), 
    'cache' =&gt; DRUPAL_NO_CACHE,
  );

  $blocks['recent'] = array(
    'info' =&gt; t('Recent content'),
    // DRUPAL_CACHE_PER_ROLE will be assumed.
  );

  return $blocks;
}
?&gt;


Example of hook_block_view: 

&lt;?php
function hook_block_view($delta = '') {
  // This example is adapted from node.module.
  $block = array();

  switch ($delta) {
    case 'syndicate':
      $block['subject'] = t('Syndicate');
      $block['content'] = array(
        '#theme' =&gt; 'feed_icon', 
        '#url' =&gt; 'rss.xml', 
        '#title' =&gt; t('Syndicate'),
      );
      break;

    case 'recent':
      if (user_access('access content')) {
        $block['subject'] = t('Recent content');
        if ($nodes = node_get_recent(variable_get('node_recent_block_count', 10))) {
          $block['content'] = array(
            '#theme' =&gt; 'node_recent_block', 
            '#nodes' =&gt; $nodes,
          );
        }
        else {
          $block['content'] = t('No content available.');
        }
      }
      break;
  }
  return $block;
}
?&gt;


Refer to the Blocks API page on Drupal.org for full list of hooks. Drupal 6 is a little different. There is no hook_block_view hook; instead use hook_block to declare blocks.