This site includes Projects (School coursework, work projects, independent projects, and freelance work) and my resume. This also serves as a place to post code and other programming-related information that I have found useful.

I also offer professional web development services for individual and small businesses.

Creating a Table inside a Form in Drupal 7

Exercises result

Create your module with info file. I named mine ac_exercise.module. Replace anything with ac_exercise with the name of your module
Here's my ac_exercise.info file:

name = Exercise
description = Exercise (ac_exercise)
core = 7.x
package = AC Modules

Here is my ac_exercise.module file:

<?php

function ac_exercise_menu()
{
$items['health/exercise'] = array(
'page callback' => 'ac_exercise',
'access arguments' => array('view exericse'),
'title' => 'Exercise',
'description' => 'Exercise',
'weight' => 2,
'type' => MENU_CALLBACK,
);

return $items;
}

/**
* Implements hook_perm().
*/
function ac_exercise_permission()
{
return array(
"view exercise" => array("title" => "View Exercise"),
"modify exercise" => array("title" => "Modify Exercise"),
);
}

function ac_exercise()
{
return drupal_get_form("ac_exercise_modify_form");
}

function ac_exercise_modify_form($form, &$form_state)
{
//TODO: Make this dynamic
$obj = new stdClass();
$obj->id = 1;
$obj->name = "Lat Pulldown";
$obj->weight = 50;
$obj->reps = 10;
$obj->sets = 3;

$obj2 = new stdClass();
$obj2->id = 2;
$obj2->name = "Mid Row";
$obj2->weight = 20;
$obj2->reps = 8;
$obj2->sets = 4;

$records = array($obj, $obj2);
//End of variables

$form['exercises'] = array(
'#type' => 'fieldset',
'#title' => t('Exercises'),
'#theme' => 'ac_exercise_exercises',
);

foreach ($records as $record)
{
$form['exercises']['exercises_name_' . $record->id] = array(
'#type' => 'textfield',
'#value' => $record->name,
'#size' => 20,
);

$form['exercises']['exercises_weight_' . $record->id] = array(
'#type' => 'textfield',
'#value' => $record->weight,
'#size' => 3,
);

$form['exercises']['exercises_reps_' . $record->id] = array(
'#type' => 'textfield',
'#value' => $record->reps,
'#size' => 3,
);

$form['exercises']['exercises_sets_' . $record->id] = array(
'#type' => 'textfield',
'#value' => $record->sets,
'#size' => 3,
);
}

return $form;
}

function ac_exercise_theme()
{
return array('ac_exercise_exercises' => array('render element' => 'form'),);
}

function theme_ac_exercise_exercises($variables)
{
$form = $variables['form'];
$rows = array();

for ($i = 1; $i <= 2; $i++)
{

$row = array();
$row[] = drupal_render($form['exercises_name_' . $i]);
$row[] = drupal_render($form['exercises_weight_' . $i]);
$row[] = drupal_render($form['exercises_reps_' . $i]);
$row[] = drupal_render($form['exercises_sets_' . $i]);
$rows[] = array('data' => $row, 'id' => 'exercise_' . $i);
}
$header = array(t('Exercise'), t('Weight'), t('Reps'), t('sets'));
$output = drupal_render_children($form);
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'id' => 'exercises_table', 'class' => 'form-item'));

return $output;
}

Ordering mixed (alphanumeric) results in mysql

I had a pretty complicated query that produced a resultset similar to the following:

tid name
20259 8"x10"
20294 10"x20"
20574 5.5"x14"
20581 20"x20"
20350 16"x20"

I wanted to return the results in order of the name so basically the smallest sizes would be shown first.

Here is a simplified query of what I did to achieve what I wanted:

SELECT tid, name
FROM table
ORDER BY name * 1, name

Now I get this resultset:

tid name
20574 5.5"x14"
20259 8"x10"
20294 10"x20"
20350 16"x20"
20581 20"x20"
Tags: 

Getting the function that called your function in Flex

I wanted to see what functions were calling this particular function because they shouldn’t have been when using debug mode.

public static function getUrlParamaters():Dictionary
{
  if (Globals.DEBUG == true)
  {
   trace("Warning: getUrlParamaters() was called during debug and it should not have been.");
   trace(new Error().getStackTrace());
  }
  //more code follows…
}

Scope is important!

After many years of using Javascript, I finally realized the importance of variable scope.
My code consisted of:

function matte_design_change(cid, selected_type, x, y, opening_width, opening_height)
{
//more code...
size = $(el).find("size");
width = size.attr("width") * ppi;
height = size.attr("height") * ppi;
//more code
}

What was happening was that the width and height were global variables and being set to something else somewhere else in the code. All I had to do to fix this issue was add var before these variables to make them local to that function.

function matte_design_change(cid, selected_type, x, y, opening_width, opening_height)
{
//more code...
var size = $(el).find("size");
var width = size.attr("width") * ppi;
var height = size.attr("height") * ppi;
//more code
}

See JavaScript Variable Scope and Hoisting Explained

Tags: 

How to generate a Google Maps API key for DEBUGGING only (Android)

  • Locate the path to the keystore
    • In Eclipse, navigate to Window | Preferences | Android | Build
    • Under "Default debug keystore" you will find the path to the keystore
  • Open a command prompt
  • cd C:\Program Files\Java\jre6\bin (or wherever your java installation is)
  • Run the command: keytool -list -alias androiddebugkey -keystore (path to keystore)\debug.keystore -storepass android -keypass android
  • It should return something like:
    androiddebugkey, Sep 2, 2010, PrivateKeyEntry,
    Certificate fingerprint (MD5): XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
  • Go to http://code.google.com/android/maps-api-signup.html and paste your certificate fingerprint and check the box to accept the terms (if you accept them of course)
  • If all goes well, it will take you go a page that says: Thank you for signing up for an Android Maps API key! Your key is: (your key)
See also:
Tags: 

Pages

randomness