问:
Images to rename
Thousands of images that follow this pattern:
1 is the main image and this is the problem image because I don't have anything to select.

```<code>1) 6-100-DS.tif - Renamed to 6-100-DS-main.tif
2) 6-100-DS_a.tif - Renamed to 6-100-DS-alt01.tif
3) 6-100-DS_b.tif - Renamed to 6-100-DS-alt02.tif
</code>```

Renaming 2 & 3 is easy enough:

```<code>Dir | Rename-Item –NewName { $_.name –replace "_a","-alt01" }
Dir | Rename-Item –NewName { $_.name –replace "_b","-alt02" }
</code>```

I may have answered my own question; I suppose I could just rename all images "-main.tif" and then include that in the selector for renaming the alt images.

```<code>"_a-main.tif", "_b-main.tif"
</code>```

Anyone know how to do this more efficiently?

答:
Let me know if this works:

What I have done is create a function for each task, but we could put it all into one function, but I thought it would be easy to explain like this.

We use the Get-ChildItem cmdlet to grab everything in the directory called DS.TIF, DS_A.tif, or DS_B.tif. Once this is done we get a list of files that forum to those rules. Now it is simple as renaming them, but keeping the 6-100-DS the same.

```<code>$Dir="F:\Test\Images"
Function Main{
$Files=Get-ChildItem $Dir -Recurse | Where-Object {$_.name -like "*DS.TIF"}
$Files | Rename-Item –NewName { $_.name –replace "DS","DS-main" }
}

Function alt01{
$Files=Get-ChildItem $Dir -Recurse | Where-Object {$_.name -like "*DS_a.TIF"}
$Files | Rename-Item –NewName { $_.name –replace "_a","-alt01" }
}

Function alt02{
$Files=Get-ChildItem $Dir -Recurse | Where-Object {$_.name -like "*DS_b.TIF"}
$Files | Rename-Item –NewName { $_.name –replace "_b","-alt02" }
}
Main
alt01
alt02
</code>```

Title: Images to rename

Body:
Thousands of images that follow this pattern:
1 is the main image and this is the problem image because I don't have anything to select.

1) 6-100-DS.tif - Renamed to 6-100-DS-main.tif
2) 6-100-DS_a.tif - Renamed to 6-100-DS-alt01.tif
3) 6-100-DS_b.tif - Renamed to 6-100-DS-alt02.tif

Renaming 2 & 3 is easy enough:

Dir | Rename-Item –NewName { $_.name –replace "_a","-alt01" }
Dir | Rename-Item –NewName { $_.name –replace "_b","-alt02" }

I may have answered my own question; I suppose I could just rename all images "-main.tif" and then include that in the selector for renaming the alt images.

"_a-main.tif", "_b-main.tif"

Anyone know how to do this more efficiently?

Body:
Let me know if this works:

What I have done is create a function for each task, but we could put it all into one function, but I thought it would be easy to explain like this.

We use the Get-ChildItem cmdlet to grab everything in the directory called DS.TIF, DS_A.tif, or DS_B.tif. Once this is done we get a list of files that forum to those rules. Now it is simple as renaming them, but keeping the 6-100-DS the same.

$Dir="F:\Test\Images"
Function Main{
$Files=Get-ChildItem $Dir -Recurse | Where-Object {$_.name -like "*DS.TIF"}
$Files | Rename-Item –NewName { $_.name –replace "DS","DS-main" }
}

Function alt01{
$Files=Get-ChildItem $Dir -Recurse | Where-Object {$_.name -like "*DS_a.TIF"}
$Files | Rename-Item –NewName { $_.name –replace "_a","-alt01" }
}

Function alt02{
$Files=Get-ChildItem $Dir -Recurse | Where-Object {$_.name -like "*DS_b.TIF"}
$Files | Rename-Item –NewName { $_.name –replace "_b","-alt02" }
}
Main
alt01
alt02


来源: stackexchange

问:
SQL Get cases related to a user and the number of files attached to that case
Hi everyone got a little stuck on an sql query. I have four tables

```<code>    users
    +----+------------+-----------+--------+
    | id | first_name | last_name | active |
    +----+------------+-----------+--------+
    |  1 | Joe        | Bloggs    |      1 |
    |  2 | John       | Doe       |      1 |
    |  3 | Dave       | Smith     |      1 |
    +----+------------+-----------+--------+

    cases
        +----+-----------+-------------+
        | id | case_code |  case_name  |
        +----+-----------+-------------+
        |  1 | THEC12C   | Test Case 1 |
        |  2 | ABCD23A   | Test Case 2 |
        +----+-----------+-------------+

case_creditors
        +----+---------+-------------+
        | id | case_id | creditor_id |
        +----+---------+-------------+
        |  1 |       1 |           3 |
        |  2 |       2 |           1 |
        +----+---------+-------------+

    case_files
    +----+---------+----------+-----------+
    | id | case_id | filename | file type |
    +----+---------+----------+-----------+
    |  1 |       1 | test.pdf | pfd       |
    |  2 |       2 | file.txt | txt       |
    |  3 |       2 | word.doc | doc       |
    +----+---------+----------+-----------+
</code>```

When a user logs in i need to show a table with the users accociated cases the number of files attached to that case so if Joe Blogs loged in head see the following table

```<code>+-----------+-------------+-------+
| Case Code |  Case Name  | Files |
+-----------+-------------+-------+
| ABCD23A   | Test Case 2 |     2 |
+-----------+-------------+-------+
</code>```

ive been trying to write the sql statement to do this but am getting stuck on the query and wandered if someone could help give me some pointers. the sql ive gor so far

```<code>SELECT * FROM cases
(SELECT COUNT(*) FROM case_files WHERE case_files.case_id = cases.id) as Files
JOIN case_creditors ON cases.id = case_creditors.case_id
WHERE case_creditors.creditor_id = 1
</code>```

答:
managed to sort this with</p>

```<code>SELECT
    ips_case.*,
    COUNT(case_files.file_id) AS Files
FROM
    ips_case
    LEFT JOIN case_files ON ips_case.id = case_files.case_id
    JOIN case_creditors ON ips_case.id = case_creditors.case_id
WHERE
    case_creditors.creditors_id = 4
GROUP BY
    ips_case.id
</code>```

ContentLicense: CC BY-SA 3.0

Body:
Hi everyone got a little stuck on an sql query. I have four tables

    users
    +----+------------+-----------+--------+
    | id | first_name | last_name | active |
    +----+------------+-----------+--------+
    |  1 | Joe        | Bloggs    |      1 |
    |  2 | John       | Doe       |      1 |
    |  3 | Dave       | Smith     |      1 |
    +----+------------+-----------+--------+

    cases
        +----+-----------+-------------+
        | id | case_code |  case_name  |
        +----+-----------+-------------+
        |  1 | THEC12C   | Test Case 1 |
        |  2 | ABCD23A   | Test Case 2 |
        +----+-----------+-------------+

case_creditors
        +----+---------+-------------+
        | id | case_id | creditor_id |
        +----+---------+-------------+
        |  1 |       1 |           3 |
        |  2 |       2 |           1 |
        +----+---------+-------------+

    case_files
    +----+---------+----------+-----------+
    | id | case_id | filename | file type |
    +----+---------+----------+-----------+
    |  1 |       1 | test.pdf | pfd       |
    |  2 |       2 | file.txt | txt       |
    |  3 |       2 | word.doc | doc       |
    +----+---------+----------+-----------+

When a user logs in i need to show a table with the users accociated cases the number of files attached to that case so if Joe Blogs loged in head see the following table

+-----------+-------------+-------+
| Case Code |  Case Name  | Files |
+-----------+-------------+-------+
| ABCD23A   | Test Case 2 |     2 |
+-----------+-------------+-------+

ive been trying to write the sql statement to do this but am getting stuck on the query and wandered if someone could help give me some pointers. the sql ive gor so far

