Skip to the posts
Buffalo's neighborhood journals since 2003 🍀 Patrick Spicy Devil Logan🌭 Sahlen🥨 Weber Spank🥟 Pierogi🐸 Scaj🍺 Labatt Utica Pink Cherio❄️ Snow Murder

paul’s journal

🏷️ programming

48 posts

Updates SurbertCom

· · 🌡️ 62°F

I updated the surebertCom library to add lots of new array functions and two new string ones.

strings: ltrim, rtrim, trim
arrays: drop, random, unique, combine, inject, substrCount, strstr, stristr, walk

I still haven't documented everything but strings and array methods are fully documented with examples. Same with sound, events, and ajax. Check it out if you are a javascripter.

image

Coding Javascript

· · 🌡️ 71°F

This week, I have recoded my years worth of javascript functions and objects into a beautiful, name spaced, inter-dependent, object oriented library that will make new stuff so much more exciting to program and extend. Unfortuantely, I now have to go through the process of retrofitting everything I previously created with the system.

Luckily, I moved all the javascript code out of my documents and into external js files years ago, so there is no having to go through lots of markup to deal with inline tags that are burried deep within. Most of the stuff shall convert nicely and now I never have to worry about namespace conflicts ever again and will never have to track down little code snippets.

Surebert is no longer surebert but the surebertCom library which has a communicate object to replace the old surebert 1.6.

None of this probably means anything to anyone, but I want to note this day for when I look back.

I will make the library publically available at some point in the near future.


The objects themselves can a sort of namespace. e.g.

myLib={

jump: function(){
alert('jump');
},
run: function(){
alert('run');
},
swim:function(){
alert('run');
}
}

now I can safely use even if I am using other javascripts that has a jump() function.
mylib.jump();

if you know you aren't going to have a conflict that you can use
jump = myLib.jump; to make a sort of global alias to the function
jump();

The nice thing is all these objects can interact and extend each other and javascript object literal notation is so easy to read and maintain.

I group all my objects in the surebertCom object and then it has further breakdowns into uses and types e.g. surebertCom.strings, subrertCom.sounds, etc

Javascript Prototypes Part II

· · 🌡️ 59°F

Here is a good example I wrote of javascript prototypes that extend other objects. @paul #4369 was part one and both were in reference to @zobar #59

[box]<html>
<body>
<script type="text/javascript">
/*create a sound object for making sounds*/
sound = function(noise){
    this.setNoise(noise);
}

/*add new prototype to output the noise */
sound.prototype = {
    /*set the noise echoed on sound.out)*/
    setNoise : function(noise){
        this.noise = noise || 'plain sound';
    },
    
    /*output the noise*/
    out : function(numTimes){
        var noise ='"';
        for(x=0;x<numTimes;x++){
            noise += this.noise;
            if(x<numTimes-1){ noise +=', ';}
        }
        return noise+'!"';
    }
}

/*create a animal object for making animals that make sounds*/
animal = function(name, noise){
    this.setName(name);
    this.vocals = new sound(noise);
}

animal.prototype = {

    /*set the name of the animal*/
    setName : function(name){
        this.name = name || 'another animal';
    },
    
    /*prototype to wrap sound.out*/
    talk : function(times){
        alert(this.name +" said "+this.vocals.out(times));
    },
    
    /*prototype to wrap sound.setNoise*/
    changeVocals : function(noise){
        mySquirrel.vocals.setNoise(noise);
    }
    
}
/*instantiate an animal ( a squirrel that barks) and make it talk */
mySquirrel = new animal('squirrelio', 'bark');
mySquirrel.talk(3);
mySquirrel.changeVocals('ruff');
mySquirrel.talk(4);
</script>
</body>
</html>
[/box]

A lot of people have come up with different methods for dealing with inheritance. Here is one page that explains it and here is another that abstracts it a bit.

Once you are into the prototyping system you can make your own system to make extending and inheriting easier.

Javascript Prototypes

· · 🌡️ 64°F

Believe it or not, I love javascript so much.

