I am trying to substitude or replace the JSON-JavaScript-Object in case it is not available - what would be a neat way to achieve this?
Situation:
I have some code which uses JSON.parse and other functions to handle JSONs, but I have to migrate this code to be compatible to the Maple-Browser of a Samsung 2011-Series, which does not have a built-in JSON-Object.
jquery-1.6.2 lib is available; adding another lib is possible.
Solution attempts:
Found this nice blog http://www.greenhughes.com/content/experimental-couchdb-powered-samsung-internettv-app, which pretty much sums this problem up and even proviedes some solution. But this attempt seems to be 2 years old and I am looking for an improved solution.
Goal:
I would like to keep as much of my code as possible as it is and only handle somewhere the sitation, when a build-in JSON-Object is not available and then make it available in a way, that I do not have to change the calls to this Object.
Many thanks to any input or ideas to achieve this goal!
Related
I am trying to create a scenario that will work every time but I do not know how to deal with the uniquely hashed javascript and CSS. I could not find any answer in the documentation about that.
What I want specifically is the ability to pass a regex into my get but that is not possible since it only takes a string.
.get("/dist/precache-manifest.3efd6185a8d8559962673d45aed7ae98.js")
.headers(headers_0)
I expect a way to be able to somehow get the URL with a regex and then use it in my get above. Is there a way to do that in a Gatling scenario.
I found a way but its a hack and it takes a lot of time I am answering this because someone might want to use this way. However this could be considered a bug.
.get("").queryParam("", _ =>regex("""\/dist\/precache-manifest.[A-Za-z0-9]+.js"""))
.headers(headers_0),
I wondering if someone could help me. I'm new to TensorFlow.js (JavaScript version).
I've built a neural network and want to add a regularization term to the cost function (loss function).
I can see the regularizers in the JavaScript API documentation, but can't figure out how to use them. The layers can have some sort of regularizer associated with them, but the cost function is not defined in the layers, so I don't think this is what I'm looking for.
I had a look through the source code on GitHub. I found some open tickets that mentioned regularization. I also found a regularization function that applied the L2 or L1 norm to a vector. I can try and write a function that augments the cost function, using the regularization function, but I don't want to go to that much effort when a function already exists. The python version of TensorFlow does contain what I'm looking for. Does anyone know if what I'm looking for already exists in the javascript version and if so, how I implement it? Thanks.
Assuming that TensorFlow operates the same way in Python and Javascript, it looks like you do add regularisation of the weights to the cost function, via the layers. From a mathematical point-of-view, this is not exactly obvious, hence my question.
If you search the internet for regularisation of the loss function, in TensorFlow.js, there is nothing. However, if you read the python tutorials, they do provide an answer. I particularly found this website useful,
https://www.analyticsvidhya.com/blog/2018/04/fundamentals-deep-learning-regularization-techniques/
I'm working in a system where there is no document and no jQuery, but
I do have to present html entities in an understandable way. So the trick of putting the string in an element and then taking the .text() won't work.
I need a pure JavaScript solution. The system isn't reachable from the outside, there is no user-input so security is not really an issue.
Thanks for any help, I'm out of ideas (not that I had to many to begin with)...
Perhaps I should clarify, what I am looking for is a function (or pointers to get me pointing in the right direction) which is able to translate a string with substrings that should translate to characters. So it should be able to translate "blah < blahblah" into "blah < blahblah".
There are no additional frameworks I can use other than pure javascript.
UPDATE:
I've got the html4 part working, not extremely difficult, but I have been busy with other things. Here's the fiddle:html4 entities to characters.
You could have done the same with a dictionary with just the characters already in there, but I didn't feel like making such a dictionary. The function is fairly simple but I guess it could do with some refactoring, can't really be bothered at the moment...
This function exists in PHP (htmlspecialchars_decode). As such, you'll find a javascript port from PHPJS. This is based on a very established codebase, and should be better than rolling something on your own.
Edit / Add:
Flub on my part. I didn't read the entities part properly. You want the equiv of html_entity_decode:
http://phpjs.org/functions/html_entity_decode/
Assuming you are using nodejs, cheerio is exactly what you need. I have used it myself a couple of times with great success for off-browser testing of HTML structures returned from servers.
https://github.com/cheeriojs/cheerio
The most awesome part is that it uses jQuery API.
I'm developing a bookmarklet now and faced this task: I need to collect all prices from any page.
The problem is that the price may be in multiple formats ($19.00, 15.45$, etc), not counting different currencies and html markup. The good news is that I'm using jquery.
If anybody has an idea how it can be accomplish, please share :)
Thanks in advance!
If there is no consistent markup you're probably going to have to write some regex's for the known patterns. For example:
To capture a pattern like $19.00 you'll use a regex that looks something like this:
\$[0-9]*.?[0-9]{1,2}
Since you're target data is so unstructured i'm not sure there is a single good answer to this. You'll need to identify the patterns you are looking for and write the regex's to identify them.
Test your regular expressions here: http://regexpal.com/
Best of luck.
-R
I did some research months ago looking for a nice javascript template engine and settled on one made by Trimpath.
I like this a lot, but I have a few wish list items:
The code is rather big. I'd love something tiny, like John Resig's template engine, but easier to use.
I'd like support for includes, and django-style inheritance.
Are there any other great template engines which have been released in the past year or so which I should know about?
Update: I thought I'd come back and update this to let people know that we settled on Handlebars.js. We've got several months experience with it under our collective belts and we've been very happy with our choice. It has the basics included and you can create helpers that give you additional capabilities as needed.
There's also ICanHandlebarz (similar to ICanHaz for Mustache) and http://tryhandlebarsjs.com/ so you can try before you buy, so to speak.
I now return you to the original answer I gave.
We've been doing a survey of JavaScript template engines because there are so many and they have many different syntax and performance profiles (some compiled, some not, etc.).
Unfortunately our favorite solution was jQuery Templates and it worked great. Now it's deprecated software and the proposed replacement for it (JsRender) is no where near ready to use at the time I write this (Oct 2011). So while there are so many to choose from, after having a solution we were quite happy with, we are suddenly adrift again and trying to find its replacement.
Comparisons
http://wiki.jqueryui.com/w/page/37898666/Template
http://wiki.jqueryui.com/w/page/41375604/Template-Comparison
http://www.viget.com/extend/benchmarking-javascript-templating-libraries/
Template Loaders
http://icanhazjs.com/
https://github.com/Nijikokun/Templator
http://markdalgleish.com/projects/tmpload/
Engines
https://github.com/jquery/jquery-tmpl
https://github.com/BorisMoore/jsrender
http://code.google.com/p/jsmart/
https://github.com/janl/mustache.js
http://www.yajet.net/
http://code.google.com/p/trimpath/wiki/JavaScriptTemplates
http://embeddedjs.com/
http://beebole.com/pure/
http://akdubya.github.com/dustjs/
http://code.google.com/closure/templates/
https://github.com/wycats/handlebars.js/
http://code.google.com/p/kite/
http://twigkit.github.com/tempo/
https://github.com/aefxx/jQote2
https://github.com/trix/nano
http://viewjs.com/
http://documentcloud.github.com/underscore/#template
http://code.google.com/p/js-tempest/
https://github.com/creationix/haml-js
https://github.com/atduskgreg/srender
https://github.com/mikesamuel/jquery-jquery-tmpl-proposal