SELECT * FROM cases
(SELECT COUNT(*) FROM case_files WHERE case_files.case_id = cases.id) as Files
JOIN case_creditors ON cases.id = case_creditors.case_id
WHERE case_creditors.creditor_id = 1

Body:
managed to sort this with

SELECT
    ips_case.*,
    COUNT(case_files.file_id) AS Files
FROM
    ips_case
    LEFT JOIN case_files ON ips_case.id = case_files.case_id
    JOIN case_creditors ON ips_case.id = case_creditors.case_id
WHERE
    case_creditors.creditors_id = 4
GROUP BY
    ips_case.id


问:
Errors in API Analytics and API Manager
So I recently migrated my API Manager environment. I upgraded from 2.0.0 to 2.1.0 for both the API Manager and API Analytics. The API Analytics is on its own server. When I run the servers I get these errors

Analytics

```<code>    ERROR {org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceComponent} -  Error in activating analytics data service: Unable to find class: piPublisher
        Serialization trace:
    columns (org.wso2.carbon.analytics.datasource.commons.AnalyticsSchema)
    schema (org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl$AnalyticsTableInfo) {org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceComponent}
    com.esotericsoftware.kryo.KryoException: Unable to find class: piPublisher
    Serialization trace:
    columns (org.wso2.carbon.analytics.datasource.commons.AnalyticsSchema)
    schema (org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl$AnalyticsTableInfo)
            at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:138)
            at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:115)
            at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:641)
            at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:752)
            at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:143)
            at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:21)
            at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:679)
            at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:106)
            at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528)
            at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:679)
            at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:106)
            at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528)
            at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:761)
            at org.wso2.carbon.analytics.datasource.core.util.GenericUtils.deserializeObject(GenericUtils.java:372)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.readTableInfo(AnalyticsDataServiceImpl.java:460)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.lookupTableInfo(AnalyticsDataServiceImpl.java:809)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.getTableSchemaFinal(AnalyticsDataServiceImpl.java:715)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.getTableSchema(AnalyticsDataServiceImpl.java:708)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.initIndexedTableStore(AnalyticsDataServiceImpl.java:210)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.<init>(AnalyticsDataServiceImpl.java:143)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceComponent.activate(AnalyticsDataServiceComponent.java:69)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:260)
            at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
            at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
            at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
            at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
            at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
            at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
            at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
            at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
            at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
            at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
            at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
            at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
            at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
            at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
            at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
            at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:451)
            at org.wso2.carbon.ntask.core.internal.TasksDSComponent.activate(TasksDSComponent.java:106)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:260)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
        at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
        at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
        at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:451)
        at org.wso2.carbon.core.internal.StartupFinalizerServiceComponent.completeInitialization(StartupFinalizerServiceComponent.java:199)
        at org.wso2.carbon.core.internal.StartupFinalizerServiceComponent.serviceChanged(StartupFinalizerServiceComponent.java:288)
        at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:451)
        at org.wso2.carbon.server.admin.internal.ServerAdminServiceComponent.activate(ServerAdminServiceComponent.java:106)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:260)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
        at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
        at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
        at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:451)
        at org.wso2.carbon.core.init.CarbonServerManager.initializeCarbon(CarbonServerManager.java:514)
        at org.wso2.carbon.core.init.CarbonServerManager.start(CarbonServerManager.java:219)
        at org.wso2.carbon.core.internal.CarbonCoreServiceComponent.activate(CarbonCoreServiceComponent.java:94)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:260)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
        at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
        at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
        at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
        at org.eclipse.equinox.http.servlet.internal.Activator.registerHttpService(Activator.java:81)
        at org.eclipse.equinox.http.servlet.internal.Activator.addProxyServlet(Activator.java:60)
        at org.eclipse.equinox.http.servlet.internal.ProxyServlet.init(ProxyServlet.java:40)
        at org.wso2.carbon.tomcat.ext.servlet.DelegationServlet.init(DelegationServlet.java:38)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1269)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1182)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5368)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5660)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: piPublisher cannot be found by kryo_2.24.0.wso2v1
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:136)
</code>```

```<code>TID: [-1234] [] [2017-03-21 14:51:50,360] ERROR {org.wso2.carbon.databridge.core.internal.queue.QueueWorker} -  Dropping wrongly formatted event sent for -1234 {org.wso2.carbon.databridge.core.internal.queue.QueueWorker}
org.wso2.carbon.databridge.core.exception.EventConversionException: Error when converting loganalyzer:1.0.0 of event bundle with events 1
        at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.createEventList(ThriftEventConverter.java:181)
        at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.toEventList(ThriftEventConverter.java:90)
        at org.wso2.carbon.databridge.core.internal.queue.QueueWorker.run(QueueWorker.java:73)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.wso2.carbon.databridge.core.exception.EventConversionException: No StreamDefinition for streamId loganalyzer:1.0.0 present in cache
        at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.createEventList(ThriftEventConverter.java:166)
</code>```

API Manager

UPDATE

I was able to fix these errors in the API Manager. See my comment below.

```<code>    TID: [-1] [] [2017-03-21 00:00:59,393] ERROR {org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter} -  Error when reporting timers {org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter}
java.sql.BatchUpdateException: Invalid object name 'METRIC_TIMER'.
        at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeBatch(SQLServerPreparedStatement.java:1178)
        at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.reportTimers(JDBCReporter.java:389)
        at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.report(JDBCReporter.java:200)
        at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
        at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
TID: [-1] [] [2017-03-21 00:01:59,391] ERROR {org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter} -  Error when reporting gauges {org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter}
java.sql.BatchUpdateException: Invalid object name 'METRIC_GAUGE'.
        at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeBatch(SQLServerPreparedStatement.java:1178)
        at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.reportGauges(JDBCReporter.java:221)
        at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.report(JDBCReporter.java:188)
        at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
        at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
</code>```

In the API Analytics is looks like there is a misspelled class or column name somewhere, but I can't find it in the configurations or database. I also tried to look in the components/plugins and was unable to really find anything. I'm guessing the errors in the API Manager are directly related to the errors in the Analytics server. I'm not sure how to trouble shoot this problem.

答: I fixed the error by deleting the ANX tables from the DB. My guess is that during migrate somethings did not go smoothly and was causing trouble for me.  </p>

Title: Errors in API Analytics and API Manager

Body:
So I recently migrated my API Manager environment. I upgraded from 2.0.0 to 2.1.0 for both the API Manager and API Analytics. The API Analytics is on its own server. When I run the servers I get these errors

