ASCII to compressed ASCII

Here is a funny experiment with javascript. It takes normal text as input and returns encoded ASCII text (from 0x20 thru 0xFF) with a 30% reduction in length, which can be decoded later to the original, with some exceptions/rules. It preserves only alphanumeric characters (except for some of them which are transliterated specially, like 1 = I or Z = 2).

This could be funny as a workaround in some situations, like circumventing the classical Twitter limit of 140 characters (would need the decoder on the other side, of course).

https://jsfiddle.net/julifos/ehuwaae2/

A few websites

A few websites I developed or helped to develop in the past few years:

http://www.julifos.com/

http://www.pescadosweb.com/

realmadridkidsplanet.com/ (dead)

http://www.chesswithoutborders.com/http://www.ajedrezsinfronteras.com/

http://pgrtraducciontecnica.com/ (dead)

http://yogamanam.com/

http://www.qilania.com/

http://www.damainvisible.com/ (dead)

And hundreds of web applications I can’t show because they reside in private areas 😉

I hope to resume my activities in this blog, as I have many things to share…

HTML5 6, Swiffy: fscommand & setFlashVars, back and forth communication

Plenty of new tools are arising in order to make a quick-move from the “old” Flash to the “new” HTML5, as HTML5 can’t still be taken into consideration when you need to create loads of contents. Simply put, there are no IDEs which would allow rapid-application-development. If you want graphic libraries, you must do it yourself. Coding? The same. Sound? The same.

Sure, there are lot of pre-written libraries, but they can’t be usable in a real pro environment. I can’t charge my interactives 1 or 2MB of javascript libraries (minimified, of course), only to have very limited possibilities, given that for me is a must-have compatibility with many browsers and platforms. Scalable graphics, toons animation with A/V support, etc. Many of my old customers are calling now companies in third-party countries, which are employing hordes of pseudo-programmers only to make what we could do before using a very compact and tiny team. Maybe cheaper. I don’t like the results in many situations and I don’t think my customers like ’em. Cheap and quick is never a real solution if you wanna be a top-notch in your field. Functionality and design are the answers. Before that could be done in a more or less cheap and fast way, as we had tools. Now STILL it can’t be done.

Adobe Edge should be in a future a possible answer.

Some of the answers we have now (Edge not being a realiable solution today we can take into account) are “Flash Professional Toolkit for CreateJS” (formerly called Wallaby), which didn’t meet the requirements the last time I tried it.

I’ve tested today Google’s Swiffy. The last time it wasn’t either ready. And it isn’t! But I found a use today, so I thought I should comment.

It works pretty fine for plain animations (cartoons) in the main timeline, and supports a very basic (but still usable) subset of AS2 (more limited AS3). Enough for clicks and so on… And I found the way to inter-communicate with the animation, so I can rely in Swiffy for the animation and cover from outside the rest (such as sync audio or whatever is needed). The cost is pretty high, though (164Kb), but at least I’m not forced to write my own animation engine (which is why I wasted this entire day to test Swiffy).

There are things you must considerate, such as the fact that some times you can’t play two things at the same time (ie, the main timeline and a mc). But if you learn the rules, it isn’t difficult to create quick, realiable and fashionable animations.

This is how you do it:

AS2 (place this on the root of your Flash movie):

// "custom methods" broadcasted to JS
playSound = function(id){fscommand('playSound',id)}
_stop = function() {fscommand('stopped');stop();}

// orders coming from JS (such as FlashVars)
this.onEnterFrame = function(){
    if(this.command){
        var c = this.command;
        if (c=='play'){
            play();
        } else if (c=='stop'){
            stop();
        }
    }
    this.command = null;
}

I used AS2, because it offers more methods and classes, including fscommand. You have as well getURL (and navigateToURL in AS3), but it’s much more rough than fscommand, as it addresses directly a named js function instead of passing it to the browser, such as “javascript:function()”.

You can see in this code two parts:

  1. Send info to javascript using fscommand.
  2. Receive info from javascript using the old-school flashvars method.

This is how you receive info in the javascript-side (well, Swiffy is nothing more than JS, but we’ll make the illusion, as if it was a different thing):

function swiffycontainer_DoFSCommand(cmd,args){
    if(cmd=='stopped'){
        alert('movie stopped')
    } else if(cmd=='playSound'){
        // do whatever, ie play sound id "args"
    }
}

Hear this. The function receiving the fscommand must be called DIVNAME + “_DoFSCommand”. DIVNAME is the name of the div containing the swiffy object, such as (fix the DIV tags, as this damm CODE tag in WP doesn’t handle it):

DIV id="swiffycontainer" style="width: 808px; height: 424px">
CLODEDIV

That div is used later (code auto-inserted by Swiffy) as follow:

var stage = new swiffy.Stage(document.getElementById('swiffycontainer'),swiffyobject);

stage.start();

So, we need the name of the div, in this example “swiffycontainer”, and append “_DoFSCommand”. You will receive one or two arguments in that function (depending on your desires), being the first one mandatory (as you’re commanding something) and the second one optional (you can pass here any options if you need to).

