问:
Getting BackbaseConfigurationException while serverstartup (Webshpere 8.5.5)
However the config file for which it complains is at the correct location I checked 10 times.

Please help

```<code>[26-2-17 15:27:38:716 CET] 00000045 webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [BA621 PBI Portal Manager#portalserver.war]:.Initializing Spring FrameworkServlet 'Portal Foundation Spring MVC'
[26-2-17 15:27:38:718 CET] 00000045 SystemOut     O 15:27:38.718 Portal Foundation [server.startup : 1] --  ERROR c.b.p.f.p.r.PortalDispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationDao' defined in URL [wsjar:file:/C:/data/apps/BA621%20PBI%20Portal%20Manager.ear/portalserver.war/WEB-INF/lib/com.backbase.portal.foundation-configuration-5.6.3.0.jar!/com/backbase/portal/foundation/integration/configuration/impl/ConfigurationDaoImpl.class]: Invocation of init method failed; nested exception is com.backbase.portal.commons.configuration.exceptions.BackbaseConfigurationException: No configuration file could be found at location: c:datawasbsbconfigeditorialdeviceConfig.xml
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1513) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) ~[spring-web-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) ~[spring-web-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1704) ~[com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:411) ~[com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:169) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:749) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:634) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:426) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:718) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1177) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1370) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:639) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:968) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:776) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.ApplicationMgrImpl$5.run(ApplicationMgrImpl.java:2195) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5477) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5603) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2200) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:435) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:378) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$500(CompositionUnitMgrImpl.java:126) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:984) [com.ibm.ws.runtime.jar:na]
    at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:502) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1881) [com.ibm.ws.runtime.jar:na]
Caused by: com.backbase.portal.commons.configuration.exceptions.BackbaseConfigurationException: No configuration file could be found at location: c:datawasbsbconfigeditorialdeviceConfig.xml
    at com.backbase.portal.foundation.integration.configuration.impl.ConfigurationDaoImpl.afterPropertiesSet(ConfigurationDaoImpl.java:139) ~[com.backbase.portal.foundation-configuration-5.6.3.0.jar:5.6.3.0-2016-12-09 22:03]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1572) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1510) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    ... 37 common frames omitted
</code>```

答: I think this problem is because of the path of config file. Try to use forward slash '/' instead of '\' and see if that solves the problem.</p>

Body:
However the config file for which it complains is at the correct location I checked 10 times.

Please help

[26-2-17 15:27:38:716 CET] 00000045 webapp        I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [BA621 PBI Portal Manager#portalserver.war]:.Initializing Spring FrameworkServlet 'Portal Foundation Spring MVC'
[26-2-17 15:27:38:718 CET] 00000045 SystemOut     O 15:27:38.718 Portal Foundation [server.startup : 1] --  ERROR c.b.p.f.p.r.PortalDispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationDao' defined in URL [wsjar:file:/C:/data/apps/BA621%20PBI%20Portal%20Manager.ear/portalserver.war/WEB-INF/lib/com.backbase.portal.foundation-configuration-5.6.3.0.jar!/com/backbase/portal/foundation/integration/configuration/impl/ConfigurationDaoImpl.class]: Invocation of init method failed; nested exception is com.backbase.portal.commons.configuration.exceptions.BackbaseConfigurationException: No configuration file could be found at location: c:datawasbsbconfigeditorialdeviceConfig.xml
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1513) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:633) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[spring-context-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) ~[spring-web-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) ~[spring-web-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1704) ~[com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:411) ~[com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:88) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:169) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:749) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:634) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:426) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:718) [com.ibm.ws.webcontainer.jar:na]
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1177) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1370) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:639) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:968) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:776) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.ApplicationMgrImpl$5.run(ApplicationMgrImpl.java:2195) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5477) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5603) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2200) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:435) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:378) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$500(CompositionUnitMgrImpl.java:126) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:984) [com.ibm.ws.runtime.jar:na]
    at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:502) [com.ibm.ws.runtime.jar:na]
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1881) [com.ibm.ws.runtime.jar:na]
Caused by: com.backbase.portal.commons.configuration.exceptions.BackbaseConfigurationException: No configuration file could be found at location: c:datawasbsbconfigeditorialdeviceConfig.xml
    at com.backbase.portal.foundation.integration.configuration.impl.ConfigurationDaoImpl.afterPropertiesSet(ConfigurationDaoImpl.java:139) ~[com.backbase.portal.foundation-configuration-5.6.3.0.jar:5.6.3.0-2016-12-09 22:03]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1572) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1510) ~[spring-beans-3.2.10.RELEASE.jar:3.2.10.RELEASE]
    ... 37 common frames omitted


来源: stackexchange

问:
Python--creating a class that adds a key to dictionary object + attaches specific values
First, here's my goal: I want to be able to add keys to a dictionary, and have those keys associated with a number of values. For example, I want to be able to have something like:

myDict['myKey1'].height
myDict['myKey1'].weight

I want to be able to add new keys to this, like myDict['myKey2'] such that I also have the option of attaching height and weight values to the new key as above.

Here's what I've got so far:

```<code>class Vividict(dict):
    def __missing__(self, key):
        value = self[key] = type(self)()
        return value
</code>```

I've been using the above class to add new keys to dictionaries. I want to not only do this, but also input lists so that I can look up things like "height" and "weight" for the new key I add to my dictionary, by adding something like this into my class.

```<code>def __init__(self, list_of_vals, list_of_names):

    for x,y in zip(list_of_vals, list_of_names):
        self.(y) = x
</code>```

I know the above is wrong, but I hope someone can see what I'm trying to achieve here. I want to define a class such that I can add a new key to a dictionary, and provide "list_of_vals" and "list_of_names" to attach some items to that dictionary key.

So, if I have "newKey" with list_of_vals=[1,2,3] and list_of_names=['height', 'weight', 'whatever'], I want to be able to do this:

```<code>myDict['newKey'].height = 1
myDict['newKey'].weight = 2
myDict['newKey'].whatever = 3
</code>```

I hope this makes sense. I'm sort of trying to mimic what I can do in Matlab using structures.

Thanks!

----Update----

```<code>import collections

class Vals:

    def add(self, list_of_vals=[], list_of_names=[]):
        for val, name in zip(list_of_vals, list_of_names):
            setattr(self, name, val)

    def __str__(self):
        return str(self.__dict__)

mydict = collections.defaultdict(Vals)
mydict['Foo'].add([1,2], ['height', 'weight'])
</code>```

The above from tdelaney is in the direction I want to move. Thanks!

If I take the above code to add height and weight attributes. I want to be able to add to these if they exist. For example, something like:

```<code>mydict['Foo'].add([3,4], ['height'])
</code>```

Such that is results in:

```<code>mydict['Foo'].height = [1,2,3,4]
</code>```

In other words, I add [3,4] to the height attribute for the 'Foo' key.

Another feature I'd like to build into this class is to concatenate new rows into a numpy array each time I add new lists of numbers. For example, if I start with this:

```<code>mydict['Foo'].add([1,2], ['height', 'weight'])
</code>```

And then do this:

```<code>mydict['Foo'].add([3,4], ['height', 'weight'])
</code>```

I want to end with the following:

```<code>mydict['Foo'].height = [1,3]
mydict['Foo'].weight = [2,4]
mydict['Foo'].array = [1, 2; 3, 4]
</code>```

In other words, I'm adding to the height and weight attributes each time, allowing me to add to growing lists with new data. At the same time, I want to the class to initialize an empty numpy array that we will add to row by row, such that each row contains height and weight, column 1 containing multiple height values, column 2 containing multiple weight values, and each row gets concatenated to the bottom of the array each time.

答:
I think idiomatic Python would avoid creating a custom class for something like this. Instead you could use a namedtuple for the dict entries, and just use a dict comprehension as your constructor:

