Tuesday, November 3, 2009

Adobe Flex Day 4 Embedding Font

On day four of the flex 3, Embedding fonts tutorial, it asks you to try and embed a font. After trying several methods to get my truetype font to rotate 45 degrees, I was unable to get the font appear. Only after using embedAsCFF attribute did it finally work. Set it to false and the Compact Font Format is ignored. This has something to do with how Adobe Flex 4 renders text.

[Embed(source='c:/windows/fonts/Consola.ttf', fontName="fontConsola",
mimeType="application/x-font-truetype", embedAsCFF="false")]

Tuesday, September 1, 2009

Analysis of several ratings / popularity algorithms

Here's a great article on the math behind some rating, ranking, popularity algorithms.

How to Build a Popularity Algorithm You can be Proud of

Wednesday, July 29, 2009

Fun with jQuery Form Validate Plugin

Things to know about the jQuery form validation plugin

http://bassistance.de/jquery-plugins/jquery-plugin-validation/

1. When dealing with input text you just need to add 'class' => 'required' to
<input type="text" 'class' => 'required' name="username"/>

2. Then add this line to get the form to validate
<script>
$().ready(function() {
$("#formValidate").validate();
});
</script>

3. What to do about checkboxes and how to position your error messages:

The form validate will auto insert your error messages when dealing with text fields and other input types. However when you're validating across multiple items like a checkbox you often want to position the error message in in a specific area.

eg.
<input type="text"><label class="error"> // Is fine

<input type="checkbox" name="data[]" value="1"><label class="error">
<input type="checkbox" name="data[]" value="1">

// The above error is out of place.

We can specify a label and use the for attribute to state where we want the error message to always show up.

<label class="error" for="data[]" >Pleased select at least two types of spam.</label> // insert this code anywhere on the page where you want the error message to appear

The problem arises when we
i) label.error { display: block; } // This causes the above label to always appear on first load of the page cause it's not hidden. Other inputs are fine as the validate 'auto-inserts' the errors.

ii) label.error { display: none; } // Next we try this style to make the explicit label.error disappear on first page load, but a side effect occurs. This style is inserted into ALL label.errors

style="display: inline"

Every label.error now loses their block style and we have a formatting problem

Solution:
1) http://groups.google.com/group/jquery-en/browse_thread/thread/2d87de7f74021f1a

<label for="data[]" class="error" style="display: none !important; clear: both; padding-bottom: 5px;">Pleased select at least two types of spam.</label> // This causes the label to be displayed hidden on the first load, and puts it on a new line cause of the clear: both;

2) OR wrap the label in a
<div class="errorCheckBoxBox"><label for="data[]" class="error"></label></div>

with the style
.errorCheckBox label{
display: none;
}



A better solution as it doesn't need additional style tags.

Saturday, June 13, 2009

Getting xhost to work on linux fedora 11

By default Fedora doesn't allow X11 to receive tcp connections.

This means if you try and run applications on another computer and display the window on your own, it won't work.

Your IP is 192.168.100.100
The other computer is 192.168.200.200

The typical step for running an xhost session is

1) On your computer you use this command to allow them access:
xhost + 192.168.200.200

2) On the other computer this commands tells it where to display all new windows:
export DISPLAY=192.168.100.100:0.0

3) On the other computer you run an application.
gnome-terminal

Problem is you get this message on the other computer:
> Can not open display:

And the terminal window doesn't appear no your computer.

Solution:
Allow TCP connections to X11 and open up the port 6000 in the firewall.

1) Edit /etc/gdm/gdm.schemas

2) Change

security/DisallowTCP
b
false


from true to false

3) In your firewall allow port 6000

4) Log out and log back to restart gdm

5) Now try the xhost commands from above

Wednesday, April 15, 2009

Dynamically pick a database in cakephp.

While doing some research into sharding and cakephp I was looking for a way to change a model's database connection.

The docs specify in your models you can use:
var $useDbConfig = 'default';
which will find a matching variable in DATABASE_CONFIG and use the connection settings.

in database.php
class DATABASE_CONFIG {
var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'port' => '',
'login' => 'myuser',
'password' => 'yeahright',
'database' => 'mycake',
'schema' => '',
'prefix' => '',
'encoding' => ''
);
...
}

Note: Difference between Sharding and Partitioning is shards resides on different servers. However both separate data depending on some field or attribute.

So to make this dynamic you start in bootstrap.php and create a hashing alg like this to separate your data:
$shardId = $id % 10;
$shardHostArray = array(5 => '192.168.0.25');

Configure::write('shard.host', $shardHostArray[5]);
or a
define('SHARDHOST', $shardHostArray[5]);
The next change you make is in database.php.

Add a constructor to class DATABASE_CONFIG
 public function __construct()
{
$this->shard = $this->default;
$this->shard['host'] = SHARDHOST;
}
Now when you have a model in cakephp such as GroupModel that you want to shard. You specify:
var $useDbConfig = 'shard'; // this is the name of a class member in
// DATABASE_CONFIG. I created this var in
// the above constructor.
And the correct server address will be used. This allows you to stay within the cakephp conventions and not break the schema caching.

Tuesday, April 14, 2009

Friday, April 10, 2009

rake db:migrate error when using differing libmysql.dll and mysql servers

I'm using a fedora mysql server, while the ruby server runs off of windows. the libmysql.dll form my previous post came from a 5.1 windows mysql server.

The version mysql server on fedora is 5.0. This caused the following error:

D:\workspace\rubytest>rake db:migrate
(in D:/workspace/rubytest)
rake aborted!
Mysql::Error: Commands out of sync; you can't run this command now: SHOW TABLES

(See full trace by running task with --trace)

Solution:
get the mysql-noinstall 5.0 server and copy the libmysql.sql into /ruby/bin

ERROR: While generating documentation for mysql

Error while running the command
gem install mysql
in windows xp

Produced this error:

C:\>gem install mysql
Successfully installed mysql-2.7.3-x86-mswin32
1 gem installed
Installing ri documentation for mysql-2.7.3-x86-mswin32...
Installing RDoc documentation for mysql-2.7.3-x86-mswin32...
ERROR: While generating documentation for mysql-2.7.3-x86-mswin32
... MESSAGE: Unhandled special: Special: type=17, text=""
... RDOC args: --op d:/Ruby/lib/ruby/gems/1.8/doc/mysql-2.7.3-x86-mswin32/rdoc -
-exclude ext --main README --quiet ext README docs/README.html
(continuing with the rest of the installation)

Solution:
set path=%path%;c:\mysql-5.1.33-win32\bin\

I then copied the libmysql.dll from the above bin into the ruby bin (I'm not sure this is necessary, but it was one of the steps). Note copying the libmysql.dll from the mysql tools did not work, it has to be from the mysql server files. An easy way without installing mysql server is to use the mysql noinstall zip.

I then ran the command
gem install mysql --no-rdoc

I still get an error if I run gem install mysql, but with the no-rdoc the ruby server is able to run.

You can now delete mysql-noinstall and your site should work.

Tuesday, January 6, 2009

Setting up cruisecontrol on fedora 10 linux

Tested using cruisecontrol-bin-2.8.1.zip
Fedora 10
Java Version: openjdk and openjdk-devel rpm

I had some problems going through the Getting Started tutorial for cruisecontrol, so here is what I did to get it working. The version we're downloading works as is and you don't need to run the install.sh as suggested. Except for a few environment variables that need to be set, it's ready to go.


Step 1
As root (cause i'm lazy and don't want to type in sudo every time, also environment variables need to be viewable by the scripts and if you set them in [yourusername] they won't appear when you run the cruisecontrol service as root)

unzip cruisecontrol-bin-2.8.1.zip -d /opt/ ln -s cruisecontrol-bin-2.8.1 cruisecontrol

Step 2
These next two environment variables are necessary or else exceptions will be thrown. You will need to find your home directory for java as it's usually symlinked to the one in /usr/bin/java. I tracked Fedora's java to

lrwxrwxrwx 1 root root 22 2008-05-17 04:59 /usr/bin/java -> /etc/alternatives/java lrwxrwxrwx 1 root root 46 2008-12-07 16:21 /etc/alternatives/java -> /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java

BASH
export JAVA_HOME='/usr/lib/jvm/jre-1.6.0-openjdk.x86_64'

TCSH
setenv JAVA_HOME /usr/lib/jvm/jre-1.6.0-openjdk.x86_64

Step 3
The other environment variable that needs to be set is
ANT_HOME

I recommend using the ant provided in the cruisecontrol directory. If this environment variable is not set an error like this appears:

log.xml does not exist.
or
The specified logger class net.sourceforge.cruisecontrol.builders.AntProgressLogger could not be used because Class not found: net.sourceforge.cruisecontrol.builders.AntProgressLogger

setenv ANT_HOME /opt/cruisecontrol/apache-ant-1.7.0

Step 4
Run cruise control
cd /opt/cruisecontrol ./cruisecontrol.sh

Step 5
This should now begin the cruisecontrol web server and you should be able to see the dashboard
Visit these URL's
http://localhost:8080/dashboard http://localhost:8080/cruisecontrol http://localhost:8080/cc-config

For some reason the current version of cruisecontrol gives a 404 error when visiting http://localhost:8080 . Older versions if cruise control redirect you to the correct place.