Analytics

    ERROR {org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceComponent} -  Error in activating analytics data service: Unable to find class: piPublisher
        Serialization trace:
    columns (org.wso2.carbon.analytics.datasource.commons.AnalyticsSchema)
    schema (org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl$AnalyticsTableInfo) {org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceComponent}
    com.esotericsoftware.kryo.KryoException: Unable to find class: piPublisher
    Serialization trace:
    columns (org.wso2.carbon.analytics.datasource.commons.AnalyticsSchema)
    schema (org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl$AnalyticsTableInfo)
            at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:138)
            at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:115)
            at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:641)
            at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:752)
            at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:143)
            at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:21)
            at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:679)
            at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:106)
            at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528)
            at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:679)
            at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:106)
            at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528)
            at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:761)
            at org.wso2.carbon.analytics.datasource.core.util.GenericUtils.deserializeObject(GenericUtils.java:372)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.readTableInfo(AnalyticsDataServiceImpl.java:460)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.lookupTableInfo(AnalyticsDataServiceImpl.java:809)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.getTableSchemaFinal(AnalyticsDataServiceImpl.java:715)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.getTableSchema(AnalyticsDataServiceImpl.java:708)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.initIndexedTableStore(AnalyticsDataServiceImpl.java:210)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceImpl.<init>(AnalyticsDataServiceImpl.java:143)
            at org.wso2.carbon.analytics.dataservice.core.AnalyticsDataServiceComponent.activate(AnalyticsDataServiceComponent.java:69)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:260)
            at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
            at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
            at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
            at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
            at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
            at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
            at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
            at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
            at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
            at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
            at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
            at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
            at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
            at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
            at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
            at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:451)
            at org.wso2.carbon.ntask.core.internal.TasksDSComponent.activate(TasksDSComponent.java:106)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:260)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
        at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
        at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
        at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:451)
        at org.wso2.carbon.core.internal.StartupFinalizerServiceComponent.completeInitialization(StartupFinalizerServiceComponent.java:199)
        at org.wso2.carbon.core.internal.StartupFinalizerServiceComponent.serviceChanged(StartupFinalizerServiceComponent.java:288)
        at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:451)
        at org.wso2.carbon.server.admin.internal.ServerAdminServiceComponent.activate(ServerAdminServiceComponent.java:106)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:260)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
        at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
        at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
        at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:451)
        at org.wso2.carbon.core.init.CarbonServerManager.initializeCarbon(CarbonServerManager.java:514)
        at org.wso2.carbon.core.init.CarbonServerManager.start(CarbonServerManager.java:219)
        at org.wso2.carbon.core.internal.CarbonCoreServiceComponent.activate(CarbonCoreServiceComponent.java:94)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.equinox.internal.ds.model.ServiceComponent.activate(ServiceComponent.java:260)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.activate(ServiceComponentProp.java:146)
        at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:345)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:620)
        at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:197)
        at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:343)
        at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:222)
        at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:107)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:861)
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:819)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:771)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
        at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:214)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:433)
        at org.eclipse.equinox.http.servlet.internal.Activator.registerHttpService(Activator.java:81)
        at org.eclipse.equinox.http.servlet.internal.Activator.addProxyServlet(Activator.java:60)
        at org.eclipse.equinox.http.servlet.internal.ProxyServlet.init(ProxyServlet.java:40)
        at org.wso2.carbon.tomcat.ext.servlet.DelegationServlet.init(DelegationServlet.java:38)
        at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1269)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1182)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5368)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5660)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: piPublisher cannot be found by kryo_2.24.0.wso2v1
        at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:136)

TID: [-1234] [] [2017-03-21 14:51:50,360] ERROR {org.wso2.carbon.databridge.core.internal.queue.QueueWorker} -  Dropping wrongly formatted event sent for -1234 {org.wso2.carbon.databridge.core.internal.queue.QueueWorker}
org.wso2.carbon.databridge.core.exception.EventConversionException: Error when converting loganalyzer:1.0.0 of event bundle with events 1
        at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.createEventList(ThriftEventConverter.java:181)
        at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.toEventList(ThriftEventConverter.java:90)
        at org.wso2.carbon.databridge.core.internal.queue.QueueWorker.run(QueueWorker.java:73)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: org.wso2.carbon.databridge.core.exception.EventConversionException: No StreamDefinition for streamId loganalyzer:1.0.0 present in cache
        at org.wso2.carbon.databridge.receiver.thrift.converter.ThriftEventConverter.createEventList(ThriftEventConverter.java:166)

API Manager

UPDATE

I was able to fix these errors in the API Manager. See my comment below.

    TID: [-1] [] [2017-03-21 00:00:59,393] ERROR {org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter} -  Error when reporting timers {org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter}
java.sql.BatchUpdateException: Invalid object name 'METRIC_TIMER'.
        at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeBatch(SQLServerPreparedStatement.java:1178)
        at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.reportTimers(JDBCReporter.java:389)
        at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.report(JDBCReporter.java:200)
        at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
        at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
TID: [-1] [] [2017-03-21 00:01:59,391] ERROR {org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter} -  Error when reporting gauges {org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter}
java.sql.BatchUpdateException: Invalid object name 'METRIC_GAUGE'.
        at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeBatch(SQLServerPreparedStatement.java:1178)
        at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.reportGauges(JDBCReporter.java:221)
        at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.report(JDBCReporter.java:188)
        at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
        at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

In the API Analytics is looks like there is a misspelled class or column name somewhere, but I can't find it in the configurations or database. I also tried to look in the components/plugins and was unable to really find anything. I'm guessing the errors in the API Manager are directly related to the errors in the Analytics server. I'm not sure how to trouble shoot this problem.


问:
What is "origin" in Git?
When I run:

```<code>git push origin branchname
</code>```

What exactly is origin and why do I have to type it before the branch name?

答:
Simple! "origin" is just what you nicknamed your remote repository when you ran a command like this:

```<code>git remote add origin git@github.com:USERNAME/REPOSITORY-NAME.git
</code>```

From then on Git knows that "origin" points to that specific repository (in this case a GitHub repository). You could have named it "github" or "repo" or whatever you wanted.

Title: What is "origin" in Git?

Body:
When I run:

git push origin branchname

What exactly is origin and why do I have to type it before the branch name?

Body:
Simple! "origin" is just what you nicknamed your remote repository when you ran a command like this:

git remote add origin git@github.com:USERNAME/REPOSITORY-NAME.git

From then on Git knows that "origin" points to that specific repository (in this case a GitHub repository). You could have named it "github" or "repo" or whatever you wanted.


问:
nodejs render multiple pages at once
I've a contact page where one can put their contact details and message. Once they put their info, it is saved into mongodb collection. If there is no error i'd want to empty the contact form and display a pop up message saying thank you. Now if i use

```<code>    app.post("/contact", function(req, res){
    var name = req.body.name;
    var email = req.body.email;
    var phone = req.body.phone;
    var message = req.body.mess;
    var contact_message = new Contact({name:name,email:email,phn_no:phone,message:message});
    contact_message.save(function (err) {
    if (err) {
        return err;
    }
    else {
        console.log("Contact details saved");
        res.render("contact");
    }
  });
</code>```

The above code just renders back the same contact page with no thank you message. If i try to create a new ejs page ( eg: thankyoupage) and render it that page by sending a message using :

```<code>res.render("thankyoupage",{message: "thankyou"});
</code>```

it will render only the new thankyou page and leave the contact page unaffected. So i won't have a contact page in this scenario. I'd want something that is a mixture of both where i'd show a pop up showing thank you message with empty fields on contact page at the background.Is there anyway i could do that ? Any suggestions/help/example would be highly appreciated.

答:
In your contact page, you can insert a script that runs when the page first loads.   That script checks to see if a certain Javascript variable is set in the page.  If that variable is set, then the script pops you a thank you message.  If the Javascript variable is not set, that script does nothing.

Then, on the server, when you render the page, you pass the template a property that tells it what to insert for the Javascript variable.  That way your rendering operation can control whether the page will popup a message or not.

You can make this as feature-rich as you want.  For example, you could pass the render, the exact message you want the page to show too and the template could put that message into a Javascript variable that the script in the page would show.

Likewise, the popup can be as rich as you want. It could be an entire div taking up the whole page while the contact portion of the page is temporarily hidden or you could just use an alert() or prompt() message box over the regular contact page.

Title: nodejs render multiple pages at once

Body:
I've a contact page where one can put their contact details and message. Once they put their info, it is saved into mongodb collection. If there is no error i'd want to empty the contact form and display a pop up message saying thank you. Now if i use

    app.post("/contact", function(req, res){
    var name = req.body.name;
    var email = req.body.email;
    var phone = req.body.phone;
    var message = req.body.mess;
    var contact_message = new Contact({name:name,email:email,phn_no:phone,message:message});
    contact_message.save(function (err) {
    if (err) {
        return err;
    }
    else {
        console.log("Contact details saved");
        res.render("contact");
    }
  });

The above code just renders back the same contact page with no thank you message. If i try to create a new ejs page ( eg: thankyoupage) and render it that page by sending a message using :

res.render("thankyoupage",{message: "thankyou"});

it will render only the new thankyou page and leave the contact page unaffected. So i won't have a contact page in this scenario. I'd want something that is a mixture of both where i'd show a pop up showing thank you message with empty fields on contact page at the background.Is there anyway i could do that ? Any suggestions/help/example would be highly appreciated.


问:
unable to retrieve latest values of controller variable in vf javascript method
I have a visualforce page with a CommandLink that calls a controller method. In the controller method I set the properties in VF page(public with getters n setters). However, from the javascript in page, when I try to get those values, it is shown as not set.</p>

答: I am assuming that there are input fields on the VF page into which the User enters data and that you have a a JS function that is trying to access those values in the Controller.  I have found that the Controller isn't updated with the input values in real time.  Those values only get updated when an action is taken.  My solution (which may not be be the correct method) is to have a function in my controller to touch those fields so that they get pulled into the controller.  Then I have an apex:action function in the VF page to call the "toucher" method.  In my JS function I call that apex:action first so the controller gets updated.


问:
Select all but this element
I have a few accordions setup and I'd like only one to be open throughout the whole page. I thought that the .not() method would achieve what I wanted however it is just immediately closing the current div.

Here is what I have if anyone can spot where I've gone wrong:

JS

```<code>$( document ).ajaxComplete(function() {
$('.accordion-toggle').click(function(){

  //Expand or collapse this panel
  $(this).next().stop().slideToggle('1000');
  $(this).toggleClass('active').siblings().removeClass('active');

  //Hide the other panels
  $('.accordion-content').not(this).slideUp('1000');

});
});
</code>```

HTML

```<code><div id="location1">

<h3 class="accordion-toggle">Opening times <i class="fa fa-angle-down"></i></h3>
<div class="accordion-content">
<p>List of products available here!</p>
</div>

<h3 class="accordion-toggle">Opening times <i class="fa fa-angle-down"></i></h3>
<div class="accordion-content">
<p>List of products available here!</p>
</div>

<h3 class="accordion-toggle">Opening times <i class="fa fa-angle-down"></i></h3>
<div class="accordion-content">
<p>List of products available here!</p>
</div>

<h3 class="accordion-toggle">Opening times <i class="fa fa-angle-down"></i></h3>
<div class="accordion-content">
<p>List of products available here!</p>
</div>

</div>

<div id="location2">

<h3 class="accordion-toggle">Opening times <i class="fa fa-angle-down"></i></h3>
<div class="accordion-content">
<p>List of products available here!</p>
</div>

<h3 class="accordion-toggle">Opening times <i class="fa fa-angle-down"></i></h3>
<div class="accordion-content">
<p>List of products available here!</p>
</div>

<h3 class="accordion-toggle">Opening times <i class="fa fa-angle-down"></i></h3>
<div class="accordion-content">
<p>List of products available here!</p>
</div>

<h3 class="accordion-toggle">Opening times <i class="fa fa-angle-down"></i></h3>
<div class="accordion-content">
<p>List of products available here!</p>
</div>

</div>
</code>```

CSS

```<code>.accordion-content {
  display: none;
  padding:20px 0;
  border-bottom: 1px solid #d4d5d7;
}

.accordion-content.default {display: block;}

.accordion-toggle {
  cursor: pointer;
  font-size:18px;
  padding:10px 0;
  margin:0;
  border-bottom:1px solid #d4d5d7;
  position:relative;
}
</code>```

答:
In your case this is the toggle not the content (it would also have to be $(this) not just this, so:

```<code>$('.accordion-content').not(this).slideUp('1000');
</code>```

Will match all accordion content.

You could try:

```<code>var $content = $(this).next('.accordion-content');
$('.accordion-content').not($content).slideUp('1000');
</code>```

As a note, I would set var $this = $(this); at the beginning of your handler so that you are not repeatedly creating jQuery objects which is relatively expensive.

Title: Select all but this element

Body:
I have a few accordions setup and I'd like only one to be open throughout the whole page. I thought that the .not() method would achieve what I wanted however it is just immediately closing the current div.

Here is what I have if anyone can spot where I've gone wrong:

JS

$( document ).ajaxComplete(function() {
$('.accordion-toggle').click(function(){

  //Expand or collapse this panel
  $(this).next().stop().slideToggle('1000');
  $(this).toggleClass('active').siblings().removeClass('active');

  //Hide the other panels
  $('.accordion-content').not(this).slideUp('1000');

});
});

HTML

Opening times

List of products available here!

Opening times

List of products available here!

Opening times

List of products available here!

Opening times

List of products available here!

Opening times

List of products available here!

Opening times

List of products available here!

Opening times

List of products available here!

Opening times

List of products available here!

CSS

.accordion-content {
  display: none;
  padding:20px 0;
  border-bottom: 1px solid #d4d5d7;
}

.accordion-content.default {display: block;}

.accordion-toggle {
  cursor: pointer;
  font-size:18px;
  padding:10px 0;
  margin:0;
  border-bottom:1px solid #d4d5d7;
  position:relative;
}

Body:
In your case this is the toggle not the content (it would also have to be $(this) not just this, so:

$('.accordion-content').not(this).slideUp('1000');

Will match all accordion content.

You could try:

var $content = $(this).next('.accordion-content');
$('.accordion-content').not($content).slideUp('1000');

As a note, I would set var $this = $(this); at the beginning of your handler so that you are not repeatedly creating jQuery objects which is relatively expensive.


问:
Apollo + React Router 4 SSR issue
Not sure if this is an issue with React Router v4, the React Apollo client or my implementation.

But with <ApolloProvider> as the top-level HOC, i.e:

```<code>const ComponentsWithData = await getDataFromTree(
  <ApolloProvider client={apolloClient}>
    <StaticRouter location={ctx.request.url} context={route}>
      <App />
    </StaticRouter>,
  </ApolloProvider>,
);

const html = ReactDOMServer.renderToString(ComponentsWithData);
</code>```

... I get:

Warning: Failed prop type: Invalid prop children of type array supplied to ApolloProvider, expected a single ReactElement.
      in ApolloProvider
  Error React.Children.only expected to receive a single React element child.

And flipped around, with React Router's <StaticRouter> as the top, i.e.:

```<code>const ComponentsWithData = await getDataFromTree(
  <ApolloProvider client={apolloClient}>
    <StaticRouter location={ctx.request.url} context={route}>
      <App />
    </StaticRouter>,
  </ApolloProvider>,
);
</code>```

... I then get:

A <Router> may have only one child element

Rendering works fine in the browser (with React Router's <BrowserRouter>), but fails on the server.

It also works well in React Router v3 due to doing all of the route matching outside of the React hierarchy, and not declaratively inside of it.

答:
This was actually a user error. I expected getDataFromTree() to return a Promise that resolved to the original component chain (with the correctly injected GraphQL data props), but it actually just waits for the data to be ready.

The correct format is:

```<code>const Components = (
  <StaticRouter location={ctx.request.url} context={route}>
    <ApolloProvider client={client}>
      <App />
    </ApolloProvider>
  </StaticRouter>
);

await getDataFromTree(Components);
const html = ReactDOMServer.renderToString(Components);
</code>```

Title: Apollo + React Router 4 SSR issue

Body:
Not sure if this is an issue with React Router v4, the React Apollo client or my implementation.

But with <ApolloProvider> as the top-level HOC, i.e:

const ComponentsWithData = await getDataFromTree(
  <ApolloProvider client={apolloClient}>
    <StaticRouter location={ctx.request.url} context={route}>
      <App />
    </StaticRouter>,
  </ApolloProvider>,
);

const html = ReactDOMServer.renderToString(ComponentsWithData);

... I get:

Warning: Failed prop type: Invalid prop children of type array supplied to ApolloProvider, expected a single ReactElement.
      in ApolloProvider
  Error React.Children.only expected to receive a single React element child.

And flipped around, with React Router's <StaticRouter> as the top, i.e.:

const ComponentsWithData = await getDataFromTree(
  <ApolloProvider client={apolloClient}>
    <StaticRouter location={ctx.request.url} context={route}>
      <App />
    </StaticRouter>,
  </ApolloProvider>,
);

... I then get:

A <Router> may have only one child element

Rendering works fine in the browser (with React Router's <BrowserRouter>), but fails on the server.

It also works well in React Router v3 due to doing all of the route matching outside of the React hierarchy, and not declaratively inside of it.

Body:
This was actually a user error. I expected getDataFromTree() to return a Promise that resolved to the original component chain (with the correctly injected GraphQL data props), but it actually just waits for the data to be ready.

The correct format is:

const Components = (
  <StaticRouter location={ctx.request.url} context={route}>
    <ApolloProvider client={client}>
      <App />
    </ApolloProvider>
  </StaticRouter>
);

await getDataFromTree(Components);
const html = ReactDOMServer.renderToString(Components);


问:
How do websites set a maximum upload limit? Are there ways to bypass it?
For example: YouTube, before verifying your account, limits the maximum upload size to 15 minutes. How does it measure the size? Is there a way to edit the maximum upload size from your browser, make the site read the file as a 15-minute video though it's more, or is it all done on the server side, so there's no way to edit except from the server itself? This question also applies to other types of data, like text and images.</p>

答: It's fixed server size, say in PHP. It takes the file, looks at it there, and rejects it based on what the file actually is. So no, it can't be bypassed.</p>


问:
Vertical-align: middle not working?
Why isn't the vertical-align: middle; not working on my h1? The ul isn't aligning with the h1 and it should.

#logo {
 color: white;
 display: inline;
 vertical-align: middle;
}

ul {
 padding: 20px;
 background: rgba(0,0,0,.5);
}

#title {
 position: absolute;
 text-align: center;
 color: white;
 font-size: 50px;
 top: 100px;

}

#navbar {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-image: url('../img/bg.jpg');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    height: 600px;
}

li {
 float: right;
 display: inline;
}

li a {
 display: inline;
 padding: 10px 10px 10px 20px;
 text-decoration: none;
 color: white;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="navbar">
  <ul>
   <h1 id="logo">Jordan Baron</h1>
   <li>About Me</li>
   <li>Contact</li>
   <li>Projects</li>
  </ul>

  <h1 id="title">Freelance Web Developer</h1>
 </div></code>```

答:
Because vertical-align only applies to inline and table-cell elements, not block-level elements.

In order to have your links line up with your header, you need to assign a line-height equal to the height of the header element (35.33px):

```<code>li {
  line-height: 35.33px;
}
</code>```

#logo {
  color: white;
  display: inline;
  vertical-align: middle;
}

ul {
  padding: 20px;
  background: rgba(0, 0, 0, .5);
}

#title {
  position: absolute;
  text-align: center;
  color: white;
  font-size: 50px;
  top: 100px;
}

#navbar {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-image: url('../img/bg.jpg');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  height: 600px;
}

li {
  float: right;
  display: inline;
  line-height: 35.33px;
}

li a {
  display: inline;
  padding: 10px 10px 10px 20px;
  text-decoration: none;
  color: white;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="navbar">
  <ul>
    <h1 id="logo">Jordan Baron</h1>
    <li>About Me</li>
    <li>Contact</li>
    <li>Projects</li>
  </ul>

  <h1 id="title">Freelance Web Developer</h1>
</div></code>```

It's also worth noting that having a
 element as a child of
 is invalid syntax. Only
 elements shouold be a child of
. What you should do is bring the title out of the
, and float the entire
 element to the right.

Hope this helps! :)

Title: Vertical-align: middle not working?

Body:
Why isn't the vertical-align: middle; not working on my h1? The ul isn't aligning with the h1 and it should.

#logo {
 color: white;
 display: inline;
 vertical-align: middle;
}

ul {
 padding: 20px;
 background: rgba(0,0,0,.5);
}

#title {
 position: absolute;
 text-align: center;
 color: white;
 font-size: 50px;
 top: 100px;

}

#navbar {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-image: url('../img/bg.jpg');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    height: 600px;
}

li {
 float: right;
 display: inline;
}

li a {
 display: inline;
 padding: 10px 10px 10px 20px;
 text-decoration: none;
 color: white;
}

Jordan Baron

About Me

Contact

Projects

Freelance Web Developer

Body:
Because vertical-align only applies to inline and table-cell elements, not block-level elements.

In order to have your links line up with your header, you need to assign a line-height equal to the height of the header element (35.33px):

li {
  line-height: 35.33px;
}

#logo {
  color: white;
  display: inline;
  vertical-align: middle;
}

ul {
  padding: 20px;
  background: rgba(0, 0, 0, .5);
}

#title {
  position: absolute;
  text-align: center;
  color: white;
  font-size: 50px;
  top: 100px;
}

#navbar {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-image: url('../img/bg.jpg');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  height: 600px;
}

li {
  float: right;
  display: inline;
  line-height: 35.33px;
}

li a {
  display: inline;
  padding: 10px 10px 10px 20px;
  text-decoration: none;
  color: white;
}

<div id="navbar">
  <ul>
    <h1 id="logo">Jordan Baron</h1>
    <li><a href="#">About Me</a></li>
    <li><a href="#">Contact</a></li>
    <li><a href="#">Projects</a></li>
  </ul>

  <h1 id="title">Freelance Web Developer</h1>
</div>

It's also worth noting that having a <h1> element as a child of <ul> is invalid syntax. Only <li> elements shouold be a child of <ul>. What you should do is bring the title out of the <ul>, and float the entire <ul> element to the right.

Hope this helps! :)


问:
Angular 2: No provider for (injected) service
I have two services in my app - MainService and RightClickService. Only MainService is accessible globally in the application, and RightClickService is injected to MainService. Therefore, I defined the following files as:

app.module.ts

```<code>@NgModule({
  declarations: [
    AppComponent,
    ...
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [MainService],
  bootstrap: [AppComponent]
})
export class AppModule { }
</code>```

RightClickService is not mentioned in app.module.ts.

service.ts

```<code> @Injectable()
 export class MainService {

  constructor(private rightClickService: RightClickService) {
    console.log("Constructor is init");
  }
}
</code>```

RightClickService exists only in one component named inside the big application RightClickComponent.

right-click.component.ts:

```<code>@Component({
  selector: 'right-click',
  template: `
    ...
  `,
  styleUrls: ['...'],
  providers: [RightClickService]
})
export class RightClickComponent implements OnInit {

  constructor(private rightClickService: RightClickService) {}

}
</code>```

Still, I get the error:

```<code>EXCEPTION: No provider for RightClickService!
</code>```

Do you know what I'm doing wrong?

答:
I just pulled this into a Plunker, and unless I mistyped something ... what you have seems to work. So maybe there is something else wrong?

Can you check out the plunker here: https://plnkr.co/edit/ea9dFs?p=info

(The tool won't let me post without the code ... but you already have the code above ... so I'm just pasting a piece of it.)

```<code>import { Injectable } from '@angular/core'

 @Injectable()
 export class RightClickService {

  constructor() {
    console.log("RightClickService is init");
  }
}
</code>```

Body:
I have two services in my app - MainService and RightClickService. Only MainService is accessible globally in the application, and RightClickService is injected to MainService. Therefore, I defined the following files as:

app.module.ts

@NgModule({
  declarations: [
    AppComponent,
    ...
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [MainService],
  bootstrap: [AppComponent]
})
export class AppModule { }

RightClickService is not mentioned in app.module.ts.

service.ts

 @Injectable()
 export class MainService {

  constructor(private rightClickService: RightClickService) {
    console.log("Constructor is init");
  }
}

RightClickService exists only in one component named inside the big application RightClickComponent.

right-click.component.ts:

@Component({
  selector: 'right-click',
  template: `
    ...
  `,
  styleUrls: ['...'],
  providers: [RightClickService]
})
export class RightClickComponent implements OnInit {

  constructor(private rightClickService: RightClickService) {}

}

Still, I get the error:

EXCEPTION: No provider for RightClickService!

Do you know what I'm doing wrong?

Body:
I just pulled this into a Plunker, and unless I mistyped something ... what you have seems to work. So maybe there is something else wrong?

Can you check out the plunker here: https://plnkr.co/edit/ea9dFs?p=info

(The tool won't let me post without the code ... but you already have the code above ... so I'm just pasting a piece of it.)

import { Injectable } from '@angular/core'

 @Injectable()
 export class RightClickService {

  constructor() {
    console.log("RightClickService is init");
  }
}


问:
How do you put a wrapper on a git command ex. git clone
I'm trying to put a wrapper on the git clone command. In other words when I type the command "git clone user@server:group/repo.git" the git clone command would trigger a script and inside the script it would...
 1. Clone the git repository
 2. run the command "git init" on the repository

The reason I want to do this is because I want the clone projectors set up a certain way automatically.

答:
Alias the desired command:

```<code>alias git='mygit'
</code>```

create a script mygit:

```<code>#/bin/bash

if [ "$1" == "clone" ] ; then
  # do your stuff here
  echo special behavior of git clone
else
  command git "$@"
fi
</code>```

Save it somewhere the PATH variable is set to, e. g. /home/user/bin. chmod 0770 it to make it executable.

When you type git clone in the shell you will fire up your special stuff. If you type e. g. git push the script will call the original git program.

Body:
Alias the desired command:

alias git='mygit'

create a script mygit:

#/bin/bash

if [ "$1" == "clone" ] ; then
  # do your stuff here
  echo special behavior of git clone
else
  command git "$@"
fi

Save it somewhere the PATH variable is set to, e. g. /home/user/bin. chmod 0770 it to make it executable.

When you type git clone in the shell you will fire up your special stuff. If you type e. g. git push the script will call the original git program.


问:
d3 multi circle series data chart

How would this be adapted to superimpose a second set of circles?

```<code>  var data = [{
    "name": "Twitter",
    "items": [{
      "value": 2000
    }, {
      "value": 3000
    }]
  }, {
    "name": "Facebook",
    "items": [{
      "value": 200
    }, {
      "value": 300
    }]
  }, {
    "name": "Ebay",
    "items": [{
      "value": 1000
    }, {
      "value": 2000
    }]
  }, {
    "name": "Foursquare",
    "items": [{
      "value": 2000
    }, {
      "value": 3000
    }]
  }]
</code>```

with the option of adding other data sets - the goal to create a 2D pyramid of sorts with different coloured circles representing the different data sets -- with the largest dataset taking the base circle.

http://jsfiddle.net/0aqvx66j/4/

```<code>function circleMaker() {

    var counter = 0;
    series = 0

    var set = svg.append("g")
      .attr("class", "series" + series);

    set.selectAll("circle")
      .data(data)
      .enter().append("circle")
      .attr("class", "series" + series)
      .attr("cy", 60)
      .attr("cx", function(d, i) {
        if (i) {
          return (counter += Math.sqrt(data[i - 1].items[series].value) + Math.sqrt(data[i].items[series].value));
        } else {
          return counter;
        }
      })
      .attr("fill", function(d, i) {
        var colorArray = ["#00ccff", "#fcdd0a"];
        return colorArray[series];
      })
      .attr("r", function(d) {
        return Math.sqrt(d.items[series].value);
      });

}
</code>```

eventually maybe even flip between the different data sets to always place the largest circle as the background. So like this

答:
mgraham's answer is great!   But since I had already written this out (and then had to go to a meeting) here's how I would code it:

$(document).ready(function() {

  var el = $('.serieschart');
  var w = el.data("width");
  var h = el.data("height");

  var margin = {
    top: 65,
    right: 90,
    bottom: 5,
    left: 150
  };

  var svg = d3.select(el[0]).append("svg")
    .attr("class", "series")
    .attr("width", w + margin.left + margin.right)
    .attr("height", h + margin.top + margin.bottom)
    .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

  var data = [{
    "name": "Twitter",
    "items": [{
      "value": 2000
    }, {
      "value": 3000
    }]
  }, {
    "name": "Facebook",
    "items": [{
      "value": 300
    }, {
      "value": 200
    }]
  }, {
    "name": "Ebay",
    "items": [{
      "value": 1000
    }, {
      "value": 2000
    }]
  }, {
    "name": "Foursquare",
    "items": [{
      "value": 2000
    }, {
      "value": 3000
    }]
  }]

  // sort items array descending by size
  // this will help us draw the bigger one first
  // introduce an index for color assignment
  data.forEach(function(d){
   d.items.forEach(function(d1,i){
      d1.id = i;
    })
    d.items.sort(function(x, y){
      return d3.descending(x.value, y.value);
    });
  });

  circleMaker();

  function circleMaker() {

    var colors = d3.scale.category10();
    var counter = 0,
        prevR = 0;

    svg.selectAll("g")
      .data(data)
      .enter()
      .append("g")
      .selectAll("circle")
      .data(function(d){
       return d.items;
      })
      .enter()
      .append("circle")
      .attr("cy", 60)
      .attr("cx", function(d, i) {
        d.r = Math.sqrt(d.value);
        if (i === 0) {
          counter += prevR + d.r;
          prevR = d.r;
        }
        return counter;
      })
      .attr("r", function(d){
        return d.r;
      })
      .style("fill", function(d){
        return colors(d.id);
      });
  }

});```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  background: #eeeeee;
}</code>```

```

Title: d3 multi circle series data chart

Body:
How would this be adapted to superimpose a second set of circles?

  var data = [{
    "name": "Twitter",
    "items": [{
      "value": 2000
    }, {
      "value": 3000
    }]
  }, {
    "name": "Facebook",
    "items": [{
      "value": 200
    }, {
      "value": 300
    }]
  }, {
    "name": "Ebay",
    "items": [{
      "value": 1000
    }, {
      "value": 2000
    }]
  }, {
    "name": "Foursquare",
    "items": [{
      "value": 2000
    }, {
      "value": 3000
    }]
  }]

with the option of adding other data sets - the goal to create a 2D pyramid of sorts with different coloured circles representing the different data sets -- with the largest dataset taking the base circle.

http://jsfiddle.net/0aqvx66j/4/

function circleMaker() {

    var counter = 0;
    series = 0

    var set = svg.append("g")
      .attr("class", "series" + series);

    set.selectAll("circle")
      .data(data)
      .enter().append("circle")
      .attr("class", "series" + series)
      .attr("cy", 60)
      .attr("cx", function(d, i) {
        if (i) {
          return (counter += Math.sqrt(data[i - 1].items[series].value) + Math.sqrt(data[i].items[series].value));
        } else {
          return counter;
        }
      })
      .attr("fill", function(d, i) {
        var colorArray = ["#00ccff", "#fcdd0a"];
        return colorArray[series];
      })
      .attr("r", function(d) {
        return Math.sqrt(d.items[series].value);
      });

}

eventually maybe even flip between the different data sets to always place the largest circle as the background. So like this

Body:
mgraham's answer is great!   But since I had already written this out (and then had to go to a meeting) here's how I would code it:

$(document).ready(function() {

  var el = $('.serieschart');
  var w = el.data("width");
  var h = el.data("height");

  var margin = {
    top: 65,
    right: 90,
    bottom: 5,
    left: 150
  };

  var svg = d3.select(el[0]).append("svg")
    .attr("class", "series")
    .attr("width", w + margin.left + margin.right)
    .attr("height", h + margin.top + margin.bottom)
    .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

  var data = [{
    "name": "Twitter",
    "items": [{
      "value": 2000
    }, {
      "value": 3000
    }]
  }, {
    "name": "Facebook",
    "items": [{
      "value": 300
    }, {
      "value": 200
    }]
  }, {
    "name": "Ebay",
    "items": [{
      "value": 1000
    }, {
      "value": 2000
    }]
  }, {
    "name": "Foursquare",
    "items": [{
      "value": 2000
    }, {
      "value": 3000
    }]
  }]

  // sort items array descending by size
  // this will help us draw the bigger one first
  // introduce an index for color assignment
  data.forEach(function(d){
   d.items.forEach(function(d1,i){
      d1.id = i;
    })
    d.items.sort(function(x, y){
      return d3.descending(x.value, y.value);
    });
  });

  circleMaker();

  function circleMaker() {

    var colors = d3.scale.category10();
    var counter = 0,
        prevR = 0;

    svg.selectAll("g")
      .data(data)
      .enter()
      .append("g")
      .selectAll("circle")
      .data(function(d){
       return d.items;
      })
      .enter()
      .append("circle")
      .attr("cy", 60)
      .attr("cx", function(d, i) {
        d.r = Math.sqrt(d.value);
        if (i === 0) {
          counter += prevR + d.r;
          prevR = d.r;
        }
        return counter;
      })
      .attr("r", function(d){
        return d.r;
      })
      .style("fill", function(d){
        return colors(d.id);
      });
  }

});

body {
  background: #eeeeee;
}

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<div id="holder">
  <div class="serieschart" data-role="serieschart" data-width=450 data-height=180></div>
</div>


问:
Button lossing click event after jQuery animation
I have an issue that happpens only when I click fast on the button and I think it has to do something with the animations but I am not sure.

This is the DOM for side menu that slides out.

On the page there is a hamburger menu button. This button is responsible for initiating slide menu.

```<code><a class="btn-hamburger btn-ripple btn-menu" href="#">
    <i class="material-icons">menu</i>
</a>
</code>```

Somewhere in the DOM tree there is also slide out menu defained and in that menu as we can see we have pretty much the same button as the starting one.

```<code><div class="side-menu-overlay hidden">
    <div class="side-menu">
        <div class="side-menu-header">
            <a class="btn-hamburger btn-ripple btn-menu" href="#">
                <i class="material-icons">menu</i>
            </a>
        </div>
    </div>
</div>
</code>```

This is my jQuery that does the animation. As you can see from the DOM above, this event is fired for both the menu button at the start and the menu button in the slide out menu. Should the button slide out or side in depends on the class 'hidden' that is applied to overlay that hosts the slide out menu.

```<code>$(document).on('click', '.btn-menu', function (e) {
    if (sideMenuOverlay.hasClass('hidden')) {
        sideMenuOverlay.removeClass('hidden');
        sideMenuOverlay.animate({
            opacity: 1
        }, 200, function () {
            sideMenu.animate({
                 marginLeft: 0
            }, 250);
        });
    }
    else {
        sideMenu.animate({
            marginLeft: -240
        }, 200, function () {
            sideMenuOverlay.animate({
                opacity: 0
            }, 300, function () {
                sideMenuOverlay.addClass('hidden');
            });
        });
    }
});
</code>```

Problem that occurs is that the hamburger menu does not fire click events anymore. If I click the menu slowly with pauses in between, it will work all the time. As soon as I start clicking fast(to slide out and in fast) at one point the hamburger menu will not fire the event anymore. Funny enough it will always be the menu button at the start, so that means NOT when the overlay is visible and the menu is out.

答:
I have run into this problem a bunch before and solution I have found to work is to use .stop() right in front of the .animate().

See this page: http://api.jquery.com/stop/

This will stop the animate queue from stacking events and getting hosed up.

Body:
I have an issue that happpens only when I click fast on the button and I think it has to do something with the animations but I am not sure.

This is the DOM for side menu that slides out.

On the page there is a hamburger menu button. This button is responsible for initiating slide menu.

    menu

Somewhere in the DOM tree there is also slide out menu defained and in that menu as we can see we have pretty much the same button as the starting one.

                menu

This is my jQuery that does the animation. As you can see from the DOM above, this event is fired for both the menu button at the start and the menu button in the slide out menu. Should the button slide out or side in depends on the class 'hidden' that is applied to overlay that hosts the slide out menu.

$(document).on('click', '.btn-menu', function (e) {
    if (sideMenuOverlay.hasClass('hidden')) {
        sideMenuOverlay.removeClass('hidden');
        sideMenuOverlay.animate({
            opacity: 1
        }, 200, function () {
            sideMenu.animate({
                 marginLeft: 0
            }, 250);
        });
    }
    else {
        sideMenu.animate({
            marginLeft: -240
        }, 200, function () {
            sideMenuOverlay.animate({
                opacity: 0
            }, 300, function () {
                sideMenuOverlay.addClass('hidden');
            });
        });
    }
});

Problem that occurs is that the hamburger menu does not fire click events anymore. If I click the menu slowly with pauses in between, it will work all the time. As soon as I start clicking fast(to slide out and in fast) at one point the hamburger menu will not fire the event anymore. Funny enough it will always be the menu button at the start, so that means NOT when the overlay is visible and the menu is out.


问:
How to read json data from URL in Android
I am having some issues with the following code. I am trying to read from the following Reddit URL

```<code>https://www.reddit.com/r/earthporn/.json?after=
</code>```

Here is the code that is not correctly being executed.

```<code>public static String readContents(String url){
        try{
        InputStream input= new URL(url).openStream();
        Reader reader = new InputStreamReader(input);
        BufferedReader in = new BufferedReader(reader);
        String line, str;
        str = "";
        while ((line=in.readLine()) != null) {
            str += line;
            System.out.println(line);
        }
        return str;
        }catch(IOException e){
            Log.d("READ FAILED", e.toString());
            return null;
        }
    }
}
</code>```

And here is where I call it from

```<code>List<Post> fetchPosts(){
    String raw=RemoteData.readContents(url);
    List<Post> list=new ArrayList<Post>();
    try{
        JSONObject data=new JSONObject(raw).getJSONObject("data");
        JSONArray children=data.getJSONArray("children");

        //Using this property we can fetch the next set of
        //posts from the same subreddit
        after=data.getString("after");

        for(int i=0;i<children.length();i++){
            JSONObject cur=children.getJSONObject(i)
                    .getJSONObject("data");
            Post p=new Post();
            p.title=cur.optString("title");
            p.url=cur.optString("url");
            p.numComments=cur.optInt("num_comments");
            p.points=cur.optInt("score");
            p.author=cur.optString("author");
            p.subreddit=cur.optString("subreddit");
            p.permalink=cur.optString("permalink");
            p.domain=cur.optString("domain");
            p.id=cur.optString("id");
            p.thumbnail=cur.optString("thumbnail");
            if(p.title!=null)
                list.add(p);
        }
    }catch(Exception e){
        Log.e("fetchPosts()",e.toString());
    }
    return list;
}
</code>```

When debugging I get the following results:
Raw is left empty.

Does anyone have any clue as to why this it is not reading anything? I hope I included enough code for it to make sense. If anymore is needed, please let me know.

答:
Hello to get response you must open an HttpsURLConnection the problem that you have is you getting a null response from the URL so  you  must here is the code that works for me : </p>

```<code>import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.MalformedURLException;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