```<code>>>> from collections import namedtuple

>>> list_of_names = ["Clumsy", "Smurfette"]
>>> list_of_vals = [[1,2,3],[4,5,6]]

>>> Smurf = namedtuple("Smurf", ("height", "weight", "whatever"))

>>> mydict = {k:Smurf(*v) for k,v in zip(list_of_names, list_of_vals)}
>>> print(mydict)

{'Clumsy': Smurf(height=1, weight=2, whatever=3), 'Smurfette': Smurf(height=4, weight=5, whatever=6)}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
First, here's my goal: I want to be able to add keys to a dictionary, and have those keys associated with a number of values. For example, I want to be able to have something like:

myDict['myKey1'].height
myDict['myKey1'].weight

I want to be able to add new keys to this, like myDict['myKey2'] such that I also have the option of attaching height and weight values to the new key as above.

Here's what I've got so far:

class Vividict(dict):
    def __missing__(self, key):
        value = self[key] = type(self)()
        return value

I've been using the above class to add new keys to dictionaries. I want to not only do this, but also input lists so that I can look up things like "height" and "weight" for the new key I add to my dictionary, by adding something like this into my class.

def __init__(self, list_of_vals, list_of_names):

    for x,y in zip(list_of_vals, list_of_names):
        self.(y) = x

I know the above is wrong, but I hope someone can see what I'm trying to achieve here. I want to define a class such that I can add a new key to a dictionary, and provide "list_of_vals" and "list_of_names" to attach some items to that dictionary key.

So, if I have "newKey" with list_of_vals=[1,2,3] and list_of_names=['height', 'weight', 'whatever'], I want to be able to do this:

myDict['newKey'].height = 1
myDict['newKey'].weight = 2
myDict['newKey'].whatever = 3

I hope this makes sense. I'm sort of trying to mimic what I can do in Matlab using structures.

Thanks!

----Update----

import collections

class Vals:

    def add(self, list_of_vals=[], list_of_names=[]):
        for val, name in zip(list_of_vals, list_of_names):
            setattr(self, name, val)

    def __str__(self):
        return str(self.__dict__)

mydict = collections.defaultdict(Vals)
mydict['Foo'].add([1,2], ['height', 'weight'])

The above from tdelaney is in the direction I want to move. Thanks!

If I take the above code to add height and weight attributes. I want to be able to add to these if they exist. For example, something like:

mydict['Foo'].add([3,4], ['height'])

Such that is results in:

mydict['Foo'].height = [1,2,3,4]

In other words, I add [3,4] to the height attribute for the 'Foo' key.

Another feature I'd like to build into this class is to concatenate new rows into a numpy array each time I add new lists of numbers. For example, if I start with this:

mydict['Foo'].add([1,2], ['height', 'weight'])

And then do this:

mydict['Foo'].add([3,4], ['height', 'weight'])

I want to end with the following:

mydict['Foo'].height = [1,3]
mydict['Foo'].weight = [2,4]
mydict['Foo'].array = [1, 2; 3, 4]

In other words, I'm adding to the height and weight attributes each time, allowing me to add to growing lists with new data. At the same time, I want to the class to initialize an empty numpy array that we will add to row by row, such that each row contains height and weight, column 1 containing multiple height values, column 2 containing multiple weight values, and each row gets concatenated to the bottom of the array each time.

Body:
I think idiomatic Python would avoid creating a custom class for something like this. Instead you could use a namedtuple for the dict entries, and just use a dict comprehension as your constructor:

>>> from collections import namedtuple

>>> list_of_names = ["Clumsy", "Smurfette"]
>>> list_of_vals = [[1,2,3],[4,5,6]]

>>> Smurf = namedtuple("Smurf", ("height", "weight", "whatever"))

>>> mydict = {k:Smurf(*v) for k,v in zip(list_of_names, list_of_vals)}
>>> print(mydict)

{'Clumsy': Smurf(height=1, weight=2, whatever=3), 'Smurfette': Smurf(height=4, weight=5, whatever=6)}


问:
How do I get "Page Attributes" option in Cocoa print dialog?
The program I'm writing runs under OS X 10.5 Leopard. My target has its Base SDK and Deployment Target both set to Mac OS X 10.5. When I initiate printing, my print dialog doesn't show the Page Attributes option in which the user can select page size and orientation.

Other programs running under Leopard do show this option:

Here's the code that initiates printing:

```<code>-(void)print {
    NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
    TemperaturePressurePrintView *printView = [[TemperaturePressurePrintView alloc] initWithFrequencies:frequencies];
    if (printView) {
        [[NSPrintOperation printOperationWithView:printView printInfo:printInfo] runOperation];
        [printView release];
    }
}
</code>```

What do I need to do to get Page Attributes to show up in my print dialog?

答:
It's a few years after the original answer and macOS Sierra seems to have introduced a bug into the behaviour of panels that have the 'NSPrintPanelShowsPageSetupAccessory' option set. Invalid values, such as a ridiculously large scale, cause crashes instead of displaying an alert sheet.

Fortunately there is a workaround. Using

```<code>NSPrintPanelShowsPaperSize | NSPrintPanelShowsOrientation | NSPrintPanelShowsScaling
</code>```

instead seems to result in a panel that works fine.

Body:
The program I'm writing runs under OS X 10.5 Leopard. My target has its Base SDK and Deployment Target both set to Mac OS X 10.5. When I initiate printing, my print dialog doesn't show the Page Attributes option in which the user can select page size and orientation.

Other programs running under Leopard do show this option:

Here's the code that initiates printing:

-(void)print {
    NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
    TemperaturePressurePrintView *printView = [[TemperaturePressurePrintView alloc] initWithFrequencies:frequencies];
    if (printView) {
        [[NSPrintOperation printOperationWithView:printView printInfo:printInfo] runOperation];
        [printView release];
    }
}

What do I need to do to get Page Attributes to show up in my print dialog?

Body:
It's a few years after the original answer and macOS Sierra seems to have introduced a bug into the behaviour of panels that have the 'NSPrintPanelShowsPageSetupAccessory' option set. Invalid values, such as a ridiculously large scale, cause crashes instead of displaying an alert sheet.

Fortunately there is a workaround. Using

NSPrintPanelShowsPaperSize | NSPrintPanelShowsOrientation | NSPrintPanelShowsScaling

instead seems to result in a panel that works fine.


问:
Centering SVG inside an SVG
I am working on a project where we need to let users upload their SVG and give them an ability to perform certain modifications on them.

For that, we have defined a root level SVG and group within which user uploaded SVG will be rendered.

The problem I am facing is that different SVG with different ViewBox settings get rendered at different location in the root SVG. I have attached sample images of this and a fiddle to play with it: https://jsfiddle.net/gsp4k6n7/2/

Here is the code that loads up the SVG in the root:

```<code>loadImage = function(svgData) {
   var root = document.getElementById('__root_group__');
   root.innerHTML = svgData;
}
</code>```

I have tried transform: translate(x, y) but that does not seem to work in every case. For example, the following code was able to center the first image with DigitalOcean logo, but the second image was way off center.

```<code>alignImage = function() {
  var svg = document.getElementById('__root_svg__');
  var group = document.getElementById('__root_group__');

  var sr = svg.getBoundingClientRect();
  var gr = group.getBoundingClientRect();

  var x = (sr.width - gr.width) / 2;
  var y = (sr.height - gr.height) / 2;

  group.setAttribute('transform', `translate(${x},${y})`);
}
</code>```

What is the best way to center align all of the imported SVG both horizontally and vertically in the root SVG?

Title: Centering SVG inside an SVG

Body:
I am working on a project where we need to let users upload their SVG and give them an ability to perform certain modifications on them.

For that, we have defined a root level SVG and group within which user uploaded SVG will be rendered.

The problem I am facing is that different SVG with different ViewBox settings get rendered at different location in the root SVG. I have attached sample images of this and a fiddle to play with it: https://jsfiddle.net/gsp4k6n7/2/

Here is the code that loads up the SVG in the root:

loadImage = function(svgData) {
   var root = document.getElementById('__root_group__');
   root.innerHTML = svgData;
}

I have tried transform: translate(x, y) but that does not seem to work in every case. For example, the following code was able to center the first image with DigitalOcean logo, but the second image was way off center.

alignImage = function() {
  var svg = document.getElementById('__root_svg__');
  var group = document.getElementById('__root_group__');

  var sr = svg.getBoundingClientRect();
  var gr = group.getBoundingClientRect();

  var x = (sr.width - gr.width) / 2;
  var y = (sr.height - gr.height) / 2;

  group.setAttribute('transform', `translate(${x},${y})`);
}

What is the best way to center align all of the imported SVG both horizontally and vertically in the root SVG?

Body:
If you don't need a root SVG you can simply use plain css.

See fiddle

var VB_REGEX = /viewBox="(\d+) (\d+) (\d+) (\d+)"/g;

var img1 = `
<?xml version="1.0" encoding="UTF-8"?>
<svg width="256px" height="192px" viewBox="0 0 256 192" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
 <g fill="#0080FF">
  <path d="M127.806368,103.431977 L127.806368,128.137065 C169.680136,128.137065 202.283513,87.6839887 188.5857,43.8050085 C182.599796,24.6296657 167.363082,9.39295184 148.187739,3.40704816 C104.308759,-10.2907649 63.8549575,22.3133371 63.8549575,64.1871048 L88.6166119,64.1871048 C88.620238,64.1871048 88.6231388,64.1805779 88.6231388,64.1805779 C88.6267649,37.901779 114.633609,17.5849518 142.262028,27.610289 C152.497677,31.3248272 160.662119,39.4878187 164.378833,49.7227422 C174.405673,77.3349616 154.119391,103.331553 127.862935,103.368844 L127.862935,78.7435694 C127.862935,78.7435694 127.860759,78.742119 127.858584,78.742119 L103.173076,78.742119 C103.170901,78.742119 103.168725,78.745745 103.168725,78.745745 L103.168725,103.431977 L127.806368,103.431977 Z M103.164374,122.405711 L84.1971671,122.405711 L84.1928159,122.40136 L84.1928159,103.431977 L103.168725,103.431977 L103.168725,122.40136 C103.168725,122.40136 103.16655,122.405711 103.164374,122.405711 Z M84.2058697,103.431977 L68.3055864,103.431977 C68.2990595,103.431977 68.293983,103.427626 68.293983,103.427626 L68.293983,87.5345949 C68.293983,87.5345949 68.2990595,87.5229915 68.3055864,87.5229915 L84.1942663,87.5229915 C84.2007932,87.5229915 84.2058697,87.528068 84.2058697,87.528068 L84.2058697,103.431977 Z"></path>
  <path d="M22.0964986,153.197507 C18.8772805,150.963853 14.8712068,149.831796 10.1899603,149.831796 L0,149.831796 L0,182.161042 L10.1899603,182.161042 C14.8596034,182.161042 18.8671275,180.965892 22.1001246,178.611127 C23.8594901,177.362312 25.241745,175.61745 26.2091785,173.426584 C27.1715354,171.24732 27.6596034,168.676442 27.6596034,165.78647 C27.6596034,162.929858 27.1715354,160.39234 26.2084533,158.243535 C25.241745,156.084578 23.8580397,154.386856 22.0964986,153.197507 Z M5.9518187,155.296272 L9.15000567,155.296272 C12.7086232,155.296272 15.6377564,155.996102 17.8590822,157.379082 C20.3248045,158.865768 21.575796,161.694096 21.575796,165.78647 C21.575796,170.001405 20.3219037,172.957371 17.8503796,174.57532 L17.848204,174.57532 C15.7211558,175.982232 12.8094278,176.695841 9.19424363,176.695841 L5.9518187,176.695841 L5.9518187,155.296272 Z M31.8332011,182.161042 L37.5631048,182.161042 L37.5631048,159.390822 L31.8332011,159.390822 L31.8332011,182.161042 Z M34.7529065,149.433654 C33.7738697,149.433654 32.9297224,149.781031 32.2501983,150.46128 C31.5626969,151.116147 31.2138697,151.946516 31.2138697,152.929178 C31.2138697,153.908215 31.5605212,154.751637 32.245847,155.436238 C32.9297224,156.121564 33.7738697,156.468941 34.7529065,156.468941 C35.7319433,156.468941 36.5753654,156.121564 37.2606912,155.436238 C37.9467422,154.750912 38.2933938,153.90749 38.2933938,152.929178 C38.2933938,151.947966 37.9445666,151.117598 37.2606912,150.465632 C36.5753654,149.781031 35.7319433,149.433654 34.7529065,149.433654 Z M58.3709008,161.293054 C56.6434448,159.756329 54.7143796,158.859966 52.6279433,158.859966 C49.4652918,158.859966 46.8363966,159.954312 44.8152295,162.109643 C42.7686799,164.248295 41.7301756,167.000476 41.7301756,170.289314 C41.7301756,173.503456 42.752,176.24621 44.7717167,178.445779 C46.8073881,180.573552 49.4507875,181.651943 52.6279433,181.651943 C54.8369405,181.651943 56.7355467,181.036963 58.2831501,179.822232 L58.2831501,180.346561 C58.2831501,182.235739 57.7769518,183.705745 56.7797847,184.715241 C55.7833428,185.723286 54.4010878,186.233836 52.6729065,186.233836 C50.0280567,186.233836 48.370221,185.194606 46.3519547,182.467082 L42.4503116,186.215705 L42.5554674,186.363649 C43.3981643,187.54647 44.6890425,188.703909 46.3925666,189.804057 C48.0968159,190.899127 50.2390935,191.456091 52.7606572,191.456091 C56.1626289,191.456091 58.914085,190.407433 60.9403286,188.339853 C62.9781756,186.261394 64.0116034,183.478028 64.0116034,180.070255 L64.0116034,159.390822 L58.3709008,159.390822 L58.3709008,161.293054 Z M56.8682606,174.741394 C55.8667422,175.878527 54.5809405,176.429688 52.9376091,176.429688 C51.2950028,176.429688 50.0164533,175.878527 49.0294391,174.742844 C48.0475014,173.612238 47.5485552,172.113949 47.5485552,170.289314 C47.5485552,168.434946 48.0475014,166.917802 49.0301643,165.779218 C50.0033994,164.652963 51.3182096,164.081496 52.9376091,164.081496 C54.5794901,164.081496 55.866017,164.637008 56.8675354,165.782119 C57.8654278,166.919977 58.3709008,168.436397 58.3709008,170.289314 C58.3709008,172.113224 57.8654278,173.611513 56.8682606,174.741394 Z M68.9154901,182.161042 L74.6453938,182.161042 L74.6453938,159.390822 L68.9154901,159.390822 L68.9154901,182.161042 Z M71.8359207,149.433654 C70.8561586,149.433654 70.0120113,149.781031 69.3324873,150.46128 C68.6449858,151.116147 68.2961586,151.946516 68.2961586,152.929178 C68.2961586,153.908215 68.6428102,154.751637 69.328136,155.436238 C70.0120113,156.121564 70.8561586,156.468941 71.8359207,156.468941 C72.8142323,156.468941 73.6576544,156.121564 74.3437054,155.436238 C75.0290312,154.750912 75.3756827,153.90749 75.3756827,152.929178 C75.3756827,151.947966 75.0268555,151.117598 74.3437054,150.465632 C73.6576544,149.781031 72.8142323,149.433654 71.8359207,149.433654 Z M87.203898,153.238844 L81.5631955,153.238844 L81.5631955,159.390822 L78.2874108,159.390822 L78.2874108,164.613076 L81.5631955,164.613076 L81.5631955,174.071297 C81.5631955,177.03089 82.1542436,179.14851 83.3211105,180.364691 C84.4908782,181.586674 86.5678867,182.206006 89.4948442,182.206006 C90.426017,182.206006 91.3629915,182.174822 92.2789348,182.115354 L92.5371105,182.097949 L92.5371105,176.880045 L90.5725099,176.983025 C89.2083853,176.983025 88.2975184,176.74298 87.8645666,176.271592 C87.425813,175.792227 87.203898,174.77838 87.203898,173.259059 L87.203898,164.613076 L92.5371105,164.613076 L92.5371105,159.390822 L87.203898,159.390822 L87.203898,153.238844 Z M112.201972,161.094346 L112.201246,161.094346 C110.465088,159.612011 108.064635,158.859966 105.068057,158.859966 C103.161473,158.859966 101.378901,159.278414 99.7660283,160.096453 C98.2742663,160.85285 96.8093371,162.106017 95.8781643,163.745722 L95.9361813,163.815343 L99.6050312,167.327547 C101.116374,164.918391 102.796691,164.081496 105.024544,164.081496 C106.22187,164.081496 107.215411,164.402765 107.979059,165.035875 C108.738357,165.664635 109.108215,166.464544 109.108215,167.478391 L109.108215,168.58434 C107.687524,168.152113 106.270459,167.933099 104.89183,167.933099 C102.040295,167.933099 99.7203399,168.603921 97.9965099,169.926708 C96.2509235,171.266176 95.3661643,173.182187 95.3661643,175.622527 C95.3661643,177.761904 96.1124079,179.499513 97.5889405,180.791841 C99.0785269,182.037756 100.939422,182.670867 103.121586,182.670867 C105.303025,182.670867 107.343773,181.791184 109.196691,180.286368 L109.196691,182.161042 L114.838119,182.161042 L114.838119,167.523354 C114.838119,164.751592 113.951184,162.589008 112.201972,161.094346 Z M102.028691,173.459943 C102.678482,173.006686 103.596601,172.778244 104.758391,172.778244 C106.137745,172.778244 107.600499,173.055275 109.108215,173.602085 L109.108215,175.835739 C107.863025,176.993178 106.199388,177.580601 104.162266,177.580601 C103.170176,177.580601 102.399275,177.360136 101.869144,176.924283 C101.349167,176.497858 101.096068,175.955399 101.096068,175.267898 C101.096068,174.486844 101.401382,173.895071 102.028691,173.459943 Z M119.403331,182.161042 L125.133235,182.161042 L125.133235,149.831796 L119.403331,149.831796 L119.403331,182.161042 Z M145.922176,182.648385 C136.732283,182.648385 129.256068,175.17217 129.256068,165.981552 C129.256068,156.79166 136.732283,149.315445 145.922176,149.315445 C155.112068,149.315445 162.588283,156.79166 162.588283,165.981552 C162.588283,175.17217 155.112068,182.648385 145.922176,182.648385 Z M145.922176,155.188941 C139.971082,155.188941 135.129564,160.030459 135.129564,165.981552 C135.129564,171.933371 139.971082,176.774164 145.922176,176.774164 C151.873269,176.774164 156.714788,171.933371 156.714788,165.981552 C156.714788,160.030459 151.873269,155.188941 145.922176,155.188941 Z M183.018969,174.019082 C181.994244,175.167819 180.945586,176.163535 180.1377,176.681337 L180.1377,176.682062 C179.345768,177.190436 178.3457,177.448612 177.166504,177.448612 C175.47821,177.448612 174.120612,176.833632 173.014663,175.567411 C171.915241,174.307717 171.357552,172.689042 171.357552,170.75345 C171.357552,168.818584 171.907989,167.202085 172.993632,165.951819 C174.085076,164.69285 175.435422,164.081496 177.122266,164.081496 C178.967932,164.081496 180.913677,165.228782 182.580941,167.200635 L186.368,163.568771 C183.898652,160.355354 180.749054,158.859966 176.990278,158.859966 C173.843581,158.859966 171.116782,160.005802 168.885303,162.264839 C166.664703,164.507195 165.539173,167.363807 165.539173,170.75345 C165.539173,174.143819 166.663977,177.006958 168.881677,179.264544 C171.101552,181.524306 173.829802,182.670867 176.990278,182.670867 C181.138493,182.670867 184.486799,180.879592 186.744385,177.598731 L183.018969,174.019082 Z M206.535433,162.572329 C205.723195,161.439547 204.616521,160.52868 203.24587,159.86221 C201.878844,159.19719 200.285552,158.859966 198.510958,158.859966 C195.312771,158.859966 192.695479,160.039887 190.730153,162.369269 C188.822844,164.680521 187.856861,167.553088 187.856861,170.908646 C187.856861,174.359207 188.917122,177.215819 191.00936,179.397983 C193.089269,181.569269 195.874085,182.670867 199.285484,182.670867 C203.149416,182.670867 206.320045,181.108034 208.708895,178.025881 L208.837983,177.859807 L205.100238,174.26783 C204.753586,174.685552 204.262618,175.159841 203.814436,175.581915 C203.248771,176.115671 202.71719,176.529042 202.148623,176.811875 C201.292147,177.2383 200.331966,177.448612 199.257201,177.448612 C197.669711,177.448612 196.354901,176.981575 195.349756,176.060555 C194.409881,175.199003 193.86017,174.037212 193.714402,172.602017 L208.89455,172.602017 L208.94604,170.510504 C208.94604,169.030346 208.744431,167.604578 208.347014,166.271637 C207.949598,164.936521 207.339694,163.691331 206.535433,162.572329 Z M194.012465,167.933099 C194.288045,166.84383 194.789892,165.936589 195.508578,165.232408 C196.28528,164.468034 197.295501,164.081496 198.512408,164.081496 C199.90119,164.081496 200.97668,164.476011 201.707694,165.25779 C202.385768,165.980102 202.767955,166.879365 202.847728,167.933099 L194.012465,167.933099 Z M228.53983,161.094346 L228.539105,161.094346 C226.802946,159.612011 224.402493,158.859966 221.405915,158.859966 C219.499331,158.859966 217.716759,159.278414 216.103887,160.096453 C214.611399,160.85285 213.14647,162.106017 212.216023,163.745722 L212.27404,163.815343 L215.94289,167.327547 C217.454232,164.918391 219.13455,164.081496 221.362402,164.081496 C222.559728,164.081496 223.553269,164.402765 224.316918,165.035875 C225.076215,165.664635 225.446074,166.464544 225.446074,167.478391 L225.446074,168.58434 C224.024657,168.152113 222.608317,167.933099 221.228963,167.933099 C218.378153,167.933099 216.057473,168.603921 214.334368,169.926708 C212.588782,171.266176 211.704023,173.182187 211.704023,175.622527 C211.704023,177.761904 212.450266,179.499513 213.926799,180.791841 C215.41566,182.037756 217.27728,182.670867 219.459445,182.670867 C221.640884,182.670867 223.681632,181.791184 225.533824,180.286368 L225.533824,182.161042 L231.175977,182.161042 L231.175977,167.523354 C231.175977,164.751592 230.289042,162.589008 228.53983,161.094346 Z M218.36655,173.459943 C219.01634,173.006686 219.934459,172.778244 221.096249,172.778244 C222.475603,172.778244 223.938357,173.055275 225.446074,173.602085 L225.446074,175.835739 C224.200159,176.993178 222.537246,177.580601 220.499399,177.580601 C219.508034,177.580601 218.737133,177.360136 218.207003,176.924283 C217.687025,176.497858 217.433926,175.955399 217.433926,175.267898 C217.433926,174.486844 217.739241,173.895071 218.36655,173.459943 Z M253.218085,161.541076 C251.621892,159.762856 249.379535,158.859966 246.551207,158.859966 C244.278391,158.859966 242.432,159.512657 241.051195,160.800635 L241.051195,159.390822 L235.432249,159.390822 L235.432249,182.161042 L241.162153,182.161042 L241.162153,169.603263 C241.162153,167.877983 241.572623,166.508057 242.38196,165.53047 C243.189847,164.555785 244.300147,164.081496 245.77668,164.081496 C247.07481,164.081496 248.058198,164.50502 248.784136,165.376 C249.512975,166.251331 249.882108,167.456635 249.882108,168.962176 L249.882108,182.161042 L255.612011,182.161042 L255.612011,168.962176 C255.612011,165.808227 254.807025,163.312045 253.218085,161.541076 Z"></path>
 </g>
