webapp2 WSGIApplication initialization - webapp2

The webapp2.WSGIApplication class is initialized with three arguments:
routes: list of tuples
debug: enable / disable debug mode
config: dictionary of config values
Why is the first argument a list of tuples and not a dictionary?

My guess is that the order of the tuples is important, and a dictionary has no order.
app = webapp2.WSGIApplication([
('/this page', ThisPageHandler),
('.*', FrontPage),
],debug=False)
If that was your app above, it's important to catch the /this_page route before the catch all .* is caught. A list preserves order where a dictionary does not.

Related

Hydra - Cannot override value in instantiate

I am developing a project based on the pytorch lightning + hydra template found here https://github.com/ashleve/lightning-hydra-template. I am trying to instantiate a Pytorch dataset object using hydra instantiate, overriding the default cfg value with the DictConfig object. Specifically, I have this config file:
...
training_dataset:
_target_: src.datamodules.components.baseline_datasets.FSD50K
cfg: omegaconf.dictconfig.DictConfig(content={})
mode: "training"
...
While the pytorch lightning datamodule does the following:
class AudioTagDataModule(LightningDataModule):
def __init__(self, cfg: DictConfig):
super().__init__()
self.cfg = cfg
self.save_hyperparameters(logger=False)
def setup(self, stage: Optional[str] = None):
self.trainset = instantiate(self.cfg.datamodule.training_dataset, cfg=self.cfg)
...
The rest of the code is pretty much unmodified from the template. However, when the pytorch dataset is instantiated, I get an error due to the config being empty. Checking in debug, I see that the config value is not being overridden, despite having the same name that was specified in the configs. Could someone provide some guidance on why the override is not working and how to correctly proceed? Thank!
Looking at the AudioTagDataModule, I see that the setup method passes a cfg=self.cfg keyword argument to the instantiate function. This is why the cfg setting from your training_dataset config is not showing up in your instantiated dataset; the keyword argument is taking precedence. Based on the code you posted, it would probably make sense to pass an empty DictConfig to AudioTagDataModule.__init__ instead of defining a cfg key/value in training_dataset.
Another thing: in your yaml file, you'd probably want cfg: {} instead of cfg: omegaconf.dictconfig.DictConfig(content={}), as the latter will result in the python string "omegaconf.dictconfig.DictConfig(content={})" and the former will result in an empty DictConfig.

How to pass in a list of Partys for invocation of a flow from the Node shell

How to pass in a list of Partys for invocation of a flow from the Node shell?
I had tried multiple ways such as passing in as a string (with multiple ways). Do i need to pass in a Json? or what is the format?
thanks for your question. The syntax for passing in lists of elements in the Corda CRaSH shell is:
flow start fabFlow parties: ["party1", "party2"]
The syntax for creating complicated objects can be found here but in essence is just a simple wrapping with curly braces to provide arguments to appropriate invocation params:
data class Campaign(val name: String, val target: Int)
newCampaign: { name: Roger, target: 1000 }

Pulling date data with onclick var

I am trying to setup a send to email on click with app maker, one of my objects that sends is the date. I have this code for pulling that data:
var todayDate = widget.parent.parent.descendants.Field.value
I then get this error when testing the date data entries:
Failed due to illegal value in property: 4
at (unknown)
at (unknown)
at Inbound_Call.Container.Form1.Form1Header.Form1Spinner.visible:-1:132
at (unknown)
at (unknown)
at (unknown)
at Inbound_Call.Container.Form1.Form1Footer.Form1SubmitButton.onClick:7:40
Assuming that you are trying to make server call to send an email, smth like this:
google.script.run.myServerFunction(myDate, otherParam1, otherParam2);
I can suggest that call fails due to App Script parameters constraints:
Legal parameters are JavaScript primitives like a Number, Boolean, String, or null, as well as JavaScript objects and arrays that are composed of primitives, objects, and arrays. A form element within the page is also legal as a parameter, but it must be the function’s only parameter. Requests fail if you attempt to pass a Date, Function, DOM element besides a form, or other prohibited type, including prohibited types inside objects or arrays. Objects that create circular references will also fail, and undefined fields within arrays become null....

how to deal with duplicated named parameters /:uuid/:uuid on an HTTP router

When creating an HTTP router, is common to see this pattern:
/get/:user --> /get/username
/get/:book/:page/ --> /get/book/3
The handlers for the request can call a method the one will return the matching name, for example:
get(":user") and that return "username"
get(":book") and that return "book"
..
In most cases a key/value map is used for storing this pairs, but what could be a best practice to deal with named parameters that have different values but share the same name, for example a hash or an UUID, example:
/get/:uuid/:uuid/ --> get/36146E6-D7EB-421C-9F7D-5F676A481A00/E122DA77-171E-4FAB-91CB-C724BF25B772
One "practice" I have found is to save the key and an array with the values in the order of appearance, something like:
:uuid = [uuid0, uuid1]
that way, the getting of the params can be consistent:
get(":uuid") return array of UUIDS instead of only the first uuid
Probably a best practice could be to avoid using duplicated params names, and that could solve all this, but there are cases when the same regex/method is tight to the same named parameter and is desired to avoid duplication code just with a different name, I mean something like
:uuid1 = uuidgen()
:uuid2 = uuidgen()
So would like to know what could be a best approach for dealing with this cases.

Meteor publish null or un-named record set

Being new to javascript and surly baby in Meteor. I could not make sense reading this part of the docs. about Meteor.publish(name, func)
Arguments
name String
Name of the record set. If null, the set has no name, and the record set is automatically sent to all connected clients.
I take it that record set means Meteor Collection, if that is correct, then how can a publish action take place on a collection with name "null" or even a collection with no name as stated? I mean, where is the collection to publish if the first parameter "that collection name" is null or does not exist? Thanks
The name parameter in Meteor.publish has absolutely nothing to do with the collection. While the convention is that you should have similar naming to what collection(s) you're using, you could literally call a publish function "asdjfsaidfj" and it would be valid. As yudap said, what data you're sending to the client is entirely determined in the function. You can also return data from multiple collections using an array:
return [
ExampleCollection.find(),
AnotherCollection.find()
];
If you publish data with null argument:
Meteor.publish(null, func)
Basically it is the same as you autopublish without autopublish package. That's mean you don't need to subscribe and you don't need to install autopublish package. The data is ready in client and reactive and you can use it in whatever template without subscribing.
where is the collection to publish? Whatever collection you want to autopublish. Just define it in func:
Meteor.publish(null, function () {
CollectionName.find({}, {
/*
sort: Sort specifier,
skip: Number,
limit: Number,
fields: Field specifier,
reactive: Boolean,
transform: Function
*/
});
});

Resources