SIDENOTE ON SUREBERT
If you want to use surebert for any AJAX stuff at artvoice, feel free. It allows you to easily post data to any page. Here is the non-compressed js version so you can see what is going on.

Prototypes
@zobar #59 if you already know this then maybe this is a waste because no one else is going to read it besides maybe @enknot who already knows this because we talk shop all day at work, but in case you haven't thought about it, you can write very extensible objects in javascript using protypes.

In fact, I would argue that the prototype if the basis of complicated OOP in javascript. The prototype is applied to every instance of the object without having to copy the function as it is when declared as a function within the constructor.

Here is how I would write it

Greeter = function(yourName){
    this.yourName = yourName;
}

Greeter.prototype.getTimeOfDay = function(timeOfDay){
    alert('Good ' + timeOfDay + ', ' + this.yourName);
}

greetZ = new Greeter('Zobar');
greetP = new Greeter('Paul');

greetZ.getTimeOfDay('afternoon');//'Good afternoon, Zobar'
greetZ.getTimeOfDay('evening');// 'Good evening, Zobar'
greetZ.getTimeOfDay('evening');// 'Good evening, Paul'
[/box]

Because everything is an object in javascript, if you have mutliple prototypes for an object you can easily write them like below which look very neat and organized when used with large objects.

[box]
Greeter = function(yourName){
    this.yourName = yourName;
}

//javascript object notation for attaching multiple protoypes to an object.Although you could write each one as Greeter.prototype.name of function, I think when have lots of protypes this looks neater. You can also add any of properties as a prototype. In this case I am also creating a property called job. that can be referred to as instanceName.job e.g. greetZ.job you can even attach protoype arrays this way

Greeter.prototype = {

    'job' : 'programmer',
    
    getTimeOfDay : function(timeOfDay){
        alert('Good ' + timeOfDay + ', ' + this.yourName);
    },
    
    getRandNumber : function(min,max){
        min = min || 0;
        max = max || 100;
        alert(Math.floor(Math.random()*max+min));
    },
    
    sayHello : function(){
        alert("Hello, "+this.yourName);
    }
}

greetZ = new Greeter('Zobar');
greetP = new Greeter('Paul');

greetZ.getTimeOfDay('afternoon');//'Good afternoon, Zobar'
greetZ.sayHello();// 'Hello, Zobar'
greetZ.getRandNumber(10,30);// 'Good evening, Paul'

New programming style

· · 🌡️ 65°F

I just discovered something that makes me want to re-organzie all this code I just wrote. Why could I not have thought of it 10,000 lines ago!

Bye bye
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype
mover.prototype

Beautiful Errors

· · 🌡️ 56°F

Well I don't officially know if they are beautiful yet as I am not officially a master of fine art - not until february. This happend as an accident. I was using surebert for an ajax front end to an applictaion and I wanted the repsonses to be in random places on the page so that it was easy to debug.

I got back into my ide but left the browser window open. When I went back, 3000 queries later, the system has drawn me this image based off the following basic colorization code, a little surebert and some error magic.

image

image

image

image

image

Here is the tiny simple code that made it happen

function mv(obj,x,y,z){
    if(typeof(obj)=='string'){
        obj = $(id);
    }
    obj.style.position='absolute';
    obj.style.left = x +'px';
    obj.style.top = y +'px';
    if(z!=undefined){obj.style.zIndex=z;}
}

function rand(min,max){
    min = min || 0;
    max = max || 100;
    return Math.floor(Math.random()*max+min);
}

function randColor(grey){
    if(grey == 1){
        grey = rand(0,255);
        return "rgb("+grey+","+grey+","+grey+")";    
    } else {
        return "rgb("+rand(0,255)+","+rand(0,255)+","+rand(0,255)+")";    
    }
}

Cancer Viewer Application

· · 🌡️ 68°F

