Get and display remote code with mod'ed VISIT key

Discuss your code, get questions answered

Get and display remote code with mod'ed VISIT key

Postby oliver » Fri Apr 22, 2011 4:10 pm

[EDIT: There's now a tutorial that explains how to establish one-click links between your computer and ND1. This supersedes most of the information in this thread. See]

Here're the steps to change the ⊛⇩ (VISIT) key (or any other key of your choosing) into a "get code from my computer and display"-key. This enables you to code on your computer and test/run on ND1 one second later.

This solution let's you use your favorite editor and requires no custom server setup.

Pre-requisite: Your computer and your iOS device need to be on the same network, and you need to have sharing of files via http:// requests enabled on your computer. (On a Mac, you'd go to System Preferences | Sharing and check Web-Sharing, to do this.)

Steps in ND1:

1) Get or update the Tools shared folder. (Tap My Data | Shared Folders | Tools)

2) Go to Definition and edit the ⊛⇩ (VISIT) key: replace @visit with ≪ "" Tools.getCode ≫
[adjust to reflect your networking environment]
Edited VISIT key.png
VISIT function after edit
Edited VISIT key.png (10.48 KiB) Viewed 8955 times


Now, here's how you use this:

1) On your computer, write some RPL or JavaScript code using an editor of your choice

2) When you're ready to run it on ND1, save your code as a .txt file into the directory that's accessible via the base URL you specified above. (On Mac, that would be ~/Sites, if your base URL looks like the one above.)

3) On ND1, from within any folder, visit a variable by the name of your file without the .txt extension.
For example: If you saved your file as pascal.txt, you'd visit 'pascal' in ND1. (Enter 'pascal', tap ⊛⇩ (VISIT).)

Your file will be transferred, stored into the variable you specified, and the contents displayed in ND1's scrolling editor.
You can then do further edits on the device, or simply enter and drop.

If you wrote RPL code, transcode characters (\<<, \->, etc.) will be translated into the unicodes that ND1 expects.

You can use this method instead of, or in addition to, having a custom server set-up, which enables one-tap transfers (also via WiFi) of entire folders, between your computer and ND1. Note, that latter requires you to use a JSON editor, while the method given here doesn't.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

No edit; other keys than VISIT

Postby oliver » Fri Apr 22, 2011 4:33 pm

If you don't want to see your transferred code in the editor, you can edit the getCode function in Tools, and remove (or comment out) the last line:
Code: Select all
setTimeout(function() { calculator.exec("setEditLine", prg); }, 0); }

The VISIT key will then just transfer and store your program (ready to be run by pressing its soft-key).

If you don't want to put this function on the VISIT key, you may put it on any other key.

Or, put it as a key onto the menu pop-up:
Edit a menu, or create a new one, to say:
@key for Menu: Title
(@key is a special identifier that makes the menu a key, instead of a regular menu)
get for Soft Keys: Names
(or whatever name you want to appear in the menu)
≪ "" Tools.getCode ≫ for Functions: Functions
(adjust to reflect your networking environment)

With this, the menu pop-up will contain a key get that will get and display your remote code.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Other file extension

Postby oliver » Sat Apr 23, 2011 1:42 am

If .txt as extension bothers you, edit getCode in the Tools folder, and change ".txt" in this line
Code: Select all
    var prg = requestURL(calculator.unquote(baseURL) + calculator.unquote(name) + ".txt");

to whatever extension you prefer.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

RPL: Other binary sources

Postby oliver » Sun May 01, 2011 3:02 pm

If you wish to import RPL code that uses binary characters, instead of the common RPL transcode (trigraph) ASCII sequences or proper Unicodes, modify trans in the Tools folder (or, better, provide another function and call it instead of trans in getCode).

Here's the code of trans, which maps transcodes to Unicodes.
Code: Select all
function (str) {   
    var transcodes = { "\\<>": "\u2220", "\\v/": "\u221a", "\\pi": "\u03c0", "\\<=": "<=", "\\>=": ">=", "\\=/": "!=", "\\->": "\u2192", "\\PI": "\u03c0", "\\<<": "\u226a", "\\>>": "\u226b", "\\:-": "/", "\\^|": "\u2191", "\\v|": "\u2193" };
    function mapStringsInString(str, map) {
        var s;
        for (var mapping in map)
            while ((s = str.replace(mapping, map[mapping])) != str)
                str = s;
        return str;
    return mapStringsInString(str, transcodes);

This allows you to adopt this import mechanism to any binary source of RPL code.

This applies to HPUserEdit, which seems to write binary codes for the special RPL characters that do not match the expected Unicodes.

To obtain the Unicode for an arbitrary character, just enter it as a string (or copy/paste it between two double-quotes, forming a one-character string) in ND1, and then run NUM (or unicode) on it. Convert to hexadecimal via HEX (or toHex) and use that code in JavaScript. ("\uhexCodeForChar")
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Re: Get and display remote code with mod'ed VISIT key

Postby sokol_22 » Thu Jan 05, 2012 11:03 am

How can one set up the sharing of files via http:// requests on a Windows 7 PC?

Posts: 9
Joined: Sat Oct 15, 2011 12:41 pm

Re: Get and display remote code with mod'ed VISIT key

Postby oliver » Thu Jan 05, 2012 11:22 am

Jiri, the easiest way would be to install IIS, if your Windows license includes it:

If you don't have IIS, you could also get and install Apache.

Apache can be run as a service or on as-needed basis launched from a cmd window.

But I believe IIS makes for an overall simpler experience.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Get and run remote code

Postby oliver » Thu Jan 05, 2012 1:17 pm

There's a new program in the Tools folder that permits to get and run remote code. It accepts a URL and will download the code associated with it and run it.

For the absolute fastest turn-around for development, have a separate key (defined in a menu, or, following the instructions above, a key on the menu pop-up) for each file you're working on, that contains a program like this
Code: Select all
≪ "" Tools.getCodeAndRun ≫

where myCode.js is the name of a specific code file. Any extension will work, but if it's ".js", a syntax check will take place.

For the key's name, the suggestion is to use the filename (myCode.js in the example).

The code will be stored in a variable that matches the basename of the path component of the URL. (myCode in this example.)
So, after using the function once, the remote code will be on your device where it can be run and edited.

This works with both JavaScript and RPL code. If your functions takes parameters, simply have them on the stack before hitting the key.

For JavaScript programs, make sure they are syntactically correct. If they're not, you're going to see a Parse Error with (currently) no detail provided. There're various free JavaScript syntax checker / lint checker available for both Mac and PCs.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Added code to defeat caching

Postby oliver » Fri Jan 06, 2012 1:20 pm

I improved the getURL function in Tools to defeat some servers' overaggressive caching.

If you found that the mod'ed VISIT key, or the getCodeAndRun function, would keep fetching old code and sometimes take many seconds or even minutes, before they pick up new content in your code file, this update should address this. Update Tools to get the improved code.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest