Archive for the 'Software Development' Category

Fuck x-webkit-speech

Friday, June 24th, 2011

Today when experimenting with chrome’s speech recognition I noticed that it censored swear (curse) words.  I could not find a property to enable me to talk like a sailor.  So I came up with a hack.  I intercept the  onwebkitspeechchange event and convert censored words to uncensored words.  So b**** become bitch, f*** becomes fuck, ect.  Here is a demo.

Get the source at http://www.timothyhuertas.com/demo.html

**note this works in chrome only
Happy uncensored searching!

InetAddress.getLocalHost().getHostAddress() 127.0.0.1

Tuesday, January 11th, 2011

Today I wasted about 4 hours on this.  I was running in to an issue because InetAddress.getLocalHost().getHostAddress() was returning “127.0.0.1″ aka the loop back address and not the “real” IP address I expected.  It sounds silly, but after hours of Google-ing and head banging it turns out the cause of this was a corrupt hosts file (which I had been looking at all day trying to figure out what I needed to do to it to make stuff work).  The moral of the story is if you run in to this problem back up your current host file then replace it with a default one.

FABridge.js play nice with Chrome

Tuesday, November 30th, 2010

Today at work I got an email that said, “The site text editor is broken in Google Chrome. Remember about 3 years ago when you thought FABridge.js was a good idea?” In hindsight I would not have used FABridge. I think the levels of indirection out weigh the ease of use (especially if you need tons of control). Nonetheless I had to fix it. Once I found the bug it was pretty easy to fix. I narrowed the error down to FABridge__bridgeInitialized in FABridge.js. FABridge__bridgeInitialized looks for either an embed or object tag based on the browser type. A check for Chrome did the trick.

In FABridge.js if you change:
if (/Explorer/.test(navigator.appName) || /Konqueror|Safari|KHTML/.test(navigator.appVersion))
to:
if((!(/Chrome/.test(navigator.appVersion))) && ((/Explorer/.test(navigator.appName) || /Konqueror|Safari|KHTML/.test(navigator.appVersion))))

you should be in good shape.

So if you hear FABridge.js does not work in Chrome. Or your JavaScript wrapper to the Flash widget is broken this may solve your challenge.

THERE IS A BETTER WAY TO DO THIS. HERE IT GOES
/**This function searches for the flash dom object that has the flex movie in it.
*In some browsers this is an object tag. In other browsers this is an embed tag.
*We know we have the right thing when we find a dom object with the function getRoot.
**/
function FABridge__bridgeInitialized(bridgeName)
{
var searchStr = “bridgeName=”+ bridgeName;
var flashInstanceWithBridge = null;

var flashInstances = document.getElementsByTagName(”object”);

//search object tag
if (flashInstances.length == 1)
{
flashInstanceWithBridge = flashInstances[0];
}
else
{
for(var i = 0; i < flashInstances.length; i++)
{
var inst = flashInstances[i];
var params = inst.childNodes;
var flash_found = false;

for (var j = 0; j < params.length; j++)
{
var param = params[j];
if (param.nodeType == 1 && param.tagName.toLowerCase() == "param")
{
if (param["name"].toLowerCase() == "flashvars" && param["value"].indexOf(searchStr) >= 0)
{
flashInstanceWithBridge = inst;
flash_found = true;
break;
}
}
}

if (flash_found) {
break;
}
}
}

if(!flashInstanceWithBridge|| !flashInstanceWithBridge[”getRoot”] || !(typeof(flashInstanceWithBridge.getRoot) == “function”) ) //search embed tag if the object tag does not have the needed methods
{
flashInstanceWithBridge = null;

flashInstances = document.getElementsByTagName(”embed”);
if (flashInstances.length == 1)
{
flashInstanceWithBridge = flashInstances[0];
}
else
{
for(var i = 0; i < flashInstances.length; i++)
{
var inst = flashInstances[i];
var flashVars = inst.attributes.getNamedItem("flashVars").nodeValue;

if (flashVars.indexOf(searchStr) >= 0)
{
flashInstanceWithBridge = inst;
}

}
}
}

if(flashInstanceWithBridge)
{
FABridge.attachBridge(flashInstanceWithBridge, bridgeName);
}

return true;
}

JNI + OSGI + Refactoring + Idiot = 2 wasted days.

Thursday, March 18th, 2010

I just wasted two days.  I am working on a desktop application in JAVA.  It needs to sniff web proxy settings from the Window’s registry (and some day other platform specific locations).  I decided to use JNI  to do this.  Everything worked like a charm in my sandbox JAVA application.  I then embarked on moving it to and OSGI bundle.  When I ran the thing I received a java.lang.UnsatisfiedLinkError.  WTF!!  WHY!! 

When I debugged my call to System.load(”somedll”) worked, but an exception was triggered when I invoked the native method.  I then thought well maybe its and OSGI thing.  After some Google-ing I found a few write ups on how to tweak the manifest to load the system specific library.  I tried effing with the manifes eight ways from Sunday, but still no workie.  I then came across a forum where someone had the same issue I did and they eventually discovered that that they had renamed their JAVA class, but did not regenerate the JNI lib.  It then dawned on me that I had refactored my JAVA class in to a new package, but did not update the generated .h file.  

The morale of the story is if your JNI call works outside of OSGI, but then stops working when you move it in to OSGI; ask yourself “did I refactor this thing when I moved it in to a bundle?” 

Motion Detection Revisited

Thursday, July 30th, 2009

About 2 years ago I did some experiments with ActionScript 3 and motion detection.  Looking back I had no idea what what the ActionScript I pieced together was doing.  I have since gained a better understanding of some of the low level bitmap data functions available in AS3.  I threw this together last night and am quite pleased with the result.  It is a virtual drum game.  The game works best if you get out of you chair and position yourself such that your hand is the same size as a drum.  I have separated the motion detection logic so that it can be reused on any DisplayObject.  Also it is not nearly as memory intensive as the first implementation.  I took the sounds from http://www.themaninblue.com/experiment/JS-909/ (thanks Cameron Adams).  Here is a demo.  Here is the source.  This is a proof of concept and certainly not the first AS3 web cam motion detection experiment.  I am curious to hear what you think of my implementation.

Flex Module with in a Module Bug (Fixed in Gumbo)

Saturday, March 7th, 2009

I know I am not the first to encounter this, but I thought it worth a mention anyway.  I ran in to an issue loading a module from with in a module using flex.  The module would load, but the ModuleEvent.READY would not fire.  The instance of the module was ready and setup was true.  WTF!!! why!  After searching the net I came across this bug https://bugs.adobe.com/jira/browse/SDK-14669.  It said a workaround is to load all the modules sequentially.  Now I know this sucks because 1 by 1 is not exactly a model of efficiency.  Anyhoo…I threw the following class together and thought it would help:


/**
* this class is to get around this bug
* https://bugs.adobe.com/jira/browse/SDK-14669
* when we move to gumbo (flex 4) the bug will be fixed
* */

package com.timothyhuertas.utils
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
import flash.utils.ByteArray;

import mx.events.ModuleEvent;
import mx.modules.IModuleInfo;

public class SequentialModuleLoader extends EventDispatcher
{
private static var _instance:SequentialModuleLoader;
private var _pool:Array;
private var _current:IModuleInfo;

public function SequentialModuleLoader(value:SingletonEnforcer)
{
_pool = new Array();
}

public static function get instance() : SequentialModuleLoader
{
if(!_instance)
{
_instance = new SequentialModuleLoader(new SingletonEnforcer());
}
return _instance;
}

public function load(info:IModuleInfo, applicationDomain:ApplicationDomain=null, securityDomain:SecurityDomain=null, bytes:ByteArray=null) : void
{
var queued:Object = new Object;
queued.info = info;
queued.applicationDomain = applicationDomain;
queued.securityDomain = securityDomain;
queued.bytes = bytes;
_pool.push(queued);
processPool();
}

protected function processPool() : void
{
if(_pool.length && _current==null)
{
var queued:Object = _pool[0];
_pool.splice(0,1);
_current = queued.info as IModuleInfo;
_current.addEventListener(ModuleEvent.READY, handleModuleResponse, false,0,true);
_current.addEventListener(ModuleEvent.ERROR, handleModuleResponse, false,0,true);
_current.load(queued.applicationDomain, queued.securityDomain, queued.bytes);
}
}

protected function handleModuleResponse(e:ModuleEvent) : void
{
IEventDispatcher(e.target).removeEventListener(e.type, handleModuleResponse);
_current = null;
processPool();
}

}
}
class SingletonEnforcer{}

An example of its usage is as follows:


var m:IModuleInfo = ModuleManager.getModule("Mod1.swf");
m.addEventListener(ModuleEvent.READY, modLoaded);
SequentialModuleLoader.instance.load(m,ApplicationDomain.currentDomain);

protected function modLoaded(e:ModuleEvent):void
{
IEventDispatcher(e.target).removeEventListener(e.type, modLoaded);
IModuleInfo(e.target).factory.create();
}

I hope this helps

Using C++ to read the Window’s registry.

Friday, November 21st, 2008

I am working on a project that requires me to deploy files to Firefox’s plugins directory.  The biggest challenge was finding the location of this directory.  People can have multiple versions of Firefox and may change the default install location.  Since the project targets Windows machines a coworker recommended reading the registry.  The idea sounded good, but it had been a while since I had cracked C++ (let alone Visual C++).  So I took to the web for some examples.  I came across this (http://msdn.microsoft.com/en-us/library/ms235431.aspx) on Microsoft’s web site.   It is a list of sample code for various Visual C++ tasks.  It helped me throw this together.  Below is source for a program that will write out every installed version of Firefox along with the location of the plugins directory.  Enjoy….


// registry_read.cpp
// compile with: /clr
using namespace System;
using namespace Microsoft::Win32;

int main( )
{

RegistryKey^ rk = nullptr;
rk = Registry::LocalMachine->OpenSubKey(”SOFTWARE”)->OpenSubKey(”Mozilla”);
array^subKeyNames = rk->GetSubKeyNames();

for ( int i = 0; i < subKeyNames->Length; i++ )
{
RegistryKey ^ tempKey = rk->OpenSubKey( subKeyNames[ i ] );
RegistryKey ^ extensionKey = tempKey->OpenSubKey( “extensions” );
if (extensionKey!=nullptr)
{
Console::WriteLine( “\nFound {0} here is the plugins dir {1}.”, tempKey->Name, extensionKey->GetValue( “Plugins” )->ToString() );
}

}

return 0;
}

Unable to resolve resource bundle “styles” for locale “en_US”.

Tuesday, July 22nd, 2008

Okay so I am hot on the trail of a bug in my AS3 application.  I save my application only to notice the following error message:

Unable to resolve resource bundle “styles” for locale “en_US”.

I say to myself “WTF” and just assume that my workspace is hosed.  I the rebuild my workspace only to be greeted by the same error message!

After about 4 hours of headbanging I am ready to reinstall Flexbuilder when I figure out what went wrong.  It turns out that I accidentally tried to include a class in the mx namespace in to an ActionScript project.

Here is the moral of the story.  If ever you find yourself with the above error message and you are working in a pure ActionScript project make sure your code does not have an import statement that references mx.

There are 10 types of people…

Friday, April 6th, 2007

It is often said, “There are 10 types of people; those who know how to count in binary and those who don’t.”  Well depending on which type you are the game I created will either be a fun way to learn or an addictive way to pass the time.  I wrote a game using Flex 2 that gives players a chance to see how many numbers they can convert from base 10 to base 2 in 60 seconds.  Note the cool binary timer in the upper left hand corner.  It is a stand alone component that extends mx.controls.Label.  As always I have included the source with this post.

Source

Play

Happy Gaming

Timothy Huertas

Digital Ink Using Flex 2

Thursday, April 5th, 2007

My friend John and I were pounding some beers at our local pub when the topic of Digital Ink arose.  He thought it would be cool to capture a signature via the web using JavaScript.  Of course I then decided to implement the thing in Flex 2.  I got the digital ink working in less than an hour (which is a testament to how bad ass Adobe Flex 2 is).  But I soon realized that I was only half way to capturing signatures via the web.  A screen with a vector graphic signature is cool, but damn near useless.  To complete this task I needed to send the signature somewhere to be archived.  I started searching Google for code to convert a canvas to a bitmap and came across James Ward’s blog.  Rats!!  He had already done what I was trying to do.  I downloaded his source and noticed that my implementation of the digital ink is slightly different.  So I decided to publish my implementation after all.  I totally ripped off his “doSave” method which leverages Tinic Uro’s AS3 PNG Encoder.  That being said I highly recommend visiting his blog.  He goes in to detail on how to use remoting to send the image to the server.  Thanks to the both of them for their help! 

Source

Run Example
Enjoy

Timothy Huertas

PS For once this code is pretty handsome!