</svg>
`;

var img2 = `
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<svg version="1.1" id="Calque_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
  viewBox="0 0 432 432" style="enable-background:new 0 0 432 432;" xml:space="preserve">
<style type="text/css">
 .st0{fill:#C77B32;}
 .st1{fill:#65C8D0;}
 .st2{fill:#838BC5;}
 .st3{fill:#404041;}
 .st4{fill:#D87985;}
</style>
<g>
 <path d="M192.8,191.2c-0.5,0.9-1,1.8-1.5,2.7c-2.1,4.1-4.1,8.3-6.3,12.4c-2.2,4.1-4.5,8.2-6.9,12.2c-0.7,1.2-1.6,2.2-2.5,3.2
  c-2.1,2.3-5.1,2.1-7.1-0.3c-0.6-0.8-1.2-1.7-1.7-2.6c-2.1-4.5-3.4-9.2-3.9-14.2c-0.2-2.1-0.5-4.2-0.5-6.3c-0.1-3.6,0-7.2,0.1-10.8
  c0.1-2.7,0.3-5.3,0.5-8c0.1-1.7,0.3-3.3,0.6-5c0.2-1.2,0.6-2.4,1.5-3.4c1.7-1.8,4.4-1.6,5.8,0.5c1,1.4,1.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,0.4,12.9c-0.1,4.2,0.2,8.4,0.2,12.6
   C254,266.1,254,268.7,254,271.3C254,271.3,254,271.3,254,271.3z"/>
 </g>
 <path class="st0" d="M318.5,326.4c-6.7-0.3-13.3-0.5-20-0.8c-7.1-0.3-14.2-0.8-21.3-1.1c-6.4-0.3-12.8-0.4-19.2-0.5
  c-5.1-0.1-10.1-0.1-15.2,0c-5.2,0.1-10.5,0.2-15.7,0.5c-9.3,0.6-18.7,1.3-28,2.2c-7.8,0.7-15.6,1.7-23.3,3
  c-6.3,1.1-12.5,2.1-18.7,3.4c-7.6,1.5-15.1,3.2-22.6,4.9c-0.3,0.1-0.6,0.2-0.9,0.2c-0.6,0.1-1-0.2-1.2-0.8c-0.2-0.5,0-1,0.5-1.2
  c0.6-0.4,1.3-0.7,1.9-1c3.6-1.6,7.4-2.6,11.2-3.5c5-1.2,10-2.3,15-3.3c6.6-1.3,13.2-2.5,19.8-3.5c6.5-1,13-1.8,19.5-2.6
  c5-0.6,9.9-1.1,14.9-1.5c6.5-0.5,13-1,19.5-1.3c4.8-0.3,9.7-0.3,14.5-0.4c3.6-0.1,7.1-0.1,10.7-0.1c4.8,0.1,9.7,0.2,14.5,0.3
  c2.6,0.1,5.2,0.2,7.8,0.3c4.5,0.2,8.9,0.5,13.4,0.8c4.3,0.3,8.7,0.8,13,1.1c3,0.3,6.1,0.5,9.1,0.8c3.3,0.3,6.6,0.6,9.9,1
  c0.4,0,0.8,0.2,1.1,0.4c0.6,0.3,0.8,0.9,0.7,1.5c-0.1,0.7-0.4,1.2-1,1.4c-0.4,0.2-0.9,0.2-1.4,0.2
  C324.1,326.7,321.3,326.6,318.5,326.4C318.5,326.5,318.5,326.4,318.5,326.4z"/>
 <g>
  <path class="st1" d="M320.6,163.6c0,1.8-0.6,3.4-1.4,4.9c-1.9,3.5-4.6,6.3-8.1,8.1c-3.2,1.7-6.4,3.4-9.8,4.7
   c-2.3,0.9-4.8,1.2-7.2,1.8c-0.8,0.2-1.5-0.1-2-0.8c-0.5-0.7-0.5-1.5-0.1-2.3c0.7-1.1,1.4-2.2,2.3-3.2c2.1-2.6,4.1-5.2,6.4-7.6
   c3-3.3,6.4-6.2,10.2-8.6c1.1-0.7,2.3-1.2,3.5-1.6C317.9,157.9,320.6,159.9,320.6,163.6z"/>
  <path class="st1" d="M294.9,186.5c6.1,0.3,11.5,2,15.9,6c1.9,1.7,3.2,3.9,3,6.6c-0.1,1.7-1,3-2.7,3.6c-2,0.7-4.1,0.8-6.1,0
   c-1.4-0.6-2.9-1.2-4.3-1.8c-2.1-0.9-3.9-2.4-5.3-4.1c-1.6-1.8-3-3.8-4.1-6c-1.3-2.5,0.1-3.6,2.2-4.2
   C294.1,186.5,294.7,186.6,294.9,186.5z"/>
 </g>
 <g>
  <path class="st1" d="M93.3,163.5c0.1-2.3,1.4-4.1,3.3-4.7c1.1-0.3,2.1-0.1,3.2,0.2c2.5,0.9,4.7,2.4,6.8,4
   c4.4,3.4,8.2,7.5,11.7,11.8c1.1,1.4,2.1,2.8,3.1,4.2c0.3,0.4,0.5,0.9,0.7,1.4c0.5,1.4-0.8,2.9-2.1,2.6c-1.4-0.3-2.8-0.6-4.2-0.9
   c-3.3-0.7-6.3-2.3-9.3-3.8c-2.1-1.1-4.2-2.1-6.1-3.5c-3.1-2.3-5.4-5.3-6.6-9C93.5,165.2,93.4,164.3,93.3,163.5z"/>
  <path class="st1" d="M119.2,186.5c0.8-0.1,1.8,0.1,2.7,0.7c1.2,0.8,1.5,1.7,0.9,3c-0.9,1.9-2.1,3.7-3.4,5.4
   c-2.5,3.3-5.8,5.5-9.7,6.8c-1.5,0.5-2.9,1.1-4.5,0.8c-0.9-0.1-1.8-0.3-2.7-0.6c-1.3-0.5-2.1-1.5-2.4-2.9c-0.2-1.1-0.1-2.3,0.4-3.4
   c0.9-2.2,2.4-3.9,4.3-5.2C109,188.2,113.8,186.8,119.2,186.5z"/>
 </g>
</g>
</svg>
`;

loadImage = function(img) {
  var root = document.getElementById('root');
  var svg = '';

  if (img === 1) {
    svg = img1;
  } else {
    svg = img2;
  }

  var vb = VB_REGEX.exec(svg);

  if (!vb) {
    window.setTimeout(function() {
      window.loadImage(img);
    }, 0);

    return;
  }

  document.getElementsByClassName('viewbox')[0].innerText =
    `{ x: ${vb[1]}, y: ${vb[2]}, width: ${vb[3]}, height: ${vb[4]} }`;

  root.innerHTML = svg;
}

body {
  padding: 15px;
}

.canvas {
  background-color: #fff;
  height: 475px;
  width: 655px;
  display: flex;
  align-items: center;
  justify-content: center;
}

svg {
  max-width: 80%;
  height: 80%;
}

.actions {
  margin-top: 15px;
}

<div id="root" class="canvas">
</div>
<div class="actions">
  <button onclick="window.loadImage(1);">Load Image 1</button>
  <button onclick="window.loadImage(2);">Load Image 2</button>
  <strong>ViewBox:</strong>
  <span class="viewbox"></span>
</div>


问:
Submit button must be clicked twice to Submit form - Java Script fix not working
My form submit button has to be clicked twice before the form will submit. My professor gave me some Java Script code, which I've implemented below, that will click the submit button twice automatically, but it is not working.

My form action is shown below:

```<code><form name="com" id="com" action="<?php if (($_POST['email'] != NULL) && ($_POST['comment'] != NULL) && ($_POST['fname'] != NULL) && ($_POST['lname'] != NULL)) {
echo "leavehandle.php";
$submit == "true";
} else {
echo "leave.php";
} ?>" method="post">
</code>```

I also have this PHP script outside of my closing form tag:

```<code><?php
if ($submit == "true") {
echo"<script>document.getElementById('com').submit();</script> ";
} ?>
</code>```

My form submit button still needs to be clicked twice before the form will submit. Any help would be much appreciated - I don't have much experience with Java Script!

Thank you!

Edit:

I adjusted my code in the form action to the following:

```<code><form name="com" id="com" action="<?php echo "leavehandle.php";
if ($submit == "true"){
} else {
echo "leave.php";
} ?>" method="post">
</code>```

Do I need the PHP opening tag in the first part of the form action? Also, I'm not sure where to place the other code for validating the form in my leavehandle.php.

Leavehandle.php:

```<code><!DOCTYPE html>
<html> <!--Opening HTML tag-->
<div align="center"> <!--Aligns content center-->
<head>
<?php //pulls in my header from another PHP page using Inlcude()
include("header.php");
?>
</head>
<style>
html {
font-family:arial;
background-color:#ffcc99;
}
</style>
<body>
<?php
include('mysqli_connect.php');

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$query = "INSERT INTO guestbook (id, email, fname, lname, date, comment)     VALUES (NULL, '$email', '$fname', '$lname', NOW(), '$comment');";

$result = mysqli_query($dbc, $query);

if ($result) {
echo "Thank you for submitting a comment $fname!";
}
else {
echo "ERROR";
}

?>
</body>
<?php //pulls in my footer from another PHP page using Inlcude()
include("footer.php");
?>
</div>
</html>
</code>```

答:
So here is hot it would be your form part

```<code><form name="com" id="com" action="leavehandle.php" method="post">
</code>```

your leavehandle.php fixed

<!DOCTYPE html>

<?php //pulls in my header from another PHP page using Inlcude()
include("header.php");
?>

<?php
include('mysqli_connect.php');

//set vars to null
$fname = $lname = $email = $comment = "";

//validade post

if(!empty($_POST['fname'])&&!empty($_POST['lname'])&&!empty($_POST['email'])&&!empty($_POST['comment'])) {

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$query = "INSERT INTO guestbook (id, email, fname, lname, date, comment)     VALUES (NULL, '$email', '$fname', '$lname', NOW(), '$comment');";

$result = mysqli_query($dbc, $query);

} else {

 //redirect to error page is is null
 header("Location: leave.php");
}

if ($result) {
echo "Thank you for submitting a comment $fname!";
}
else {
echo "ERROR";
}

?>

<?php //pulls in my footer from another PHP page using Inlcude()
include("footer.php");
?>

```

Body:
My form submit button has to be clicked twice before the form will submit. My professor gave me some Java Script code, which I've implemented below, that will click the submit button twice automatically, but it is not working.

My form action is shown below:

<form name="com" id="com" action="<?php if (($_POST['email'] != NULL) && ($_POST['comment'] != NULL) && ($_POST['fname'] != NULL) && ($_POST['lname'] != NULL)) {
echo "leavehandle.php";
$submit == "true";
} else {
echo "leave.php";
} ?>" method="post">

I also have this PHP script outside of my closing form tag:

<?php
if ($submit == "true") {
echo" ";
} ?>

My form submit button still needs to be clicked twice before the form will submit. Any help would be much appreciated - I don't have much experience with Java Script!

Thank you!

Edit:

I adjusted my code in the form action to the following:

<form name="com" id="com" action="<?php echo "leavehandle.php";
if ($submit == "true"){
} else {
echo "leave.php";
} ?>" method="post">

Do I need the PHP opening tag in the first part of the form action? Also, I'm not sure where to place the other code for validating the form in my leavehandle.php.

Leavehandle.php:

<!DOCTYPE html>

<?php //pulls in my header from another PHP page using Inlcude()
include("header.php");
?>

<?php
include('mysqli_connect.php');

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$query = "INSERT INTO guestbook (id, email, fname, lname, date, comment)     VALUES (NULL, '$email', '$fname', '$lname', NOW(), '$comment');";

$result = mysqli_query($dbc, $query);

if ($result) {
echo "Thank you for submitting a comment $fname!";
}
else {
echo "ERROR";
}

?>

<?php //pulls in my footer from another PHP page using Inlcude()
include("footer.php");
?>

Body:
So here is hot it would be your form part

<form name="com" id="com" action="leavehandle.php" method="post">

your leavehandle.php fixed

<!DOCTYPE html>
<html> <!--Opening HTML tag-->
<div align="center"> <!--Aligns content center-->
<head>
<?php //pulls in my header from another PHP page using Inlcude()
include("header.php");
?>
</head>
<style>
html {
font-family:arial;
background-color:#ffcc99;
}
</style>
<body>
<?php
include('mysqli_connect.php');

//set vars to null
$fname = $lname = $email = $comment = "";

//validade post

if(!empty($_POST['fname'])&&!empty($_POST['lname'])&&!empty($_POST['email'])&&!empty($_POST['comment'])) {

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$query = "INSERT INTO guestbook (id, email, fname, lname, date, comment)     VALUES (NULL, '$email', '$fname', '$lname', NOW(), '$comment');";

$result = mysqli_query($dbc, $query);

} else {

 //redirect to error page is is null
 header("Location: leave.php");
}

if ($result) {
echo "Thank you for submitting a comment $fname!";
}
else {
echo "ERROR";
}

?>
</body>
<?php //pulls in my footer from another PHP page using Inlcude()
include("footer.php");
?>
</div>
</html>


问:
need help finding the context free grammar of these languages
I need help finding the grammar of these languages.
I feel like I am getting nowhere with these solution

1) {a^h b^k a^m b^n | h + k = m + n}

2) {a^i b^j a^k |  (i = j and k ≥ 0) or (i ≥ 0 and j > k)}

any help would be appreciated

答:
I assume you're looking for context-free grammars. I'll use the convention that S is the root production rule and that upper-case words are rules (like S, AB, A, etc.), the empty production is written empty and that literals are written as 'a' and 'b'.

The first grammar is:

```<code>S := AB
AB := 'a' AB 'b' | AA | BB
AA := 'a' AA 'a' | BA
BB := 'b' BB 'b' | BA
BA := 'b' BA 'a' | empty
</code>```

The trick here is to realise that to keep the two halves the same length, one has to define grammar productions that add one symbol on either side. Then to note that we start by adding 'a' to the left, and 'b' to the right, and from there we proceed either adding 'a' to both sides, or 'b' to both sides, and finally proceed to adding 'b' to the left and 'a' to the right.

The second grammar is:

```<code>S := AB A | A B BA
AB := 'a' AB 'b' | empty
A := 'a' A | empty
B := 'b' B | 'b'
BA := 'b' BA 'a' | empty
</code>```

This is easier than the first: the root production is already given as a choice of two things, so it's natural to express that in the rule. The first choice to to generate some number of 'a's followed by the same number of 'b's and then any number of 'a's. The second choice is to generate some number of 'a's, then some positive number of 'b's and then an equal number of 'b's and 'a's. That guarantees that "j>k" in the description of that choice.

Neither grammar here is unambiguous, although it's only a little more complicated to remove the ambiguities.

Body:
I assume you're looking for context-free grammars. I'll use the convention that S is the root production rule and that upper-case words are rules (like S, AB, A, etc.), the empty production is written empty and that literals are written as 'a' and 'b'.

The first grammar is:

S := AB
AB := 'a' AB 'b' | AA | BB
AA := 'a' AA 'a' | BA
BB := 'b' BB 'b' | BA
BA := 'b' BA 'a' | empty

The trick here is to realise that to keep the two halves the same length, one has to define grammar productions that add one symbol on either side. Then to note that we start by adding 'a' to the left, and 'b' to the right, and from there we proceed either adding 'a' to both sides, or 'b' to both sides, and finally proceed to adding 'b' to the left and 'a' to the right.

The second grammar is:

S := AB A | A B BA
AB := 'a' AB 'b' | empty
A := 'a' A | empty
B := 'b' B | 'b'
BA := 'b' BA 'a' | empty

This is easier than the first: the root production is already given as a choice of two things, so it's natural to express that in the rule. The first choice to to generate some number of 'a's followed by the same number of 'b's and then any number of 'a's. The second choice is to generate some number of 'a's, then some positive number of 'b's and then an equal number of 'b's and 'a's. That guarantees that "j>k" in the description of that choice.

Neither grammar here is unambiguous, although it's only a little more complicated to remove the ambiguities.


问:
MongoMapper - Full Text Search
Using this command directly on the database I get the results I am after

```<code>db.products.find({$text: {$search: "some product"}}, {score: {$meta: "textScore"}}).sort({score:{$meta:"textScore"}})
</code>```

But using it in MongoMapper I am getting errors.
The search without the score field doesn't produce any errors

```<code>@products = Product.where(
    '$text' => {'$search' => @search_string}
)
</code>```

However, when I try to add the sort field is where I get issues

```<code>@products = Product.where(
    '$text' => {'$search' => @search_string}, :score => {'$meta' => "textScore"}
)
</code>```

Mongo::OperationFailure at /search unknown operator: $meta

It also fails using the raw query method

```<code>@products = MongoMapper.database['products'].find(
    '$text' => {'$search' => @search_string}, :score => {'$meta' => "textScore"}
)
</code>```

The full query I am trying to run is

```<code> @products = Product.where(
    '$text' => {'$search' => @search_string},:score => {'$meta' => "textScore"}
).sort(:score => {'$meta' => "textScore"}).limit(5)
</code>```

This gives the error

Mongo::OperationFailure at /search must have $meta projection for all $meta sort keys

Does anyone have suggestions of where I am going wrong? I assume I am using it wrong.

Installed version. mongo_mapper (0.14.0, 0.13.1)

答:
A user on the MongoMapper Google group has pointed me in the right direction</p>

```<code>@products = Product.where(
'$text' => {'$search' => @search_string}).fields(:score => {'$meta' => "textScore"})
</code>```

Title: MongoMapper - Full Text Search

Body:
Using this command directly on the database I get the results I am after

db.products.find({$text: {$search: "some product"}}, {score: {$meta: "textScore"}}).sort({score:{$meta:"textScore"}})

But using it in MongoMapper I am getting errors.
The search without the score field doesn't produce any errors

@products = Product.where(
    '$text' => {'$search' => @search_string}
)

However, when I try to add the sort field is where I get issues

@products = Product.where(
    '$text' => {'$search' => @search_string}, :score => {'$meta' => "textScore"}
)

Mongo::OperationFailure at /search unknown operator: $meta

It also fails using the raw query method

@products = MongoMapper.database['products'].find(
    '$text' => {'$search' => @search_string}, :score => {'$meta' => "textScore"}
)

The full query I am trying to run is

 @products = Product.where(
    '$text' => {'$search' => @search_string},:score => {'$meta' => "textScore"}
).sort(:score => {'$meta' => "textScore"}).limit(5)

This gives the error

Mongo::OperationFailure at /search must have $meta projection for all $meta sort keys

Does anyone have suggestions of where I am going wrong? I assume I am using it wrong.

Installed version. mongo_mapper (0.14.0, 0.13.1)

Body:
A user on the MongoMapper Google group has pointed me in the right direction

@products = Product.where(
'$text' => {'$search' => @search_string}).fields(:score => {'$meta' => "textScore"})


问:
python csv.reader method fails when called within the object used in its argument
I am using csv.reader(), but it fails when I use it from a method within a class if the argument to reader() is that object itself (i.e., "self).  The failure is non-intuitive.  When I call csv.reader() from outside the object, all is well.  Can somebody explain what conceptual error I've made?  Hope my explanation makes some sense: it probably is easier to read/invoke the code.

You can see that in main I first invoke the readDirList() method directly, and everything is happy.  However, if I invoke the readDirList() method of the dirList class (which is supposed to do the same thing), I get the odd "no next() method" error.  Befuddled, I am.

Thanks for taking a look!

(am using python 2.7.6 in Linux Mint 17.3)  Also BTW I get the same area if in main I omit the "mdl" stuff and jump right to the "mdl2" stuff.
    #!/usr/bin/python
    # example: why csv.reader.next() doe not work

```<code>import csv

class dirList(object):
    def __init__(self):
        self.inFile = None
        return
    # a dirList object is iterable so that csv.reader can be used
    def __iter__(self):
        return self
    def next(self):
        line = self.inFile.next()
        return line
    def readDirList(self, sourceFile):
        # read csv file
        self.infile = open(sourceFile)
        print type(self) #yup, self is indeed of the right class which DOES have next() method
        rdr = csv.reader(self)
        for csvline in rdr:
            print csvline
        self.infile.close()
        return True
#----------------------------------------------------------------------
if __name__ == "__main__":
    # this works as expected
    mdl = dirList()
    mdl.inFile = open('tin.csv', 'r')
    rdr = csv.reader(mdl)
    for aaa in rdr:
        print aaa
    mdl.inFile.close()
    # when doing the same thing within a method of the object, it fails with:
    # AttributeError: 'NoneType' object has no attribute 'next'
    mdl2 = dirList()
    mdl2.readDirList('tin.csv')
    sys.exit()
#---- contents of file 'tin.csv' is as follows
"""
a,b,c
d,e,f
1,3,4
"""
</code>```

答: Your file is in the variable self.infile, however, you are calling next on self.inFile, which is None. Simple typo.

Body:
I am using csv.reader(), but it fails when I use it from a method within a class if the argument to reader() is that object itself (i.e., "self).  The failure is non-intuitive.  When I call csv.reader() from outside the object, all is well.  Can somebody explain what conceptual error I've made?  Hope my explanation makes some sense: it probably is easier to read/invoke the code.

You can see that in main I first invoke the readDirList() method directly, and everything is happy.  However, if I invoke the readDirList() method of the dirList class (which is supposed to do the same thing), I get the odd "no next() method" error.  Befuddled, I am.

Thanks for taking a look!

(am using python 2.7.6 in Linux Mint 17.3)  Also BTW I get the same area if in main I omit the "mdl" stuff and jump right to the "mdl2" stuff.
    #!/usr/bin/python
    # example: why csv.reader.next() doe not work

import csv

class dirList(object):
    def __init__(self):
        self.inFile = None
        return
    # a dirList object is iterable so that csv.reader can be used
    def __iter__(self):
        return self
    def next(self):
        line = self.inFile.next()
        return line
    def readDirList(self, sourceFile):
        # read csv file
        self.infile = open(sourceFile)
        print type(self) #yup, self is indeed of the right class which DOES have next() method
        rdr = csv.reader(self)
        for csvline in rdr:
            print csvline
        self.infile.close()
        return True
#----------------------------------------------------------------------
if __name__ == "__main__":
    # this works as expected
    mdl = dirList()
    mdl.inFile = open('tin.csv', 'r')
    rdr = csv.reader(mdl)
    for aaa in rdr:
        print aaa
    mdl.inFile.close()
    # when doing the same thing within a method of the object, it fails with:
    # AttributeError: 'NoneType' object has no attribute 'next'
    mdl2 = dirList()
    mdl2.readDirList('tin.csv')
    sys.exit()
#---- contents of file 'tin.csv' is as follows
"""
a,b,c
d,e,f
1,3,4
"""


问:
Latex: how to draw box around text that contains a verbatim block
Typically, to box in some text, I use the following:

```<code>\fbox {
    \parbox{\linewidth}{
    This is some text! Blah blah blah...
    }
}
</code>```

However, say I have a verbatim block within that. It will never compile. Anyone know how I could draw a box around text which contains a verbatim block? Like this for example...

```<code>\fbox {
    \parbox{\linewidth}{
        \begin{verbatim}
        This is some text!
        \end{verbatim}
    }
}
</code>```

I should not that I re-posted this in tex.stackexchange after CPF pointed out that there was such a thing. Let me know if people are opposed to doubled posting. If not, I'll keep it up here as well.

答:
Easier: use the fancyvrb package.

```<code>\begin{Verbatim}[frame=single]
stuff
\end{Verbatim}
</code>```

ContentLicense: CC BY-SA 2.5

Body:
Typically, to box in some text, I use the following:

\fbox {
    \parbox{\linewidth}{
    This is some text! Blah blah blah...
    }
}

However, say I have a verbatim block within that. It will never compile. Anyone know how I could draw a box around text which contains a verbatim block? Like this for example...

\fbox {
    \parbox{\linewidth}{
        \begin{verbatim}
        This is some text!
        \end{verbatim}
    }
}

I should not that I re-posted this in tex.stackexchange after CPF pointed out that there was such a thing. Let me know if people are opposed to doubled posting. If not, I'll keep it up here as well.

Body:
Easier: use the fancyvrb package.

\begin{Verbatim}[frame=single]
stuff
\end{Verbatim}


问:
Canvas: Strange behavior when pressing key down
By default the rectangle of my canvas should move from left to right. When pressing the key down, it should start moving down.

var canvas = document.getElementById('canvas'),
    ctx = canvas.getContext('2d'),
    x = 0,
    y = 0;

function draw(x_move, y_move) {
  requestAnimationFrame(function() {
    draw(x_move, y_move);
  });
  ctx.beginPath();
  ctx.rect(x, y, 20, 20);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "#ffffff";
  ctx.fill();
  ctx.closePath();
  x = x + x_move;
  y = y + y_move;
}

draw(1, 0);

document.addEventListener('keydown', function(event) {
  //console.log(event.keyCode);
  if (event.keyCode == 40) {
    draw(0, 1);
  }
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>canvas { background-color: red; }</code>```

<canvas id="canvas" width="600" height="400"></canvas>```

Using the code above, you may at least notice two issues:

When pressing key down, the rectangle moves down but also keeps moving to the right.

When you keep pressing the down key multiple times, the speed gets increased.

How can I fix those issues?

答:
I believe this is what you want to be doing (and you were close!). I hope this is the behaviour you were looking for.

A related point: It may be a good idea to wrap x_move and y_move up in a closure with these functions so you avoid accidentally changing them in other parts of the program. That way the functions you implement for changing directions of the square will have private access to these variables.

var canvas = document.getElementById('canvas'),
  ctx = canvas.getContext('2d'),
  x = 0,
  y = 0;

var x_move = 1;
var y_move = 0;

function draw() {
  requestAnimationFrame(function() {
    draw();
  });

  ctx.beginPath();
  ctx.rect(x, y, 20, 20);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "#ffffff";
  ctx.fill();
  ctx.closePath();
  x = x + x_move;
  y = y + y_move;
}

draw();

document.addEventListener('keydown', function(event) {
  //console.log(event.keyCode);
  if (event.keyCode == 40) {
    x_move = 0;
    y_move = 1;
  }
});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>canvas {
  background-color: red;
}</code>```

<canvas id="canvas" width="600" height="400"></canvas>```

Body:
By default the rectangle of my canvas should move from left to right. When pressing the key down, it should start moving down.

var canvas = document.getElementById('canvas'),
    ctx = canvas.getContext('2d'),
    x = 0,
    y = 0;

function draw(x_move, y_move) {
  requestAnimationFrame(function() {
    draw(x_move, y_move);
  });
  ctx.beginPath();
  ctx.rect(x, y, 20, 20);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "#ffffff";
  ctx.fill();
  ctx.closePath();
  x = x + x_move;
  y = y + y_move;
}

draw(1, 0);

document.addEventListener('keydown', function(event) {
  //console.log(event.keyCode);
  if (event.keyCode == 40) {
    draw(0, 1);
  }
});

canvas { background-color: red; }

<canvas id="canvas" width="600" height="400"></canvas>

Using the code above, you may at least notice two issues:

When pressing key down, the rectangle moves down but also keeps moving to the right.

When you keep pressing the down key multiple times, the speed gets increased.

How can I fix those issues?

Body:
I believe this is what you want to be doing (and you were close!). I hope this is the behaviour you were looking for.

A related point: It may be a good idea to wrap x_move and y_move up in a closure with these functions so you avoid accidentally changing them in other parts of the program. That way the functions you implement for changing directions of the square will have private access to these variables.

var canvas = document.getElementById('canvas'),
  ctx = canvas.getContext('2d'),
  x = 0,
  y = 0;

var x_move = 1;
var y_move = 0;

function draw() {
  requestAnimationFrame(function() {
    draw();
  });

  ctx.beginPath();
  ctx.rect(x, y, 20, 20);
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "#ffffff";
  ctx.fill();
  ctx.closePath();
  x = x + x_move;
  y = y + y_move;
}

draw();

document.addEventListener('keydown', function(event) {
  //console.log(event.keyCode);
  if (event.keyCode == 40) {
    x_move = 0;
    y_move = 1;
  }
});

canvas {
  background-color: red;
}

<canvas id="canvas" width="600" height="400"></canvas>


问:
encrypt and decrypt with AESCrypt in android
I'm developing an app, but I found a problem. I can encrypt but I can not decipher. Can you help me fix it?

the app comes to sensitive data and I would like to send in Firebase encrypted data but they remain decrypted on the list.

This is my code:

```<code>public class UserActivity extends AppCompatActivity {

private EditText input_tipo, input_id, input_password;
private ListView list_data;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mDatabaseReference;
private FirebaseAnalytics firebaseAnalytics;
private List<User> list_users = new ArrayList<>();
private User selectedUser;
private FirebaseAuth mAuth;
private FirebaseUser mUser;
private String encryptPass, decryptPass;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user);

    Toolbar tool = (Toolbar) findViewById(R.id.toolbar);
    tool.setTitle("MySecurity");
    setSupportActionBar(tool);

    input_tipo = (EditText) findViewById(R.id.tipo);
    input_id = (EditText) findViewById(R.id.id);
    input_password = (EditText) findViewById(R.id.password);
    list_data = (ListView) findViewById(R.id.list_data);

    mAuth = FirebaseAuth.getInstance();
    mUser = mAuth.getCurrentUser();

    list_data.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            User user = (User) adapterView.getItemAtPosition(i);
            selectedUser = user;

            input_tipo.setText(user.getTipo());
            input_id.setText(user.getId());
            input_password.setText(user.getPassword());

        }
    });

    initFirebase();
    addEventFirebaseListener();
    findNetwork();

}

private void findNetwork() {
    ConnectivityManager CM = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo ninfo = CM.getActiveNetworkInfo();
    if (ninfo != null && ninfo.isConnectedOrConnecting()) {
        Toast.makeText(getBaseContext(), "Connesso in Firebase:" + ninfo.getTypeName(), Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(getBaseContext(), "Connessione internet assente", Toast.LENGTH_LONG).show();
    }
}

private void addEventFirebaseListener() {
    list_data.setVisibility(View.VISIBLE);
    mDatabaseReference.child("users").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (list_users.size() > 0)
                list_users.clear();
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                User user = postSnapshot.getValue(User.class);
                list_users.add(user);
            }
            ListViewAdapter adapter = new ListViewAdapter(UserActivity.this, list_users);
            list_data.setAdapter(adapter);
            list_data.setVisibility(View.VISIBLE);
        }

            @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}

private void initFirebase() {
    FirebaseApp.initializeApp(this);
    mFirebaseDatabase = FirebaseDatabase.getInstance();
    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    firebaseAnalytics = FirebaseAnalytics.getInstance(this);
    firebaseAnalytics.setAnalyticsCollectionEnabled(true);
    firebaseAnalytics.setMinimumSessionDuration(5000);
    mDatabaseReference = mFirebaseDatabase.getReference().child("users").child(mUser.getUid());
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.home, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_add) {
        createUser();
    } else if (item.getItemId() == R.id.menu_remove) {
        deleteUser(selectedUser);
    } else if (item.getItemId() == R.id.menu_deselect) {
        DeselectedUser(selectedUser);
    }else if(item.getItemId()== R.id.menu_decrypt){
        DecryptUser(selectedUser);
    }
    return true;
}

private void DecryptUser(User selectedUser) {
    if (selectedUser != null) {
        mDatabaseReference.child("users").child(selectedUser.getUid());

        String password = selectedUser.getPassword().trim();
        String Message= selectedUser.getPassword().trim();

        try {
            decryptPass= AESCrypt.decrypt( password, Message);
            input_tipo.setText(input_tipo.getText().toString());
            input_id.setText(input_id.getText().toString());
            input_password.setText(decryptPass);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

private void DeselectedUser(User selectedUser) {
    if (selectedUser != null) {
        mDatabaseReference.child("users").child(selectedUser.getUid());
        clearEditText();
    }
}

private void deleteUser(User selectedUser) {
    if (selectedUser != null) {
        mDatabaseReference.child("users").child(selectedUser.getUid()).removeValue();
        clearEditText();
    }
}

private void createUser() {

    String password = input_password.getText().toString().trim();
    String Message= input_password.getText().toString().trim();

    try {
        encryptPass = AESCrypt.encrypt(password, Message);
        User user1= new User(UUID.randomUUID().toString(), input_tipo.getText().toString(),
                input_id.getText().toString(), encryptPass);
        mDatabaseReference.child("users").child(user1.getUid()).setValue(user1);
        clearEditText();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

private void clearEditText() {
    input_tipo.setText("");
    input_id.setText("");
    input_password.setText("");
}

@Override
protected void onStop() {
    super.onStop();
    finish();
}

}
</code>```

答: The password and Message variables are assigned the same thing (selectedUser.getPassword().trim()). What you are doing is trying to decrypt the user password, using the user password. Probably you need to assign the ciphertext that you want to decrypt to the Message variable.

Body:
I'm developing an app, but I found a problem. I can encrypt but I can not decipher. Can you help me fix it?

the app comes to sensitive data and I would like to send in Firebase encrypted data but they remain decrypted on the list.

This is my code:

public class UserActivity extends AppCompatActivity {

private EditText input_tipo, input_id, input_password;
private ListView list_data;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mDatabaseReference;
private FirebaseAnalytics firebaseAnalytics;
private List<User> list_users = new ArrayList<>();
private User selectedUser;
private FirebaseAuth mAuth;
private FirebaseUser mUser;
private String encryptPass, decryptPass;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user);

    Toolbar tool = (Toolbar) findViewById(R.id.toolbar);
    tool.setTitle("MySecurity");
    setSupportActionBar(tool);

    input_tipo = (EditText) findViewById(R.id.tipo);
    input_id = (EditText) findViewById(R.id.id);
    input_password = (EditText) findViewById(R.id.password);
    list_data = (ListView) findViewById(R.id.list_data);

    mAuth = FirebaseAuth.getInstance();
    mUser = mAuth.getCurrentUser();

    list_data.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            User user = (User) adapterView.getItemAtPosition(i);
            selectedUser = user;

            input_tipo.setText(user.getTipo());
            input_id.setText(user.getId());
            input_password.setText(user.getPassword());

        }
    });

    initFirebase();
    addEventFirebaseListener();
    findNetwork();

}

private void findNetwork() {
    ConnectivityManager CM = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo ninfo = CM.getActiveNetworkInfo();
    if (ninfo != null && ninfo.isConnectedOrConnecting()) {
        Toast.makeText(getBaseContext(), "Connesso in Firebase:" + ninfo.getTypeName(), Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(getBaseContext(), "Connessione internet assente", Toast.LENGTH_LONG).show();
    }
}

private void addEventFirebaseListener() {
    list_data.setVisibility(View.VISIBLE);
    mDatabaseReference.child("users").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (list_users.size() > 0)
                list_users.clear();
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                User user = postSnapshot.getValue(User.class);
                list_users.add(user);
            }
            ListViewAdapter adapter = new ListViewAdapter(UserActivity.this, list_users);
            list_data.setAdapter(adapter);
            list_data.setVisibility(View.VISIBLE);
        }

            @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}

