Giter Site home page Giter Site logo

Array length hint about schematic-ipsum HOT 8 OPEN

buzzm avatar buzzm commented on August 10, 2024
Array length hint

from schematic-ipsum.

Comments (8)

jonahkagan avatar jonahkagan commented on August 10, 2024

That's a good idea - it think it would be good to use the minItems and maxItems attributes for this (http://json-schema.org/latest/json-schema-validation.html#anchor42). Would you like to try implementing it?

from schematic-ipsum.

buzzm avatar buzzm commented on August 10, 2024

OK, so I took the bait. I did not have node on my OS X machine nor coffee so I started by getting that all set up. While drinking coffee, in fact.

Downloaded the ipsum source and ran it and "express" was not found.
Fortunately, I recalled seeing something about npm and realized it was probably very gem like (I am no expert at ruby either).
So I did 'nom install' and it appeared to download a healthy collection of things.
Reran node bin/server.js and got this:

Buzzs-MacBook-Pro:schematic-ipsum buzz$ node bin/server.js
undefined
/Users/buzz/tmp/schematic-ipsum/bin/../public
Schematic Ipsum listening on port 3000

I can curl http://localhost:3000 -d @f1.json where f1.json is the sample schema on the online site but it returns Bad type: "undefined" and the server output says

Bad type: "undefined"
POST / 400 80ms - 21

In fact, ANY content I POST to the server yields the same undefined error.

Any quick tips on debugging this? I am happy to try to add logic to the app and learn coffee and node and all but starting from a running app is a huge leg up. I am less of a framework person and more of an info arch / solutions design person (as the rants on moschetti.org might suggest).

On Nov 29, 2013, at 3:08 AM, Jonah Kagan [email protected] wrote:

That's a good idea - it think it would be good to use the minItems and maxItems attributes for this (http://json-schema.org/latest/json-schema-validation.html#anchor42). Would you like to try implementing it?


Reply to this email directly or view it on GitHub.

from schematic-ipsum.

buzzm avatar buzzm commented on August 10, 2024

So I did this:
app.post("/", function(req, res) {
return async.waterfall([
function(done) {
console.log("inbound body: " + req.body);
console.log( JSON.stringify(req.body, null, 4) );

My client side curl is this:

curl -d '{ "type": "string"}' http://localhost:3000

And this is what gets printed:

inbound body: [object Object]
{
"{ "type": "string"}": ""
}

Yow! The entire input is being parsed into the key and value is blank.
There must be some sort of pilot error on my part. Any clues? BTW, I know where the maxItems minItems logic should go and am excited to give that a crack.

On Nov 29, 2013, at 12:50 PM, Buzz Moschetti [email protected] wrote:

OK, so I took the bait. I did not have node on my OS X machine nor coffee so I started by getting that all set up. While drinking coffee, in fact.

Downloaded the ipsum source and ran it and "express" was not found.
Fortunately, I recalled seeing something about npm and realized it was probably very gem like (I am no expert at ruby either).
So I did 'nom install' and it appeared to download a healthy collection of things.
Reran node bin/server.js and got this:

Buzzs-MacBook-Pro:schematic-ipsum buzz$ node bin/server.js
undefined
/Users/buzz/tmp/schematic-ipsum/bin/../public
Schematic Ipsum listening on port 3000

I can curl http://localhost:3000 -d @f1.json where f1.json is the sample schema on the online site but it returns Bad type: "undefined" and the server output says

Bad type: "undefined"
POST / 400 80ms - 21

In fact, ANY content I POST to the server yields the same undefined error.

Any quick tips on debugging this? I am happy to try to add logic to the app and learn coffee and node and all but starting from a running app is a huge leg up. I am less of a framework person and more of an info arch / solutions design person (as the rants on moschetti.org might suggest).

On Nov 29, 2013, at 3:08 AM, Jonah Kagan [email protected] wrote:

That's a good idea - it think it would be good to use the minItems and maxItems attributes for this (http://json-schema.org/latest/json-schema-validation.html#anchor42). Would you like to try implementing it?


Reply to this email directly or view it on GitHub.

from schematic-ipsum.

jonahkagan avatar jonahkagan commented on August 10, 2024

It looks like curl -d sends form encoded data using the syntax key=val. If you want to just send a JSON string, you have to add a header like so: curl localhost:3000 -H "Content-Type: application/json" -d '{"type":"string"}'.

Hopefully that will get you on the right track! Sorry for not including instructions about npm install - I've added them now. Also, you can use ./run.sh to run a development server.

It might be useful to add some tests for min/maxItems before you start - then you can just test your implementation using make test instead of curl.

from schematic-ipsum.

buzzm avatar buzzm commented on August 10, 2024

Success! Thanks.
OK, now onto making the mods. Ageed with adding the tests first. Test-driven development is choice.

On Nov 29, 2013, at 2:49 PM, Jonah Kagan [email protected] wrote:

"Content-Type: application/json"

from schematic-ipsum.

buzzm avatar buzzm commented on August 10, 2024

In my excitement I put the min/max array aside and change the MAX_ITEMS from 50 100000.
The schema file from the online site gets up to n=81 OK. With n=82, something goes bad here (I put in a null check and a hardcode for crutch at the moment):

readFile = function(files, done) {
return fs.readFile(_.randomFrom(files), "utf8", function(err, contents) {
if(contents == null) {
console.log("?!? contents null reading files: " + err);
return done(err, [ "Buzz", "M" ]);
} else {
return done(err, contents.split("\n"));
}
});
};

The err is #define EMFILE 24 /* Too many open files */

So I am guessing that those data files are open but not closed. Will take a look at that, too.

On Nov 29, 2013, at 4:15 PM, Buzz Moschetti [email protected] wrote:

Success! Thanks.
OK, now onto making the mods. Ageed with adding the tests first. Test-driven development is choice.

On Nov 29, 2013, at 2:49 PM, Jonah Kagan [email protected] wrote:

"Content-Type: application/json"

from schematic-ipsum.

buzzm avatar buzzm commented on August 10, 2024

These are the mods I have in the making, now that I learned coffeescript, installed node.js, etc. etc.

  1. Increase MAX_ITEMS from 50 to 10000000. I need to generate some BIG lists....
  2. Add minItems/maxItems optional hints to array type to permit varying size arrays (instead of just between 1 and 5)
  3. Fix existing array logic so that one and only one entry could be created with minItems = 1 and maxItems = 1
  4. (Brace yourself) Change the readFile function to use fs.readFileSync. The async version for large values of n on the command line would exhaust the file descriptor supply. Initial tests show essentially no change in performance, especially since the same process in the OS is going after the same file and it's probably all in OS cache......
  5. Add an ipsum hint called counter that auto increments an integer. Very useful for generate large sequences of messages and other ordinal things.

from schematic-ipsum.

buzzm avatar buzzm commented on August 10, 2024

Folks: Due to my struggling with coffeescript and out-of-memory errors stemming from the creation of a big list that gets stringified at the very end, I have abandoned making changes to this codebase and reimplemented it in python. And Java, too, actually. Thanks to Jonah for providing a good path to follow.

from schematic-ipsum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.