And, finally, this is how you send commands or info to the Swiffy object:

stage.setFlashVars('command=play');

You’re setting FlashVars as key=value. And you must address stage, which is the var you defined before to hold the swiffy object (well, Swiffy did it for you, but can change that name).

This sample one-liner will set the variable “command” to the string “play”. You will read that from the enterFrame handler you wrote before, and make something with it.

The part I don’t like is using SVG. Doesn’t seem very good in performance in complex animations, compared to their opponents Flash & canvas. That’s browser’s fault, as they have the SVG specs since ancient times (!).

In my preliminary tests, seems that the output is supported in much more browsers than those stated in the Swiffy website, but that may depend on the features you need (maybe some filters won’t work in older FF versions, or something like that). But works in a wide range of browsers/versions for the basic features I tested.

Cheers.

Backup remote mysql database to local machine

I told you here a way to backup remote MySQL databases using a mix of AppleScript and shell script (ssh).

But that method won’t work with certain table types, which don’t store the data in files, such as InnoDB. So, here is a one-liner using mysqldump to backup that kind of databases…

mysqldump --opt --compress --host='website.com' --user='USER' --password='PWD' --all-databases | mysql -uUSER -pPWD -h127.0.0.1

Just substitute where needed USER and PWD. This shell script requires MySQL running in both machines and privileges to access the data in both sides.

IMHO, it runs much slower than the other method (making a copy of the remote db files) so, if you can use it, go for it! Otherwise, this method is safe for your data (safe if you don’t lose power or internet connection in the process 😉 ).

See “man mysqldump” for more options (such as extracting only certain databases or tables, as this script will backup everything!).

Modify tiles walkability in OpenSpace (on-the-fly)

This post applies to OpenSpace 1.x, but may apply also to 2.x (I didn’t study it yet!).

One major issue for OS1 owners is controlling avatar’s movements all the time long. Full control over the avatar. All the methods and properties related to avatar movement and re-creation of the tile-map according to new settings are private, closed. You can’t access and modify them unless you purchase a source license.

But here we go with a custom solution, which may be helpful for you in some situations as it was for us. As there is no available method to prevent avatar movement (ie, the user clicks in a tile and the avatar walks there in despite of what you say), the only solution is preventing user clicks!

Simple, not smart, but working solution.

And how in hell you do that? Also simple: place a transparent-clickable movie-clip in the tile, so it catches user clicks and nulls them. Just iterate over OpenSpace.getChildAt(0)’s children (the tiles) and do the job.

And now a few hints, as the situations are very different depending on your needs…

You can’t moveMyAvatar() or teleportMyAvatar() to the current tile –> this way you can’t prevent avatar movements! So, before user clicks, you must evaluate and decide if the avatar can walk (click, if you use the suggested workaround).

If you can’t decide prior to user’s election if he can walk/click, then you must evaluate after he clicks and starts walking. In that situation, take into consideration the previous paragraph. As you can’t moveMyAvatar() or teleportMyAvatar() to the current avatar’s coordinates (as coming from getCurrentTile()), move or teleport the avatar to a different tile.

There is a variety of events you can use to evaluate your conditions (ENTER_TILE, TILE_SELECTED, etc.), so most probably you will find some solution to your headache 😉

EDIT: Appart from the exposed method, still valid, would be nice to take a look to the following approach: dispatch a first moveMyAvatar() to a fake tile, so OpenSpace registers as current-tile the next one in the pathfinding, the issue a new moveMyAvatar() to the current (real) one.

AppleScript, mother tongue of Mac’rs

Before you were a Codewarrior addict, later Carbon libraries consumer, then Cocoa, then Obj-c, then iPhone developer, then what!

If you are a Mac user (not developer, being old or new to the business), AppleScript is your friend. In fact, any OSA-based language or “dialect” if I can call it so (such as appscript by Has or some handmade experiments by Phillip Aker). Apple Events. Application Intercommunication. Sounds like simple, but it’s the marmalade (not to talk about glue) of the daily workflow of hundreds of thousands of Mac users.

Come to mind other “experiments”, like “basic” (being Real or MS) or JavaScript for apps (such as Adobe’s apps or Air), but that is just System/App communication. It’s fine, but not in any way a checkpoint.

Although Qilania lives in a Ubuntu-driven server, many automation tasks are done in various “slave” machines, and many of them are driven by AppleScript, specially mirroring and db integration. For example, you can make tiny changes to a SWF file, and see them live in a few seconds. First, on the local server. Then, in the live server. And also changes are propagated to backup disks and so on. Magic under a double-click. Lots of technology involved: network connections, remote servers via ssh or sftp or scp, various desktop applications, etc. And one scripting language to rule them all: AppleScript.

I can ensure today, Sep 10th 2010, there is not programming language to acomplish most of these tasks we solve in a few seconds in Qilania, not in Mac nor in Win or *nix.

AppleScript, the marmalade and mother tongue of all Mac users.