public class main {
    public static String getJSON(String url) {
        HttpsURLConnection con = null;
        try {
            URL u = new URL(url);
            con = (HttpsURLConnection) u.openConnection();

            con.connect();

                BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
                StringBuilder sb = new StringBuilder();
                String line;
                while ((line = br.readLine()) != null) {
                    sb.append(line + "\n");
                }
                br.close();
                return sb.toString();

        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (con != null) {
                try {
                    con.disconnect();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {

        String url = "https://www.reddit.com/r/earthporn/.json?after=";
        System.out.println(getJSON(url));

    }

}
</code>```

Body:
I am having some issues with the following code. I am trying to read from the following Reddit URL

https://www.reddit.com/r/earthporn/.json?after=

Here is the code that is not correctly being executed.

public static String readContents(String url){
        try{
        InputStream input= new URL(url).openStream();
        Reader reader = new InputStreamReader(input);
        BufferedReader in = new BufferedReader(reader);
        String line, str;
        str = "";
        while ((line=in.readLine()) != null) {
            str += line;
            System.out.println(line);
        }
        return str;
        }catch(IOException e){
            Log.d("READ FAILED", e.toString());
            return null;
        }
    }
}

And here is where I call it from

List<Post> fetchPosts(){
    String raw=RemoteData.readContents(url);
    List<Post> list=new ArrayList<Post>();
    try{
        JSONObject data=new JSONObject(raw).getJSONObject("data");
        JSONArray children=data.getJSONArray("children");

        //Using this property we can fetch the next set of
        //posts from the same subreddit
        after=data.getString("after");

        for(int i=0;i<children.length();i++){
            JSONObject cur=children.getJSONObject(i)
                    .getJSONObject("data");
            Post p=new Post();
            p.title=cur.optString("title");
            p.url=cur.optString("url");
            p.numComments=cur.optInt("num_comments");
            p.points=cur.optInt("score");
            p.author=cur.optString("author");
            p.subreddit=cur.optString("subreddit");
            p.permalink=cur.optString("permalink");
            p.domain=cur.optString("domain");
            p.id=cur.optString("id");
            p.thumbnail=cur.optString("thumbnail");
            if(p.title!=null)
                list.add(p);
        }
    }catch(Exception e){
        Log.e("fetchPosts()",e.toString());
    }
    return list;
}

When debugging I get the following results:
Raw is left empty.

Does anyone have any clue as to why this it is not reading anything? I hope I included enough code for it to make sense. If anymore is needed, please let me know.

Body:
Hello to get response you must open an HttpsURLConnection the problem that you have is you getting a null response from the URL so  you  must here is the code that works for me :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import java.net.MalformedURLException;
import java.net.URL;

import javax.net.ssl.HttpsURLConnection;

public class main {
    public static String getJSON(String url) {
        HttpsURLConnection con = null;
        try {
            URL u = new URL(url);
            con = (HttpsURLConnection) u.openConnection();

            con.connect();

                BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
                StringBuilder sb = new StringBuilder();
                String line;
                while ((line = br.readLine()) != null) {
                    sb.append(line + "\n");
                }
                br.close();
                return sb.toString();

        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (con != null) {
                try {
                    con.disconnect();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {

        String url = "https://www.reddit.com/r/earthporn/.json?after=";
        System.out.println(getJSON(url));

    }

}


问:
2D Array stream reduce in java
I'm new to using streams in java and I have a question on using streams.
I have a double[][] in which i want to perform the summation of elements, for it I've written the following approach similar to C#Linq, but it doesn't seem to work.

```<code>Arrays.stream(myArray).reduce(0,(acc, i) -> acc + Arrays.stream(i).sum());
</code>```

The error is that acc seems to be a double[], so it can't perform double[]+double.
In C#Linq the accumulator is assumed to be the same type as the seed(0 in this case). What am I missing here?
Thanks in advance.

答:
If you look at the signature of reduce, the type of the identity has to be the type of the stream's elements. Which would be double[] in this case. That would also give acc the type of double[].

There is an overload where you can supply an accumulator of a different type, but you also need to pass a combiner, to combine 2 accumulators.

You can do this:

```<code>double result = Arrays.stream(myArray)
    .reduce(0D, (acc, i) -> acc + Arrays.stream(i).sum(), Double::sum);
</code>```

Where 0D is a double literal, and Double::sum is used to combine 2 accumulators.

Alternatively, it might be more convenient to do this:

```<code>double result = Arrays.stream(myArray)
    .flatMapToDouble(DoubleStream::of)
    .sum();
</code>```

ContentLicense: CC BY-SA 4.0

Title: 2D Array stream reduce in java

Body:
I'm new to using streams in java and I have a question on using streams.
I have a double[][] in which i want to perform the summation of elements, for it I've written the following approach similar to C#Linq, but it doesn't seem to work.

Arrays.stream(myArray).reduce(0,(acc, i) -> acc + Arrays.stream(i).sum());

The error is that acc seems to be a double[], so it can't perform double[]+double.
In C#Linq the accumulator is assumed to be the same type as the seed(0 in this case). What am I missing here?
Thanks in advance.

Body:
If you look at the signature of reduce, the type of the identity has to be the type of the stream's elements. Which would be double[] in this case. That would also give acc the type of double[].

There is an overload where you can supply an accumulator of a different type, but you also need to pass a combiner, to combine 2 accumulators.

You can do this:

double result = Arrays.stream(myArray)
    .reduce(0D, (acc, i) -> acc + Arrays.stream(i).sum(), Double::sum);

Where 0D is a double literal, and Double::sum is used to combine 2 accumulators.

Alternatively, it might be more convenient to do this:

double result = Arrays.stream(myArray)
    .flatMapToDouble(DoubleStream::of)
    .sum();


问:
How to select data top x data after y rows from SQL Server
For example I have a table which contains 10'000 rows. I want to select top 100 rows after top 500th row. How can I do this most efficiently.

Query needed for SQL Server 2008

For example i have this query already but i wonder are there any more effective solution

```<code>SELECT TOP 100 xx
FROM nn
WHERE cc NOT IN
   (SELECT TOP 500 cc
      FROM nn ORDER BY cc ASC)
</code>```

答:
```<code>SELECT
  col1,
  col2
FROM (
    SELECT ROW_NUMBER() OVER (
        ORDER BY [t0].someColumn) as ROW_NUMBER,
    col1,
    col2
    FROM [dbo].[someTable] AS [t0]
    ) AS [t1]
WHERE [t1].[ROW_NUMBER] BETWEEN 501 and 600
ORDER BY [t1].[ROW_NUMBER]
</code>```

Body:
For example I have a table which contains 10'000 rows. I want to select top 100 rows after top 500th row. How can I do this most efficiently.

Query needed for SQL Server 2008

For example i have this query already but i wonder are there any more effective solution

SELECT TOP 100 xx
FROM nn
WHERE cc NOT IN
   (SELECT TOP 500 cc
      FROM nn ORDER BY cc ASC)

ContentLicense: CC BY-SA 2.5


问:
How to check if a nested list contain only empty strings
In pyqt I have a qtableview which a user can edit. If the users makes a change to the table, the table will be copied when the user is done. If no changes are made, the table is skipped. The table is filled with empty strings i.e:

```<code>table = [["","",""],["","",""]]
</code>```

I want to check if the table contains only "", and if it does, ignore it. If it doesnt, i.e. contains a "1", some code runs on the list.
Now I have a working code but its not very pythonic and I wonder how I can improve it. My code is as follows:

```<code>tabell1 = [["","",""],["","",""]]
meh = 0
for item in self.tabell1:
    for item1 in item:
        if item1 == "":
            pass
        else:
            meh = 1
if meh == 1:
    do the thing
</code>```

答:
Or you could avoid looping through the list by converting it to a string, removing all the characters that would only appear if it were empty, then checking if it is empty or not:

```<code>tabell1 = [["","",""],["","",""]]
if not str(tabell1).translate(None, "[]\"\', "):
    #do the thing
</code>```

Although this will mean that any tables containing only instances of [, ], ", ', and  will be considered empty.

Body:
In pyqt I have a qtableview which a user can edit. If the users makes a change to the table, the table will be copied when the user is done. If no changes are made, the table is skipped. The table is filled with empty strings i.e:

table = [["","",""],["","",""]]

I want to check if the table contains only "", and if it does, ignore it. If it doesnt, i.e. contains a "1", some code runs on the list.
Now I have a working code but its not very pythonic and I wonder how I can improve it. My code is as follows:

tabell1 = [["","",""],["","",""]]
meh = 0
for item in self.tabell1:
    for item1 in item:
        if item1 == "":
            pass
        else:
            meh = 1
if meh == 1:
    do the thing

Body:
Or you could avoid looping through the list by converting it to a string, removing all the characters that would only appear if it were empty, then checking if it is empty or not:

tabell1 = [["","",""],["","",""]]
if not str(tabell1).translate(None, "[]\"\', "):
    #do the thing

Although this will mean that any tables containing only instances of [, ], ", ', and  will be considered empty.