private void initFirebase() {
    FirebaseApp.initializeApp(this);
    mFirebaseDatabase = FirebaseDatabase.getInstance();
    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    firebaseAnalytics = FirebaseAnalytics.getInstance(this);
    firebaseAnalytics.setAnalyticsCollectionEnabled(true);
    firebaseAnalytics.setMinimumSessionDuration(5000);
    mDatabaseReference = mFirebaseDatabase.getReference().child("users").child(mUser.getUid());
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.home, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_add) {
        createUser();
    } else if (item.getItemId() == R.id.menu_remove) {
        deleteUser(selectedUser);
    } else if (item.getItemId() == R.id.menu_deselect) {
        DeselectedUser(selectedUser);
    }else if(item.getItemId()== R.id.menu_decrypt){
        DecryptUser(selectedUser);
    }
    return true;
}

private void DecryptUser(User selectedUser) {
    if (selectedUser != null) {
        mDatabaseReference.child("users").child(selectedUser.getUid());

        String password = selectedUser.getPassword().trim();
        String Message= selectedUser.getPassword().trim();

        try {
            decryptPass= AESCrypt.decrypt( password, Message);
            input_tipo.setText(input_tipo.getText().toString());
            input_id.setText(input_id.getText().toString());
            input_password.setText(decryptPass);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

private void DeselectedUser(User selectedUser) {
    if (selectedUser != null) {
        mDatabaseReference.child("users").child(selectedUser.getUid());
        clearEditText();
    }
}

private void deleteUser(User selectedUser) {
    if (selectedUser != null) {
        mDatabaseReference.child("users").child(selectedUser.getUid()).removeValue();
        clearEditText();
    }
}

private void createUser() {

    String password = input_password.getText().toString().trim();
    String Message= input_password.getText().toString().trim();

    try {
        encryptPass = AESCrypt.encrypt(password, Message);
        User user1= new User(UUID.randomUUID().toString(), input_tipo.getText().toString(),
                input_id.getText().toString(), encryptPass);
        mDatabaseReference.child("users").child(user1.getUid()).setValue(user1);
        clearEditText();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

private void clearEditText() {
    input_tipo.setText("");
    input_id.setText("");
    input_password.setText("");
}

@Override
protected void onStop() {
    super.onStop();
    finish();
}

}


问:
WORDPRESS: Where do I delete my site?
I've looked absolutely everywhere for an answer to this, and so far have not gotten any that have solved my problem. It seems like it should be simple, but Im either getting answers that tell me to press a "Delete Account" button in my dashboard that simply IS NOT there, or someone says "look it up on Google" or something else that is not at all helpful. I've looked and am getting very frustrated. So, here's my question(s):

If I cancel the hosting (Blue Host), will it automatically cancel all payments relating to the site? That is, is signing up on WordPress free, with the hosting being the part that is paid? I can't find statements or anything related to the WordPress part of it, so I'm hoping that the hosting is the only part I'm paying for (this site was started a few years ago, and I just don't have time for it, so I don't remember anymore.)

Can a Wordpress.org account/site actually be deleted? I've emptied all the contents as stated in the documentation, but when it comes to actually pressing "Delete Account," the button is no where to be found in my dashboard! As long as I'm not paying for it to just sit there, I guess I can leave it, but I'd prefer to delete it altogether, if possible.

Thank you to anyone who offers constructive advice on this topic. I know others have asked about this, but none of those solutions have worked, so I'm asking again. (It also doesn't help that WordPress doesn't offer direct support, only forums, so if you happen to know of a good resource outside of their own documentation--which, as stated, hasn't helped me--I'll appreciate the referral.)

答:
if you want to delete your site just delete all the file for this site in public_html folder. or if you want delete hosting for this site contact with your hosting provider. you can do it if you want to do.
But I think you can sell your domain, if your domain age is above 5 years may be your domain has SEO domain authority (DA) . you can sell it .  </p>

Title: WORDPRESS: Where do I delete my site?


问:
Excel Combine two columns in call to function?
My spreadsheet looks like this:

I have two lists of dates, I want to get all unique dates between Dates1 and Dates2 and put them in column C.

I can get unique dates in column A with UNIQUE(A2:A4), but I want all unique dates between both columnms. When I try to do =UNIQUE(A2:A4,B2:B5) I get the error:

Wrong number of arguments to UNIQUE. Expected 1 arguments, but got 2 arguments.

How can I get all unique dates between both? I've also tried concatenate, but that just gives me a huge number, not a row of dates.

Thanks!

答:
Put all cells on the argument ie UNIQUE(A2:B5)

For seperate columns, create a dummy column next to the one you are comparing to, set its contents to the actual column, then use Unique


问:
Get and Set methods for Maps in Erlang
I have started to learn Erlang, so I'm a noob in functional programming.

I think that I can't have "global variables" that I could use in different processes of the same module. Therefore, I have thought that I could use maps to store data (counters, status,...) and manage/update it.

My question is: Is there any way to do get/set methods (similar to the methods that we can find in Java, C#,...) to access to maps data without writing them in files? Or is there another way to have these data globally.

Thank you!

答:
I think that I can't have "global variables" that I could use in
  different processes of the same module. Therefore, I have thought that
  I could use maps to store data (counters, status,...) and
  manage/update it.

Then the map would have to be assigned to some global inter-process variable, and you are back to the same problem.

My question is: Is there any way to do get/set methods (similar to the
  methods that we can find in Java...

To what methods are you referring?

You can use a database, like mnesia, to store data that different processes can access.

Title: Get and Set methods for Maps in Erlang


问:
Does Django Oscar provide features to connect your e-commerce website with other e-commerce websites?
I have not integrated Oscar in my Django project and I am planning to build an eCommerce web site using Oscar. But we will be having a requirement at later stage to add connector between our website and other eCommerce giants like Alibaba, Amazon, eBay.

That means I need different website APIs to push one or more products (taken from Django Oscar products) on different sites and track/manage orders done by users on those sites directly on our platform.

Does someone have any knowledge regarding this?

I am doing a detailed R&D and would add answer to this question if I find something related.

答:
Yes, you can do this with Oscar, however you will need to do a fair amount of custom development to get your desired API integrations working.

Oscar is composed of numerous self-contained apps which allow you to "fork" and subclass all of it's code. This allows you to mold the framework to fit your exact business needs.

It sounds like you would need to "fork" the catalogue app, add whatever custom models you might need and then add code to integrate with all your other APIs (like pushing all new products to another API). If you are wanting to keep track of orders from other e-commerce platforms, you would probably need to fork the dashboard app and make some custom code to call your other APIs and display that info.

Here's an explanation on how to fork an app in Oscar:

https://django-oscar.readthedocs.io/en/releases-1.4/topics/fork_app.html