Converting Java code to JS (jsweet error) - javascript

I wrote a code in Java which gets number of each piece type and fills some area with tetris block and print filled array.
I wanted to make website (probably on github.io, no server) which calculates this and print for other users.
I wrote the code in Eclipse(jdk 12.0.2) and no error on it.
But when I convert code with JSweet, it gave me some errors:
1.
final EnumMap<P,Integer> M = new EnumMap<>(P.class);
->type 'P' does not satisfy the constraint 'Enum<P>'
2.
EnumMap<P,Integer> M = (something);
Iterator<Piece> P = new ArrayList<>(M.keySet().iterator());
->property 'slice' does not exist on type 'Set<P>'
Then I found GWT, but it seems like wont work without server... I tried it but it failed.
How to fix errors on JSweet? Or is there other apps to convert Java code to js?
(This is my first project in Java and Eclipse, and newbie in js)

Related

converting vanitygenplus into javascript

I'm currently working on converting vanitygenplus (https://github.com/exploitagency/vanitygen-plus) from C into JavaScript to run in a web-browser.
As I dont really know C ive been going almost line by line converting what I need and setting the rest to remarks for now. but now I reached this:
pkey = EC_KEY_new_by_curve_name(NID_secp256k1);
Is this creating a random key or just creating a holder for the key, and what form would that be in?

Different names - JS and CS

Im Trying to get to the same text on JS and on CS
JS CODE:
var LblSits = document.getElementById('<%=SelectedSits.ClientID%>');
LblSits.textContent+= NumId;
CS Code:
int Sits = int.Parse(SelectedSits.Text);
When i Run This , i can see the SelectedSits Label updating with numbers
but when im trying to Debug it from the CS its always empty ("").
the diffrence of the names driving me crazy.
same happened to me With ImageUrl on CS and src on JS until i figured it out.
Which name connected to whom?
What can i do?
Why is that always empty?
From the C# code, you can only see content that is changed in JavaScript code for specific controls that support sending the changes made by JavaScript on the client back to the server.
Instead of using a Label, use a TextBox or HiddenField control.

Javascript charCodeAt not reading correct codes

I was trying to host a code of mine from Khan Academy on my own website.
The processing code works alright on Khan Academy. But while hosting it I am facing some issues.
The problem is - Khan Academy's processing is able to read unicode value of certain characters correctly, but when I do the same offline from the browser it gets incorrectly shown.
I think it has to do with the charCodeAt function not working correctly.
Here's my code :-
var test = "Ĭ";
println(test);
println(test.charCodeAt(0));
On Khan Academy the unicode is correctly printed as 300. Wherease my browser prints it as 196. Whats more the string is interpreted as 2 characters instead of 1 from the browser. It's size is shown as 2.
How to make the charCodeAt to work correctly.
Please note that I am making use of Processing JS and here is the code I am making use of to host a Processing Canvas :-
var sketchProc=function(processingInstance){ with (processingInstance) {
size(400, 400);
frameRate(60);
var test = "Ĭ";
var n = test.codePointAt(0);
println(n);
println(String.fromCharCode(300));
println(test.length);
}};
Thanks.
Based on the comment of AlexandrKapustin, I was able to resolve the problem.
I added the following meta tag to the html file hosting the Processing script :-
<meta charset="utf-16">

JS giving wrong value when executing thru selenium web driver

I am using JS to find out the number of classes of certain type. When I execute JS in webdriver, it gives me the wrong value. When I execute the same JS on Firebug console, it gives me the right value.
Webdriver:
Returns 0
int Rects = ((IJavaScriptExecutor)driver).ExecuteScript<int>(" $('.optimization.flighting .interval').size()");
Returns 4
$('.optimization.flighting .interval').size()
Without more information on the page itself, those elements you are trying to target, version of jQuery etc etc, I can only guess at an answer (which I will happily delete if proven wrong), but I suspect it's being the JavascriptExecutor needs a little more pushing when returning values:
int Rects = ((IJavaScriptExecutor)driver).ExecuteScript<int>("return $('.optimization.flighting .interval').size()");
Specifically, adding the return statement before the actual Javascript, in a similar way you can add return to C# methods.
(Also, why you are not using the built in element finding mechanisms?)

Max/MSP JavaScript distortion possible?

I'm trying to help a friend to figure out if it's possible to implement DSP algorithms in Max/MSP javascript. He was told so in class, and he asked for my help but I can't find any way to process actual samples.
TL;DR
Is it possible to get samples in and return them out in Max/MSP using javascript?
Thanks
No, it's not, as it's made only for processing messages and not signal vectors. Probably you mixed JavaScript with Java — there is a mxj~ object which allows you to use Java 6 (not higher!) for developing signal processing algorithms. Check out the tutorial, which everyone starts to learn how to use Java with: http://pcm.peabody.jhu.edu/~gwright/stdmp/docs/WritingMaxExternalsInJava.pdf
You can write DSP algorithms using Max’s gen~ and codebox, the syntax for which resembles JavaScript or C.
DSP in Max runs at high priority to avoid audio dropouts, which the js object does not, but it is possible to generate code using JavaScript and load that into a gen~ instance. You can find an example of this bundled with Max itself: search for a file called gen~.dynamicexpr.maxpat
They released a node.js API with Max 8. You can now.
Though not using javascript, like delucis said you can now use gen~ to write dsp code.
Here's a distortion gen~ function using tanh for my own project:
tanh_dist(input, amp, offset)
{
pass1 = input + offset;
pass2 = pass1 * amp;
pass3 = tanh(pass2);
return(dcblock(pass3));
}
I also made a sample patch to show you how to use it (in the codebox). Just copy the following text and paste into an empty max patch window:
----------begin_max5_patcher----------
1168.3ocyW8tbiZCD+y3mBF9TROWOHAXG2qsyzGf9Db4FOxfLVWAACH74bYx
8r2U+ALXv13j3zlOPFu+jzt6uc0tZedhky5r8zRG6ey9K1VVOOwxRIRJvx7a
KmTx9vDRoZYNgYooTtvYpFSP2KTxy1rojJdjWCjSDgaY73UEzPgVA3kAybmZ
iWH+hBbk+yyelq8WM6gWkx3ITgRSnCBypD0RcMRYQZst9a+Jx0QJ6kISjel9
F8CRZ94cBWzAmve9rf2EeX9qwE1jjAGbsstIqHknLx4FIfgvRgEHU4rZkBmv
AgnKFrl6K+piUX704m3994xCLaAIkJnEqnbx5DZadQeDhmxoZSwwYpsyZBO1
w9q2ZZJnOMgOPdCvSnkKj4.uy7zh+C3IN86fp6cgH7ovD5OsQv0ryvBttGxV
lGbdV.OHKf5yBANmxSKYwbRxqyOiIL9Ouru3gvp5TK0+J3RwzzpDAKbKgyoI
6HELBWzNXcwPt+qJjaHBHv+5HC5OhHgifM7cWp9WP82qIzNPAOry6WFZLcLw
SLVEOwH+ymc5M1rSzkyNaaTzBimYbMnTDKgtiVTxx3sTgkCIOukXqVaQxGeK
ScPOLsQDiqE41HpftiUueuFojBfZD.uTUnrTm8yqS5jGSVDsfWwTlhVHDYLl
jJFvgzxxbRndyQk4y.lu9.bZ2hbt5lybcgf4lLHYwwZJAhzwIYg+CMpsg6jk
S4LddAsDZMSDFOnANhtg.2xVsIiKJY+PYGpaoCfuwXmCBJ8DkS7Wv8zjFWHt
fEkwkFQm3gTbs5fzo.8yWZ6LpUvI4C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