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">
Related
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)
I'm using this online tool to create the JavaScript code required to obfuscate an email address with an ROT13 cipher and it works fine, however I get the below JS ReferenceError when using it:
ReferenceError: eo is not defined
Here is the code I am using:
<span id="obf">
<script>document.getElementById("obf").innerHTML="<n uers=\"znvygb:vasb#zzjgenqrznexf.pbz.nh\" >vasb#zzjgenqrznexf.pbz.nh</n>".replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});document.body.appendChild(eo);</script>
<noscript>[Enable JavaScript to see email]</noscript>
</span>
This bit of code at the end of the script appears to be the culprit:
document.body.appendChild(eo);
Any idea what the issue is?
Try this ... the last part of the script is just plain wrong:
<span id="obf">
<script>document.getElementById("obf").innerHTML="<n uers=\"znvygb:vasb#zzjgenqrznexf.pbz.nh\" >vasb#zzjgenqrznexf.pbz.nh</n>".replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});</script>
<noscript>[Enable JavaScript to see email]</noscript>
</span>
Check out his GitHub. It has some more instructions, including that you should first obfuscate the mail though javascript. Like devnull69 mentioned, that last part can be omitted. And it is indeed omitted in the documentation on GitHub.
EDIT: Checking out the HTML of the page, the eo object is indeed used for something. Check out line 58 and line 144
I've been playing with snippets for Atom editor,
and see that I've learned I can include
JavaScript inside of a snippet, as my example shows.
(It inserts a TODO Comment with date)
TODO: (RAM) Fix this - 2014-11-23 20:55
HELLO
How can I include MORE JavaScript.?
For example
inside the snippet to set
var= to something
or
call a JS library
or
ask for input from user i.e. confirm();
and proceed on basis of confirm() function.
Any help would be appreciated, I looked for a long time,
but not much documentation on this. Submlime Text's snippets allowed lots of code to be inserted via Python.
Thanks
~Rob
Inside file snippets.cson
'.source.js':
'Date TODO: insert':
'prefix': 'datetd'
'body': """
TODO: (RAM) $1 - #{datetime = new Date(); datetime.getFullYear()}-#{(datetime.getMonth()+1)}-#{datetime.getDate()} #{datetime.getHours()}:#{datetime.getMinutes()}
#{"hello".toUpperCase(); }
$2
"""
Update: With the merge of atom/atom#4791, the capability of putting CoffeeScript code in CSON configuration files has been removed from Atom. The rest of the answer has been left intact for historic reference.
Actually, the syntax of the file is CoffeeScript (hence .cson as in CoffeeScript Object Notation), not JavaScript. It just so happens that you typed in JavaScript that is allowed as CoffeeScript. CoffeeScript doesn't use the var keyword, so you can assign variables like you did in your example:
datetime = new Date()
The other items, you'll probably have to get a little creative. I don't believe that the snippets package was intended to be used in this manner, which is why the lack of documentation on the "feature".
The title probably isn't saying much at all, but hopefully it got someone interested.
The actual problem is quite simple.
I want to make a web application that loads JavaScript code dynamically (might even be a hardcoded string) as a string, then I want to run that code line by line and analyze the debug info every step.
Basically, I need a JavaScript interpreter/debugger written in JavaScript.
Hopefully, I'd be able to do something like this
var source = "var a = 5; var b = a; b = 6"
var vm = new VirtualMachine(source);
vm.step();
vm.getDebugInfo();
and it would tell me about the local variables and their values.
This project hasn't been updated in a while but maybe you could build something for your purpose around it
https://github.com/jterrace/js.js/ - A JavaScript JavaScript interpreter
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
KmTx9vDRoZ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