Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Sunday, February 20, 2011

Thursday, November 4, 2010

And the Weiner is...

Yes, I admit it... Epic Fail.

I could complain about my wife being out of town and, therefore, not only not able to help me with my Venom costume, but causing me to be distracted, as I don't operate well (at all) when she's not around.

I could also blame the time I spent on reviewing stuff for the websites or helping to run the ACM Regional Programming Competition at LSU, but that would be unseemly, now wouldn't it?

Or, I could blame it on the red paint not drying on the rubber snake (it didn't for about a week, actually) or the fact that Hancock Fabrics didn't have enough of the material I wanted. I could even say it's all because my sewing machine refused to work the night before the contest... which is true, but hardly the one thing that went wrong...

The truth, of course, is that I tried to do too much, in too short of a time. I didn't even wear a costume for Halloween this year. Live and (hopefully) learn, I suppose. My plan is to keep working on the Venom costume over the next year, in my "spare" time. I am generally a busy person, but I'm going to try to set aside a few hours a week to work on "Personal Projects," such as building a full-sized R-Series Droid, modifying my car, dabbling with electronics and making costumes, not the least of which is this Venom costume.

In other news, my best friend, neighbor, fellow Game Vortex game reviewer and partner in crime, J.R. Nip, did throw together a costume in a single night, and not only did it come out nice looking - he actually took first place at Lamar's Corporate Headquarters Costume Contest. He went as Dilbert, with black shoes, white socks, black pants, a white shirt, a flip-up red tie that I helped rig up with a metal coat hanger and a mask he made of poster board, skin-tone material and enough chemical adhesives to tranquilize a horse. He did an awesome job, and won a hundred dollar prize, to boot!

Ah, well... Venom will have to have his day next year. . .

Monday, August 16, 2010

JavaScript String Replace All... and Then Some...

Need to replace text in a JavaScript string? Use string.replace and you're done. Unless, of course, there are multiple instances to be replaced, since the string.replace() function only replaces the first occurrence.

I had that problem, and found Brandino's article, JavaScript String Replace All to be just the trick.

It seems that you can use a regular expression as the target of the string.replace function.

In fact, in addition to being able to do multiple replaces on a single target, this also would allow you to create a regex target for your replace that would replace different things with the same replacement text... which could be handy if you need to remove or replace certain unwanted characters throughout a string...

Thursday, August 28, 2008

Appending to event functions in javascript

So, Google Answers is a Google Product (feature?) that has come and gone, evidently. I was looking up some information on how to do something specific with JavaScript and Googled into a JavaScript question that someone had posted, asking how to go about "Appending to event functions in javascript".

Well, this was not what I was doing, specifically, but along the same vein of what I was looking into. Anyway, I was sad to see that I knew the answer and yet, with Google Answers closed down, I wasn't able to post a response, even though no one had answered the question.

Anyway, I am posting a code snippet below for anyone who is interested in adding javascript function calls (or, for that matter, other javascript executable statements) to the document.body.onload after the page has started loading.

This comes with no guarantee or warranty, but may be fun to play around with. Please note that the alert that says "This fires first" fires ON LOAD, as do the others, but it fires before the "page has loaded" alert, because it is being PREpended to the top of the list of things to do on load. This allows you to include something later in the file that needs to be done before other things. Using this same concept, one could build a more elaborate set of functions that allow you to insert statements into the list of statements to be executed in a specific, desired order, sort the statements in some fashion or specifically delete or modify a single statement, but I don't know if that would really serve any true purpose. This is more of an academic exercise.

The code:
<html>
<head>
<title>Changing Onload via JavaScript</title>
<script>
function onload1()
{
alert("page has loaded");
}
function addedFunction()
{
alert("Added Function successfully");
}

function prependOnload(statement)
{
insertOnload(statement, true);
}
function appendOnload(statement)
{
insertOnload(statement, false);
}
function insertOnload(statement, isPrepend)
{
var oldOnload = document.body.onload+"";
var startOfOldStatements = oldOnload.indexOf("{")+1;
var endOfOldStatements = oldOnload.lastIndexOf("}")-1;
var instructions = oldOnload.substring(
startOfOldStatements, endOfOldStatements);
var newOnload = (isPrepend)?
(statement+instructions):(instructions+statement);

newOnload = new Function(newOnload);
document.body.onload = newOnload;

}

</script>

</head>
<body onload="onload1();">
<script>
appendOnload("addedFunction();");
prependOnload("alert('This fires first');");
</script>
</body>
</html>


Notes on the code:
The main work-horse here is insertOnload(). The first thing it does is gets the current value of onload as it stands. This is a function, not a string, so in order to manipulate it, we have to force a cast to string, hence the +""... add a string to something and it becomes a string. Sneaky, no?

With the contents in a string form, we then peel off the function definition, leaving us with a list of instructions (again, as a big ole chunk of text). We can easily either add our new statement to the beginning (statement+instructions) or to the end (instructions+statement).

Now that we have the statements that we want executed, we have to create a new Function containing this new list and then assign it to document.body.onload and we're done.

Saturday, November 22, 2003

Linux for PlayStation 2 Community: Linux for PlayStation 2 in Education

Linux for PlayStation 2 Community: Linux for PlayStation 2 in Education

PS2DEV: PS2 Programming - Latest News

PS2DEV: PS2 Programming - Latest News - The PlayStation 2 Underground Unauthorized Development Movement... Cool.

Thursday, October 9, 2003

A Gentle Introduction to ML

Hmm... Language considerations... A Gentle Introduction to ML.
Newsgroup: (news:comp.lang.ml, news:comp.lang.functional)

And then there's always F#...