My dermatology viewer application is coming along great. Today I had a meeting with the doctor who requested it and he seemed genuinely impressed. It allows for zoom ,hue, saturation, brightness, contrast, sharpen and position changes which are all logged via surebert to a database so that the image maintains state between uses. Anytime someone switches images, saves, or leaves the site - the current images data is saved to the database. To remain compliant with HIPAA compliant it also keep an annotated log of what it is doing and who is using it and can report what it is doing using HL7

Doctors and clinicians can also add their own annotations.

It feels good to make things that have some purpose other than social networking. The app isn't blurry, I just blurred out everything you could identify.

image

I know its weird but I though skin tones was an appropriate color scheme. When testing some out in ther derm clinic today, I thought about how werid it would be to some day be a patient image inside my own application. I just hope that never happens.

Where do the days go?

· · 🌡️ 44°F

I have developed an insane amount of new code for really cool DHTML/AJAX interface kind of stuff but it seems I never have time to implement any of it. Today I had a biweekly meeting with my boss about what i was working on and I decided to print out some of the stuff from this week. There were like 30 pages of javascript of every flavor.

It was so weird to see so much work printed out on paper. It really quanitifies programming while destroying the enviroment at the same time.

Lots of fun with math this time. Math is definately not my strong point but I am getting a lot better at it each day. When that's done I am going to learn italian and then finish editing my thesis.

On another note, I am glad to see someone is graduating @holly #139

I really wish it was me. I guess I will try for the summer. This is getting so fucking ridiculous because (e:strip) was my final project and I would say it has "done enough" for about a year or two. Now I just need to say something about it.

I made so many form widget, but this one is my favorite followed by the adjuster widget which iterates through arrays.

image

The cancer viewer using some serious flash AS to manipulate image vectors and change brightness, contrast, hue, saturation, blur as well as zoom - all of then which communicate with the client via javascript sliders that auto save their positions between use.

image

An rss reader that uses surebert and poser to bring rss feeds live to the web page on timed animation sequence.
image

A javascript based motion capture object that can record and playback animations that can be saved for late ruse on a web site or to push drawings back and forth between user in realtime using surebert
image

PPC 6700 extraneous data in jpegs

· · 🌡️ 36°F

The PPC 6700 which runs Windows Mobile 5.0 is my first truly futuristisic phone. I had a sidekick, I had a blackberry, I had a Nokia 7710 but this phone blows the other ones away in tersm of features, network speed (~200-500kps), includes Wifi, bluetooth, keyboard, IR. It is amazing.

image

The only problem is that the 1.3 Megapixel camera produces faulty jpegs that have 16 extraneous bytes in their EXIF data. The unfortunately cause the photos to not work with many web sites which use open source Jpeg libraries to resize images. I heard they even have problems being viewed in gmail.

In order for the phone to be truly useful I had to be be able to take images from the phone and use them on my journal. So it was time to get out the old fashioned hex editor and begin experimenting with which bytes were the extraneous ones. Turns out it was a regular sequence right at the end of the EXIF data. The etxra string looks like this:

"x00x10x4Ax46x49x46x00x01x01x00x00x01x00x01x00x00"

I found that this string identifies the images as from the PPC 6700

"x41x70x61x63x68x65x00x48"

Unfortunately, the string is sometimes repeated but only the first one was extraneous, so you can't just doa blind search and replace. instead you have to just repalce the first one. here is some PHP code that would allow you to use these images as normal ones using GD. You an find a copy of this


<?php
function checkFixPPC6700($orig){
    //get the file contents
    $data = file_get_contents($orig);
    //if its a PPC 6700 image cut out the extraneous 16 bits
    if(strstr($data, "x41x70x61x63x68x65x00x48")){
        $bad_data = "x00x10x4Ax46x49x46x00x01x01x00x00x01x00x01x00x00";
        return substr_replace($data, "", strpos($data, $bad_data), strlen($bad_data));
    } else {
        //if not from a PPC 6700 return data unaltered
        return $data;
    }
        
}

$data = checkFixPPC6700('IMAGE_006452.jpg');
//$im = imagecreatefromstring($data);

if (($im = imagecreatefromstring($data)) !== false) {
header('Content-Type: image/jpeg');
imagejpeg($im);
}

?>