Q: Error Create Datasource JBOSS 7.1.1 FINAL Error when deploying the server I get this error in jboss 7.1.1 final
log Error:
09:44:28,645 INFORMACIÓN [org.jboss.modules] JBoss Modules version 1.1.1.GA
09:44:28,865 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA
09:44:28,935 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting
09:44:29,924 INFO  [org.xnio] XNIO Version 3.0.3.GA
09:44:29,924 INFO  [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
09:44:29,944 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA
09:44:29,954 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA
09:44:29,975 INFO  [org.jboss.as.configadmin] JBAS016200: Activating ConfigAdmin Subsystem
09:44:29,988 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers
09:44:30,005 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 44) JBAS013101: Activating Security Subsystem
09:44:30,017 INFO  [org.jboss.as.security] (MSC service thread 1-2) JBAS013100: Current PicketBox version=4.0.7.Final
09:44:30,067 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 38) JBAS011800: Activating Naming Subsystem
09:44:30,097 INFO  [org.jboss.as.osgi] (ServerService Thread Pool -- 39) JBAS011940: Activating OSGi Subsystem
09:44:30,097 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 31) JBAS010280: Activating Infinispan subsystem.
09:44:30,109 INFO  [org.jboss.as.naming] (MSC service thread 1-4) JBAS011802: Starting Naming Service
09:44:30,125 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension
09:44:30,179 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-3) JBAS015400: Bound mail session [java:jboss/mail/Default]
09:44:30,241 INFO  [org.jboss.as.connector] (MSC service thread 1-5) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)
09:44:30,341 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-5) JBoss Web Services - Stack CXF Server 4.0.2.GA
09:44:30,350 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
09:44:30,386 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
09:44:30,390 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.fabric.jdbc.FabricMySQLDriver (version 5.1)
09:44:30,393 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 27) JBAS014612: Operation ("add") failed - address: ([
    ("subsystem" => "datasources"),
    ("jdbc-driver" => "mysql")
]): org.jboss.msc.service.DuplicateServiceException: Service jboss.jdbc-driver.mysql is already registered
    at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:154) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:227) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:560) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:201) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2228) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.msc.service.ServiceBuilderImpl.install(ServiceBuilderImpl.java:307) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at org.jboss.as.controller.OperationContextImpl$ContextServiceBuilder.install(OperationContextImpl.java:955) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.connector.subsystems.datasources.JdbcDriverAdd.startDriverServices(JdbcDriverAdd.java:164) [jboss-as-connector-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.connector.subsystems.datasources.JdbcDriverAdd.performRuntime(JdbcDriverAdd.java:128) [jboss-as-connector-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractAddStepHandler$1.execute(AbstractAddStepHandler.java:50) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:385) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:272) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:200) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.connector.subsystems.datasources.DataSourceEnable$1.execute(DataSourceEnable.java:91) [jboss-as-connector-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:385) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:272) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:200) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.connector.subsystems.datasources.DataSourceEnable$1.execute(DataSourceEnable.java:91) [jboss-as-connector-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:385) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:272) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:200) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.controller.ParallelBootOperationStepHandler$ParallelBootTask.run(ParallelBootOperationStepHandler.java:311) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_72]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_72]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_72]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.0.0.GA.jar:2.0.0.GA]

09:44:30,836 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-4) Arrancando Coyote HTTP/1.1 en puerto http-localhost-127.0.0.1-8080

jboss-as-7.1.1.Final\standalone\configuration\standalone.xml
<?xml version='1.0' encoding='UTF-8'?>

<server xmlns="urn:jboss:domain:1.2">
    <extensions>
        <extension module="org.jboss.as.clustering.infinispan"/>
        <extension module="org.jboss.as.configadmin"/>
        <extension module="org.jboss.as.connector"/>
        <extension module="org.jboss.as.deployment-scanner"/>
        <extension module="org.jboss.as.ee"/>
        <extension module="org.jboss.as.ejb3"/>
        <extension module="org.jboss.as.jaxrs"/>
        <extension module="org.jboss.as.jdr"/>
        <extension module="org.jboss.as.jmx"/>
        <extension module="org.jboss.as.jpa"/>
        <extension module="org.jboss.as.logging"/>
        <extension module="org.jboss.as.mail"/>
        <extension module="org.jboss.as.naming"/>
        <extension module="org.jboss.as.osgi"/>
        <extension module="org.jboss.as.pojo"/>
        <extension module="org.jboss.as.remoting"/>
        <extension module="org.jboss.as.sar"/>
        <extension module="org.jboss.as.security"/>
        <extension module="org.jboss.as.threads"/>
        <extension module="org.jboss.as.transactions"/>
        <extension module="org.jboss.as.web"/>
        <extension module="org.jboss.as.webservices"/>
        <extension module="org.jboss.as.weld"/>
    </extensions>
    <management>
        <security-realms>
            <security-realm name="ManagementRealm">
                <authentication>
                    <properties path="mgmt-users.properties" relative-to="jboss.server.config.dir"/>
                </authentication>
            </security-realm>
            <security-realm name="ApplicationRealm">
                <authentication>
                    <properties path="application-users.properties" relative-to="jboss.server.config.dir"/>
                </authentication>
            </security-realm>
        </security-realms>
        <management-interfaces>
            <native-interface security-realm="ManagementRealm">
                <socket-binding native="management-native"/>
            </native-interface>
            <http-interface security-realm="ManagementRealm">
                <socket-binding http="management-http"/>
            </http-interface>
        </management-interfaces>
    </management>
    <profile>
        <subsystem xmlns="urn:jboss:domain:logging:1.1">
            <console-handler name="CONSOLE">
                <level name="INFO"/>
                <formatter>
                    <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                </formatter>
            </console-handler>
            <periodic-rotating-file-handler name="FILE">
                <formatter>
                    <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
                </formatter>
                <file relative-to="jboss.server.log.dir" path="server.log"/>
                <suffix value=".yyyy-MM-dd"/>
                <append value="true"/>
            </periodic-rotating-file-handler>
            <logger category="com.arjuna">
                <level name="WARN"/>
            </logger>
            <logger category="org.apache.tomcat.util.modeler">
                <level name="WARN"/>
            </logger>
            <logger category="sun.rmi">
                <level name="WARN"/>
            </logger>
            <logger category="jacorb">
                <level name="WARN"/>
            </logger>
            <logger category="jacorb.config">
                <level name="ERROR"/>
            </logger>
            <root-logger>
                <level name="INFO"/>
                <handlers>
                    <handler name="CONSOLE"/>
                    <handler name="FILE"/>
                </handlers>
            </root-logger>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:configadmin:1.0"/>
        <subsystem xmlns="urn:jboss:domain:datasources:1.0">
            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
                    <driver>h2</driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <datasource jndi-name="java:jboss/datasources/EvelingDs" pool-name="EvelingDs" enabled="true" use-java-context="true">
                    <connection-url>jdbc:mysql://localhost:3306/proyectoEveling</connection-url>
                    <driver>mysql</driver>
                    <security>
                        <user-name>infra</user-name>
                        <password>infra_pass</password>
                    </security>
                </datasource>
                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                      <driver name="mysql" module="com.mysql"/>
                </drivers>
            </datasources>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
            <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000"/>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:ee:1.0"/>
        <subsystem xmlns="urn:jboss:domain:ejb3:1.2">
            <session-bean>
                <stateless>
                    <bean-instance-pool-ref pool-name="slsb-strict-max-pool"/>
                </stateless>
                <stateful default-access-timeout="5000" cache-ref="simple"/>
                <singleton default-access-timeout="5000"/>
            </session-bean>
            <pools>
                <bean-instance-pools>
                    <strict-max-pool name="slsb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
                    <strict-max-pool name="mdb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/>
                </bean-instance-pools>
            </pools>
            <caches>
                <cache name="simple" aliases="NoPassivationCache"/>
                <cache name="passivating" passivation-store-ref="file" aliases="SimpleStatefulCache"/>
            </caches>
            <passivation-stores>
                <file-passivation-store name="file"/>
            </passivation-stores>
            <async thread-pool-name="default"/>
            <timer-service thread-pool-name="default">
                <data-store path="timer-service-data" relative-to="jboss.server.data.dir"/>
            </timer-service>
            <remote connector-ref="remoting-connector" thread-pool-name="default"/>
            <thread-pools>
                <thread-pool name="default">
                    <max-threads count="10"/>
                    <keepalive-time time="100" unit="milliseconds"/>
                </thread-pool>
            </thread-pools>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:infinispan:1.2" default-cache-container="hibernate">
            <cache-container name="hibernate" default-cache="local-query">
                <local-cache name="entity">
                    <transaction mode="NON_XA"/>
                    <eviction strategy="LRU" max-entries="10000"/>
                    <expiration max-idle="100000"/>
                </local-cache>
                <local-cache name="local-query">
                    <transaction mode="NONE"/>
                    <eviction strategy="LRU" max-entries="10000"/>
                    <expiration max-idle="100000"/>
                </local-cache>
                <local-cache name="timestamps">
                    <transaction mode="NONE"/>
                    <eviction strategy="NONE"/>
                </local-cache>
            </cache-container>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:jaxrs:1.0"/>
        <subsystem xmlns="urn:jboss:domain:jca:1.1">
            <archive-validation enabled="true" fail-on-error="true" fail-on-warn="false"/>
            <bean-validation enabled="true"/>
            <default-workmanager>
                <short-running-threads>
                    <core-threads count="50"/>
                    <queue-length count="50"/>
                    <max-threads count="50"/>
                    <keepalive-time time="10" unit="seconds"/>
                </short-running-threads>
                <long-running-threads>
                    <core-threads count="50"/>
                    <queue-length count="50"/>
                    <max-threads count="50"/>
                    <keepalive-time time="10" unit="seconds"/>
                </long-running-threads>
            </default-workmanager>
            <cached-connection-manager/>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:jdr:1.0"/>
        <subsystem xmlns="urn:jboss:domain:jmx:1.1">
            <show-model value="true"/>
            <remoting-connector/>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:jpa:1.0">
            <jpa default-datasource=""/>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:mail:1.0">
            <mail-session jndi-name="java:jboss/mail/Default">
                <smtp-server outbound-socket-binding-ref="mail-smtp"/>
            </mail-session>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:naming:1.1"/>
        <subsystem xmlns="urn:jboss:domain:osgi:1.2" activation="lazy">
            <properties>
                <!-- Specifies the beginning start level of the framework -->
                <property name="org.osgi.framework.startlevel.beginning">1</property>
            </properties>
            <capabilities>
                <!-- modules registered with the OSGi layer on startup -->
                <capability name="javax.servlet.api:v25"/>
                <capability name="javax.transaction.api"/>
                <!-- bundles started in startlevel 1 -->
                <capability name="org.apache.felix.log" startlevel="1"/>
                <capability name="org.jboss.osgi.logging" startlevel="1"/>
                <capability name="org.apache.felix.configadmin" startlevel="1"/>
                <capability name="org.jboss.as.osgi.configadmin" startlevel="1"/>
            </capabilities>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:pojo:1.0"/>
        <subsystem xmlns="urn:jboss:domain:remoting:1.1">
            <connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"/>
        <subsystem xmlns="urn:jboss:domain:sar:1.0"/>
        <subsystem xmlns="urn:jboss:domain:security:1.1">
            <security-domains>
                <security-domain name="other" cache-type="default">
                    <authentication>
                        <login-module code="Remoting" flag="optional">
                            <module-option name="password-stacking" value="useFirstPass"/>
                        </login-module>
                        <login-module code="RealmUsersRoles" flag="required">
                            <module-option name="usersProperties" value="${jboss.server.config.dir}/application-users.properties"/>
                            <module-option name="rolesProperties" value="${jboss.server.config.dir}/application-roles.properties"/>
                            <module-option name="realm" value="ApplicationRealm"/>
                            <module-option name="password-stacking" value="useFirstPass"/>
                        </login-module>
                    </authentication>
                </security-domain>
                <security-domain name="jboss-web-policy" cache-type="default">
                    <authorization>
                        <policy-module code="Delegating" flag="required"/>
                    </authorization>
                </security-domain>
                <security-domain name="jboss-ejb-policy" cache-type="default">
                    <authorization>
                        <policy-module code="Delegating" flag="required"/>
                    </authorization>
                </security-domain>
            </security-domains>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:threads:1.1"/>
        <subsystem xmlns="urn:jboss:domain:transactions:1.1">
            <core-environment>
                <process-id>
                    <uuid/>
                </process-id>
            </core-environment>
            <recovery-environment socket-binding="txn-recovery-environment" status-socket-binding="txn-status-manager"/>
            <coordinator-environment default-timeout="300"/>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">
            <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
            <virtual-server name="default-host" enable-welcome-root="true">
                <alias name="localhost"/>
                <alias name="example.com"/>
            </virtual-server>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:webservices:1.1">
            <modify-wsdl-address>true</modify-wsdl-address>
            <wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host>
            <endpoint-config name="Standard-Endpoint-Config"/>
            <endpoint-config name="Recording-Endpoint-Config">
                <pre-handler-chain name="recording-handlers" protocol-bindings="##SOAP11_HTTP ##SOAP11_HTTP_MTOM ##SOAP12_HTTP ##SOAP12_HTTP_MTOM">
                    <handler name="RecordingHandler" class="org.jboss.ws.common.invocation.RecordingServerHandler"/>
                </pre-handler-chain>
            </endpoint-config>
        </subsystem>
        <subsystem xmlns="urn:jboss:domain:weld:1.0"/>
    </profile>
    <interfaces>
        <interface name="management">
            <inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
        </interface>
        <interface name="public">
            <inet-address value="${jboss.bind.address:127.0.0.1}"/>
        </interface>
        <!-- TODO - only show this if the jacorb subsystem is added  -->
        <interface name="unsecure">
            <!--
              ~  Used for IIOP sockets in the standard configuration.
              ~                  To secure JacORB you need to setup SSL
              -->
            <inet-address value="${jboss.bind.address.unsecure:127.0.0.1}"/>
        </interface>
    </interfaces>
    <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
        <socket-binding name="management-native" interface="management" port="${jboss.management.native.port:9999}"/>
        <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
        <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9443}"/>
        <socket-binding name="ajp" port="8009"/>
        <socket-binding name="http" port="8080"/>
        <socket-binding name="https" port="8443"/>
        <socket-binding name="osgi-http" interface="management" port="8090"/>
        <socket-binding name="remoting" port="4447"/>
        <socket-binding name="txn-recovery-environment" port="4712"/>
        <socket-binding name="txn-status-manager" port="4713"/>
        <outbound-socket-binding name="mail-smtp">
            <remote-destination host="localhost" port="25"/>
        </outbound-socket-binding>
    </socket-binding-group>
</server>

jboss-as-7.1.1.Final\modules\com\mysql\module.xml
<module xmlns="urn:jboss:module:1.1" name="com.mysql">

    <resources>
        <resource-root path="mysql-connector-java-5.1.34-bin.jar"/>
        <!-- Insert resources here -->
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>

Thank you for the help you can...

A: Although this one looks old for the benefit of others who happen to stumble upon the same one
please add

<driver-class>com.mysql.jdbc.Driver</driver-class>  to your driver definition in standalone.xml

  complete entry

<drivers>
 <driver name="com.mysql" module="com.mysql">
 <driver-class>com.mysql.jdbc.Driver</driver-class>
 <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
 </driver>
</drivers>


Q: unable to use R's future package for lasso regression with glmnet I recently discovered R's future package and have already successfully used it.
However I am unable to use this package together with predictions for lasso regressions.
In the following toy example I first create some toy data, then fit a lasso regression and finally I make a prediction for new data.
I do this procedure twice: once without the future package and then with the future package:
library(tidyverse)
library(glmnet)

set.seed(1)
a <- tibble(id = rep(letters[1:2], each = 100), x1 = rnorm(200), x2 = rnorm(200),
            y = 1 + 2*x2 + rnorm(200))

newdata <- as.matrix(data.frame(x1 = rnorm(200), x2 = rnorm(200)))

pred_func <- function(z) predict(z, newx = newdata)[,1]

b1 <- a %>%
  group_by(id) %>%
  nest(.key = data) %>%
  mutate(lasso = map(data, function(z){glmnet(x = as.matrix(select(z, x1, x2)), y = z$y,
                                                 intercept = T, alpha = 1)})) %>%
  mutate(myprediction = map(lasso, pred_func))

This works just fine. Now with the future package:
library(future)

plan(multiprocess)
b2 <- a %>%
  group_by(id) %>%
  nest(.key = data) %>%
  mutate(lasso = map(data, function(z){glmnet(x = as.matrix(select(z, x1, x2)), y = z$y,
                                              intercept = T, alpha = 1)})) %>%
  mutate(myprediction_future = map(lasso, ~future(pred_func(.x)))) %>%
  mutate(myprediction = values(myprediction_future))

This terminates with an error (which is in german). Basically it tells me that it cannot use predict for an object of class elnet, glmnet.
I first thought that maybe there is a different predict function in the future package but this does not seem to be the case.
Since I do not really understand what happens behind the curtains of the future functions I feel stuck with this one.
EDIT:
here is the error message in english:
Error in mutate_impl(.data, dots) :
Evaluation error: no applicable method for 'predict' applied to
an object of class "c('elnet', 'glmnet')".

A: There's a predict.glmnet() in glmnet package.
Just define a new function.
pred_func2 <- function(z) predict.glmnet(z, newx = newdata)[,1]

And run.
plan(multiprocess)
b2 <- a %>%
  group_by(id) %>%
  nest(.key=data) %>%
  mutate(lasso=map(data,
                     function(z) {
                       glmnet(x=as.matrix(select(z, x1, x2)), y=z$y,
                              intercept=TRUE, alpha=1)
                       })) %>%
  mutate(myprediction_future=map(lasso, ~future(pred_func2(.x)))) %>%
  mutate(myprediction=values(myprediction_future))

Yielding
> b2
# A tibble: 2 x 5
  id    data               lasso       myprediction_future      myprediction
  <chr> <list>             <list>      <list>                   <list>
1 a     <tibble [100 x 3]> <S3: elnet> <S3: MultisessionFuture> <dbl [200]>
2 b     <tibble [100 x 3]> <S3: elnet> <S3: MultisessionFuture> <dbl [200]>


Q: PHP ftp_connect does nothing I've configured a couple of php codes that connects to my server with the use of ftp connect. It works perfectly when I'm testing it locally, it connects, it goes in, i can access stuff.
BUT
when I upload it online and try it there. The php code does nothing. It executes all lines before "ftp_connect" then from that line onwards, it doesn't get processed.
It doesn't show any errors, warnings, etc on screen but the code execution from the line of "ftp_connect" just stops.
What seems to be the problem?

A: Your host probably has error reporting turned off, try turning on error reporting with
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

at the top of your file, or check for a file called error_log in the directory of your script.


Q: Did the city search data from the Facebook Ads API suddenly change? The City Search call used to return a response where each city had the form:
{
  "name": "Dublin, CA",
  "key": 220522764,
  "subtext": "CA, United States"
}

Now the API returns:
{
  "name": "Dublin",
  "key": 220522764,
  "subtext": "California, United States"
}

The first format is still listed in the API docs here: https://developers.facebook.com/docs/reference/ads-api/get-autocomplete-data/
Is this a permanent change?

A: Yes, last week. No warning from Facebook.

A: Our apologies for this change - we've reverted this change and will take precaution to avoid these things in the future. Thank you for the report.
We've added another parameter to use in your query if you want to get the city name without the state. Documentation updated: https://developers.facebook.com/docs/reference/ads-api/get-autocomplete-data/


Q: "Task timed out after..." when connecting to a MongoDB database in an AWS Lambda function I am have Node.js script where in the beginning of it I connect to my MongoDB database and get a specific collection and use that within the script. I set this script up in an AWS Lambda function with a timeout of 10 seconds. When I test the AWS Lambda  with a configured test event, I get a "Task timed out after 10.00 seconds". My script is still suppose to run after it connects and finish the rest of the script. However, it stops and I get a timeout error from AWS Lambda. If I set a timeout higher, such as 15 minutes, I get the timeout error 15 minutes after I connect to the MongoDB database within the script (I got this my looking at the CloudWatch logs for the AWS Lambda function). I experimented with different timeout timings and found that for x seconds I set the timeout, my script will give the timeout error x seconds after I connect to the MongoDB database. I followed all best practices mentioned in this article about connecting to MongoDB from AWS Lambda and they are are: defining the MongoDB client connection outside the handler function and setting the context property callbackWaitsForEmptyEventLoop to false. I am not sure how to fix this. Below is some relevant code I used in my script:
main.ts:
import { connectToDatabase } from './mongodb'
import mongodb from 'mongodb'

export const handler = async (event: any, context: any, callback: any) => {
    context.callbackWaitsForEmptyEventLoop = false
    const db = await connectToDatabase().then((db: mongodb.Db) => db).catch(error => error)
    var collection: mongodb.Collection = db.collection("{collection-name}")
    // Rest of the script
}

mongodb.ts:
import mongodb, { MongoClient } from "mongodb"

let uri: undefined | string = process.env.MONGODB_URI
let dbName: undefined | string = process.env.MONGODB_DB

let cachedClient: null | mongodb.MongoClient = null
let cachedDb: null | mongodb.Db = null

export async function connectToDatabase() {
  if (cachedClient && cachedDb) {
    return cachedDb
  }

  if (!uri) {
    throw new Error(
      "Please define the MONGODB_URI environment variable inside .env.local"
    )
  }

  if (!dbName) {
    throw new Error(
      "Please define the MONGODB_DB environment variable inside .env.local"
    )
  }

  const client = await MongoClient.connect(uri, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  })

  const db = client.db(dbName)

  cachedClient = client
  cachedDb = db

  return db
}

Other info: I use serverless to push the script to AWS Lambda and also using serverless plugin "serverless-webpack" for TypeScript files.

A: The best practice linked in your article says Define the MongoDB client connection outside of your handler function. In your case you should change const db = ... to db = ... and declare db outside of your handler function and change it to let db = null like in the example in the article, so you can reuse the connections in different Lambda invocations. For example:
let db = null;

export const handler = async (event, context, callback) => {
  if (!db) {
    db = connectToDatabase();
  }

  // do something with your db

  callback();
};

Besides that, take @hoangdv 's advice and call the callback function to signal AWS Lambda that you're done with handling the event. That should do the trick.

A: I found that AWS Lambda functions can only run for a maximum of 15 minutes (even if the code is still running after that amount of time). If I wanted to run the script for more than 15 minutes, I guess I would have to use an AWS EC2 instance.
Source: https://aws.amazon.com/lambda/faqs/

A: I have a similar issue with trying so many different approaches, having a larger maximum memory, and having a longer latency time. but they fail to solve it.
Then I found a solution by not using the whole parameter, its' value may be changed, outside of functions. Because cache can store the param in memory. it may lead the program to read the value from cache memory.
So put cachedClient, cachedDb defining in function:connectToDatabase not out of function.


Q: Why doesn't the 'Add' type satisfy the constraint 'number'? I tried practicing type gymnastics with typescript.And my goal is Implementing mathematical operations on numeric literals.
First of all,I implemented type BuildArray:
type BuildArray<
    Length extends number,
    Ele = unknown,
    Arr extends unknown[] = []
> = Arr['length'] extends Length
        ? Arr
        : BuildArray<Length, Ele, [...Arr, Ele]>;
type MyArray = BuildArray<3> // type MyArray = [unknown, unknown, unknown]

Then,I implemented type Add:
type Add<Num1 extends number, Num2 extends number> =
    [...BuildArray<Num1>, ...BuildArray<Num2>]['length']
type AddResult = Add<2, 5> // type AddResult = 7

However, when I tried implementing Multiply based on Add,it occured error:
type Multiply<Num1 extends number, Num2 extends number, Counter extends number = 0, Result extends number = 0> =
    Counter extends Num2?
    Result:
    Multiply<Num1, Num2, Add<Counter, 1>, Add<Num1, Result>>
type MultiplyResult = Multiply<4, 5> // type MultiplyResult = 20

Though the result is correct, it occured compile error:

Playground link
Can someone please tell me why this compilation error occurs?

A: When you are passing Counter in Add<Counter, 1>, it's extending the type number, but it's still unknown number. When it's passed from Add to BuildArray, you then have this check:
Arr['length'] extends Length?

and based on that check, you have different expected types Arr or BuildArray<Length, Ele, [...Arr, Ele]> which will again have the same issue.
Going back to Add, in the case of unknown number, TypeScript won't achieve that this length prop is the prop of an Array, which is already a number.
So you get the value correctly, but the type itself is still not sure that this is a number, because the check Arr['length'] extends Length? in BuildArray is not resolved to know that the Arr is the type that we are trying to access length from.
I am not sure if this was clear enough, but TL;DR: To achieve what you need with the minimum changes, you need to tell TypeScript that this Add type will always be a number instead of relying on TypeScript to learn that by itself.
For example, you can force this info by adding & number:
type Add<Num1 extends number, Num2 extends number> =
    [...BuildArray<Num1>, ...BuildArray<Num2>]['length'] & number
// −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−^^^^^^^^

or have any kind of type checks.
Playground link

A: This is because here you are extending with number
Counter extends number = 0, Result extends number = 0

and your Add<num1, num2> type returns a narrowed number.
For example: type AddResult = Add<2, 5> // type AddResult = 7
when you do typeof AddResult, the output would be 7 (for TS it is unknown) and not number and that's why the error occured.


Q: Doctrine2 Custom Type Not Returning Data iam regreting for last two days since came to my mind that i could create encrypted custom type, so that encryption and decryption of data would be done in that type so that i dont need to call those functions evrytime, generally to make my life easier but it turn it into living hell :/
My custom type is inserting encrypted data in the database as i intended but problem is when i need to retrive data, here is print of object that holds retrived data from database
    Uapi\CoreBundle\Entity\Request Object
(
    [id:Uapi\CoreBundle\Entity\Request:private] => 2
    [clientIPAdress:Uapi\CoreBundle\Entity\Request:private] =>
    [clientHost:Uapi\CoreBundle\Entity\Request:private] =>
    [clientISP:Uapi\CoreBundle\Entity\Request:private] =>
    [clientOS:Uapi\CoreBundle\Entity\Request:private] =>
    [clientOSVersion:Uapi\CoreBundle\Entity\Request:private] =>
    [clientBrowser:Uapi\CoreBundle\Entity\Request:private] =>
    [clientBrowserVersion:Uapi\CoreBundle\Entity\Request:private] =>
    [clientLanguage:Uapi\CoreBundle\Entity\Request:private] =>
    [clientCountry:Uapi\CoreBundle\Entity\Request:private] =>
    [clientCity:Uapi\CoreBundle\Entity\Request:private] =>
    [possibleProxy:Uapi\CoreBundle\Entity\Request:private] =>
    [proxyIPAdress:Uapi\CoreBundle\Entity\Request:private] =>
    [torExitNode:Uapi\CoreBundle\Entity\Request:private] =>
    [maliciousInput:Uapi\CoreBundle\Entity\Request:private] =>
    [maliciousInputLog:Uapi\CoreBundle\Entity\Request:private] =>
    [serverIPAdress:Uapi\CoreBundle\Entity\Request:private] =>
    [serverPort:Uapi\CoreBundle\Entity\Request:private] =>
    [requestMethod:Uapi\CoreBundle\Entity\Request:private] =>
    [requestTimeFloat:Uapi\CoreBundle\Entity\Request:private] => P�a�;
)

Here is my Encrypted type class definition
    use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Uapi\CoreBundle\Provider\EncryptionProvider;

class EncryptedType extends Type {

    const ENCRYPTED = 'encrypted';

    public function getName()
    {
        return self::ENCRYPTED;
    }

    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) {
        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
    }

    public function convertToDatabaseValue($value, AbstractPlatform $platform) {
        return ($value === null)? null : base64_encode(EncryptionProvider::getCrypter()->encrypt($value));
    }

    public function convertToPHPValue($value, AbstractPlatform $platform) {
        return ($value === null)? null : base64_decode(EncryptionProvider::getCrypter()->decrypt($value));
    }
}

And i did register it within boot function in core bundle class
 $connection = $this->container->get('doctrine')->getConnection();
        if(!Type::hasType('encrypted'))
        {
            Type::addType('encrypted', 'Uapi\CoreBundle\System\DBALType\EncryptedType');
            $connection->getDatabasePlatform()->registerDoctrineTypeMapping('encrypted', 'encrypted');
        }

A: I did fix this on my own, its not general issue but ill explain here.I needed to firstly define a EncryptionProvider wich is my class that implements PHPSecLib\AES.So this is correct
public function boot()
{
    new EncryptionInit();
    EncryptionProvider::setCrypter(EncryptionProvider::AES, $this->container->getParameter('uapi_core.security_key'), $x = array());

    $connection = $this->container->get('doctrine')->getConnection();
    if(!Type::hasType('encrypted'))
    {
        Type::addType('encrypted', 'Uapi\CoreBundle\System\DBALType\EncryptedType');
        $connection->getDatabasePlatform()->registerDoctrineTypeMapping('encrypted', 'encrypted');
    }

 }


Q: Using Ansible to create AWS Application Load Balancer rules I'm trying to use Ansible to create rules for an unconfigured HTTP listener on my existing ALB. I kick things off by retrieving facts for the alb and then use those facts to define an Ansible ALB resource adding the rules I want, but I'm hitting an issue.
I would like Ansible to loop through my group_vars file (which it already does for other tasks successfully) to create these multiple rules. However when looping through, instead of appending rules to the listener it destroys/creates them. So when the playbook completes you are just left with a single rule referencing whichever item is defined at the end of the vars file (in my case Surrey).
My code is below (for the sake of brevity I have excluded the parts which get & set facts):
- name: Add HTTP listener rules
  elb_application_lb:
    state: present
    name: "{{ albinfo.load_balancer_name }}"
    subnets:
      - "{{ albinfo.availability_zones[0].subnet_id }}"
      - "{{ albinfo.availability_zones[1].subnet_id }}"
      - "{{ albinfo.availability_zones[2].subnet_id }}"
    security_groups:
      - "{{ albinfo.security_groups[0] }}"
    listeners:
      - Protocol: HTTP
        Port: 80
        DefaultActions:
          - Type: forward
            TargetGroupName: default
        Rules:
          - Conditions:
              - Field: host-header
                Values: "{{ item.url }}"
            Priority: "{{ item.priority }}"
            Actions:
              - TargetGroupName: "{{ item.name }}"
                Type: forward
    purge_listeners: no
  with_items: "{{ regions }}"

And my "regions" vars file looks like this:
regions:
  - name: manchester
    priority: 1
    url:
      - manchester.example.com

  - name: surrey
    priority: 2
    url:
      - surrey.example.com

A: The way you are using with_items to iterate the elb_application_lb module will not work as you have found out. Executing multiple commands will have the effect that the last one will 'win', as it will overwrite the existing elb rule set.
What you would need to do is define each rule on a single call to elb_application_lb instead, you can not layer on rules with multiple calls to this module. You might be able to create a dict that defines all your rules instead like this:
- name: Add HTTP listener rules
  elb_application_lb:
    state: present
    name: "{{ albinfo.load_balancer_name }}"
    subnets:
      - "{{ albinfo.availability_zones[0].subnet_id }}"
      - "{{ albinfo.availability_zones[1].subnet_id }}"
      - "{{ albinfo.availability_zones[2].subnet_id }}"
    security_groups:
      - "{{ albinfo.security_groups[0] }}"
    listeners:
      - Protocol: HTTP
        Port: 80
        DefaultActions:
          - Type: forward
            TargetGroupName: default
        Rules:
          - "{{ region_rules }}"
    purge_listeners: no

Where region rules var looks like this:
    region_rules:
      - Conditions:
          - Field: host-header
            Values: manchester.example.com
        Priority: 1
        Actions:
          - TargetGroupName: manchester
            Type: forward

      - Conditions:
          - Field: host-header
            Values: surrey.example.com
        Priority: 2
        Actions:
          - TargetGroupName: surrey
            Type: forward


Q: Is there any reason to make a template template parameter non variadic? If I expect a template template parameter to have one arguement then I could declare it as follows:
template<template<typename> class T>
struct S {
    T<int> t_;
    //other code here
}

however if I later want to provide a template template parameter which takes two arguements where the second has a default value (like std::vector) T<int> t_; would still work but the template would not match template<typename> class T. I could fix this by making template<typename> class T into a variadic template template template<typename...> class T. Now my code is more flexible.
Should I make all my template template parameters variadic in future? Is there any reason I should not (assuming C++11 support is already required for my code for other reasons)?

A: First, documentation. If the parameter is variadic, the user now needs to check some other source to find out that this really wants something that will takes one template parameter.
Second, early checking. If you accidentally pass two arguments to T in S, the compiler won't tell you if it's variadic until a user actually tries to use it.
Third, error messages. If the user passes a template that actually needs two parameters, in the variadic version the compiler will give him an error message on the line where S instantiates T, with all the backtrace stuff in-between. In the fixed version, he gets the error where he instantiates S.
Fourth, it's not necessary, because template aliases can work around the issue too.
S<vector> s; // doesn't work
// but this does:
template <typename T> using vector1 = vector<T>;
S<vector1> s;

So my conclusion is, don't make things variadic. You don't actually gain flexibility, you just reduce the amount of code the user has to write a bit, at the cost of poorer readability.

A: If you know already that you will need it with high probability, you should add it. Otherwise, You Ain't Gonna Need It (YAGNI) so it would add more stuff to maintain. It's similar to the decision to have a template parameter in the first place. Especially in a TDD type of environment, you would refactor only when the need arises, rather than do premature abstraction.

Nor is it a good idea to apply rampant abstraction to every part of
  the application. Rather, it requires a dedication on the part of the
  developers to apply abstraction only to those parts of the program
  that exhibit frequent change. Resisting premature abstraction is as
  important as abstraction itself
Robert C. Martin
  Page 132, Agile Principles, Patterns and Practices in C#

The benefits of variadic templates can be real, as you point out yourself. But as long as the need for them is still speculative, I wouldn't add them.


Q: How to deliver multiple application versions without confusion? We currently work on multiple branches of our web application. The VCS of choice is SVN.
We have:

*

*v1: /trunk, live application, bugfixing

*v2: /branches/1, additional features, without trunk bugfixes
There are more steps planned. The current plan is to have a stable and client accepted v1 and then merge v2 into v1. At that point it's for sure that v3 will pop up.
The problem is that the client needs more transparency, he can currently only see and test v1. If i'd make v2 available to them too, it's very likely that they can't tell the versions apart and report v1 (fixed) bugs again for v2. It would be a mess, imo.
I also don't like the idea of a daily merge because it would be even harder to tell new and old bugs apart.
I have the feeling that this is more a problem with our development process than an technical one. Any inspirations to solve the problem or to make both sides feel more convenient about future development are welcome. Thanks.
edit
One partial problem is also that my co-workers aren't too deep into version-control, using 2 branches is already inconvenient for them. However if i find a better strategy i'll probably force them to do it right.
edit2
Thanks all for the answers. After some thinking it turns out that the whole problem is even bigger, because we keep binary files within SVN. Without very strict policies merging will be impossible and probably will be crippled anyway.

A: It seems kind of unorganized.  Merging version 2 into version 1? Eh? What version are you left with? Still version 1? With the features of version 2? Wha..?
What I like for smallish projects:
Trunk: This is where things get committed when the developer is confident that it's working.  Do internal QA testing on the trunk.
Tags: Make a new tag for each release, by copying from the trunk. Name your tags "/tags/v1.0" or "/tags/v1.1" or however you want to do it.  If you need an external client to test something, name your tag something like "/tags/v1.0-beta" and give them that to test.  Don't let them test with the trunk, because while they're testing you're still going to be developing!
Branches: When you've got a feature that's going to take some time to develop, you can't commit it to the trunk before it's done.  Make a branch.  Name it after the feature you're implementing, like "/branches/user_logins".
Bugfixes get committed to the trunk and are included in the next tagged release. If there's an emergency bugfix which must be released TODAY, but there's stuff in the trunk which can not yet be released yet, make another tag but copy from the tag of the buggy release instead of from the trunk, call it something like "v1.0.1", fix the bug there, give them a new release, and then merge that bugfix into the trunk.

A: *

*"without trunk bugfixes"

*"it would be even harder to tell new and old bugs apart."

*"I have the feeling that this is more a problem with our development process than an technical one."

Damn straight. Your development process fails to acknowledge failures in V1.  How can you hope that V2 will be better than V1 if you don't carry over the corrections in V1 to V2?!
Bug fixes are always more important than new features.  If the old features are broken and not worth fixing then remove them.
Get off your lazy ass; if you, or someone, has made the effort to fix a defect in V1, then make sure it doesn't reappear in V2. FIX IT!  If your code is so rubbish that this is a daily occurrence then stop working on V2 and focus on getting the bug fixes down to less often.  If you can't get V1 features working properly then you'll never make it to V3.
I might also suggest "mercurial" or "git" or "bazaar" rather than svn. They're much better at keeping management types at bay if you find and use the "cherrypicking" and "queue" functionalities: you can add a feature and pull the-ONE-that-management-think-will-save-them into production without pulling all the other half-baked ideas they came up with then abandoned. If politics prevent a move to distributed version control just use it yourself and only push the stuff you deliver (and they want) to svn.

A: For me it seems that you switched the terms branch and trunk. Normally trunk is the active development branch, where releases live on their own bugfix branches. It looks that you use trunk as release1 bugfix branch, while /branches/1 is the real development trunk, and are stuck since you can't create a second trunk for release2.
If I'm right I would recommend to move your current trunk into a /branches/v2 branch, and your /branches/1 branch to /trunk. With this scenario you can have as many release branches as you need (but try to keep them as low as possible), while the main development line is in /trunk.
See http://nvie.com/posts/a-successful-git-branching-model/ for more details. While it is for git, there is a lot of VCS-independent information.

A: I agree to you other fellow posters. c0rnh0li0 You need to rethink your checkin & merge policies.
Look at your repository layout and try to define rules that can easily be repeated by anyone in the team and that help to populate changes consequently from stable to unstable. For me this allows merges mostly in one direction.
Example layout for a maintainance-branch scenario
branches/v1
-approved and shipped/deploy
-Only bugfixes allowed

branches/v2
-is not approved by the client but nearly ready
-Fixes and feature-commits allowed that focus on getting v2 stable & ready
-receive bugfixes commited in v1 (merge down)

branches/v3
-is not approved by the client and far from ready
-Fixes and feature-commits allowed that focus on getting v3 stable & ready
-receive bugfixes commited in v2 (merge down)

trunk
-All syntax-error free commits allowed (mainline)
-receive merges from LATEST stable branch (merge down from v3 in this case)

The top branch is the oldest with the fewest features but the highes stability (well tested, not many featurs been added in the recent past). The trunk on the other hand is pretty unstable and receives bleeding-edge features. v2 and v3 are Somewhet in between.
You could also add featrue branches "below" the trunk which would be even more unstable than the trunk. Merge directions remain the same. I'd like to quote the mantra "merge down, copy up".
The more concurrent releases you prepare/maintain the more merges you will have to do though. But thanks to mergetracking it is not so much of a task IMHO and it ensures no bugfix is left behind and has to be re-discovered and fixed again manually.
I didnt mention tags here. If you can create them and do not release from a branch directly.
Now while this should fix your change-flow management to a great deal and help isolate high-risk development from low-risk, there is the issue left of visualizing to the client what he is testing/previewing.

Visualising application VCS origin to the client
Possibilities:

*

*If it is a web-projekt host, the versions on URLs that contain the branch-name

*For any project: Just check in a logo or text property that contains something like "version 3.x" and display it in your application

*Coolest solution is to use svn keywords and parse the value of $HeadURL$ in your app to dynamically display the branch name this build originates from


Q: Cross join two dataframes by key column using condition in R I have two dataframes.
mydata1=structure(list(ID_WORKES = c(58005854L, 58005854L, 58002666L,
58002666L), ID_SP_NAR = c(463L, 1951L, 21L, 465L), KOD_DEPO = c(3786L,
3786L, 1439L, 1439L), KOD_DOR = c(58L, 58L, 92L, 92L), COLUMN_MASH = c(6L,
6L, 5L, 5L), prop_violations = structure(c(1L, 2L, 2L, 2L), .Label = c("0.2",
"1"), class = "factor"), mash_score = c(0L, 2L, 2L, 2L)), .Names = c("ID_WORKES",
"ID_SP_NAR", "KOD_DEPO", "KOD_DOR", "COLUMN_MASH", "prop_violations",
"mash_score"), class = "data.frame", row.names = c(NA, -4L))

mydata2=structure(list(ID_SP_NAR = c(463L, 1951L, 21L, 465L, 500L, 600L
)), .Names = "ID_SP_NAR", class = "data.frame", row.names = c(NA,
-6L))

i need crossjoin merge these dataframes by ID_SP_NAR. Mydata2 contatins only key variable ID_SP_NAR.
I need join this in such a way that if the id_workers does not have any codes from the ID_SP_NAR from mydata2, then these code are inserted into the dataset, but for them in variables prop_violations and mash_score must be inserted zero values.
I.E. SP_ID_NAR in mydata2 has such values
ID_SP_NAR
463
1951
21
465
500
600

ID_workes =58005854 has
463,
1951
but another not have.
and
ID_workes =58002666 has  21 and 465 and not anonter!
So desired output after cross join
   ID_WORKES ID_SP_NAR KOD_DEPO KOD_DOR COLUMN_MASH prop_violations mash_score
1   58005854       463     3786      58           6             0.2          0
2   58005854      1951     3786      58           6               1          2
3   58005854        21     3786      58           6               0          0
4   58005854       465     3786      58           6               0          0
5   58005854       500     3786      58           6               0          0
6   58005854       600     3786      58           6               0          0
7   58002666        21     1439      92           5               1          2
8   58002666       465     1439      92           5               1          2
9   58002666       500     1439      92           5               0          0
10  58002666       600     1439      92           5               0          0
11  58002666       463     1439      92           5               0          0
12  58002666      1951     1439      92           5               0          0

KOD_DEPO,KOD_DOR,COLUMN_MASH have fixed value , it must be saved too.
How to do that?
merge(mydata1,mydata2, by = ID_SP_NAR) is not working( i try use via left join doesn't work), it doesn't insert zeros as i want .

A: We could use complete from tidyr to expand the dataset based on the 'ID_WORKES' and the valuse of 'ID_SP_NAR' in the second dataset
library(tidyverse)
mydata1 %>%
   mutate_if(is.factor, as.character) %>%
   complete(ID_WORKES, ID_SP_NAR = mydata2$ID_SP_NAR,
            fill = list(prop_violations = '0', mash_score = 0)) %>%
     fill(3:5)
# A tibble: 12 x 7
#   ID_WORKES ID_SP_NAR KOD_DEPO KOD_DOR COLUMN_MASH prop_violations mash_score
#       <int>     <int>    <int>   <int>       <int> <chr>                <dbl>
# 1  58002666        21     1439      92           5 1                        2
# 2  58002666       463     1439      92           5 0                        0
# 3  58002666       465     1439      92           5 1                        2
# 4  58002666       500     1439      92           5 0                        0
# 5  58002666       600     1439      92           5 0                        0
# 6  58002666      1951     1439      92           5 0                        0
# 7  58005854        21     1439      92           5 0                        0
# 8  58005854       463     3786      58           6 0.2                      0
# 9  58005854       465     3786      58           6 0                        0
#10  58005854       500     3786      58           6 0                        0
#11  58005854       600     3786      58           6 0                        0
#12  58005854      1951     3786      58           6 1                        2


Q: MyBatis select query with IN but without forEach how can I use a select query where I have only two values for one column without using for each loop ?

A: Without using IN, you can use OR:
SELECT * FROM `table` WHERE co1 = `value1` OR col1 = `value2`


Q: Android app timeout how to apply? when it minimized I want to make a exam app I want to apply a feature in my app in this feature when student minimize app then exam will automatically cancelled. so they can't cheat so please tell me what will and how will I do this in Android app in adt.

A: In your exam activity, override onPause() and paste cancel exam method before super.onPause().
Edit: I think you need onPause() instead of onStop(). Learn more about Activity Life cycle

A: When you minimize app, onStop will called.

Called when you are no longer visible to the user

So inside onStop you can cancel the example
@Override
protected void onStop() {
    super.onStop();
    // cancel exam here
}


Q: Login error connecting to salesforce.com from Flex Has anyone suddenly encountered login errors from their users trying to connect to salesforce.com from a Flex app using as3salesforce.swc?
I get the following error... password removed to protect the innocent...
App Domain = null
Api Server name = na3.salesforce.com
_internalServerUrl = https://na3.salesforce.com/services/Soap/u/14.0
loading the policy file: https://na3.salesforce.com/services/Soap/cross-domain.xml
Your application must be running on a https server in order to use https to communicate with salesforce.com!
login with creds
loading the policy file: https://na3.salesforce.com/services/crossdomain.xml
Your application must be running on a https server in order to use https to communicate with salesforce.com!
invoke login
intServerUrl is null
intServerUrl = https://na3.salesforce.com/services/Soap/u/14.0
_invoke login
'5A5D3012-7717-E3C2-9B39-FFBBFF1F1B47' producer set destination to 'DefaultHTTPS'.
Method name is: login
'direct_http_channel' channel endpoint set to http://localhost/pm_server/pm/
'5A5D3012-7717-E3C2-9B39-FFBBFF1F1B47' producer sending message 'E32C7199-72C1-B258-B483-FFBC1641173D'
'direct_http_channel' channel sending message:
(mx.messaging.messages::HTTPRequestMessage)#0
  body = "<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/"><se:Header xmlns:sfns="urn:partner.soap.sforce.com"/><se:Body><login xmlns="urn:partner.soap.sforce.com" xmlns:ns1="sobject.partner.soap.sforce.com"><username>simon.palmer@dialectyx.com</username><password>******</password></login></se:Body></se:Envelope>"
  clientId = (null)
  contentType = "text/xml; charset=UTF-8"
  destination = "DefaultHTTPS"
  headers = (Object)#1
  httpHeaders = (Object)#2
    Accept = "text/xml"
    SOAPAction = """"
    X-Salesforce-No-500-SC = "true"
  messageId = "E32C7199-72C1-B258-B483-FFBC1641173D"
  method = "POST"
  recordHeaders = false
  timestamp = 0
  timeToLive = 0
  url = "https://na3.salesforce.com/services/Soap/u/14.0"
'5A5D3012-7717-E3C2-9B39-FFBBFF1F1B47' producer connected.
Method name is: login
Error: Ignoring policy file at https://na3.salesforce.com/crossdomain.xml due to meta-policy 'by-content-type'.

'5A5D3012-7717-E3C2-9B39-FFBBFF1F1B47' producer acknowledge of 'E32C7199-72C1-B258-B483-FFBC1641173D'.
responseType: Fault
Saleforce Soap Fault: sf:INVALID_LOGIN
INVALID_LOGIN: Invalid username, password, security token; or user locked out.
Comunication Error : sf:INVALID_LOGIN : INVALID_LOGIN: Invalid username, password, security token; or user locked out. : [object Object]

A: Obviously nobody else out there is building Flex apps on top of salesforce.com..
yippee, I'm first.
Anyhow, I just found out that this is a bug at salesforce.com as at 6th December 2008.  The issue is that the scripts which handle login do not cope adequately with the redirect necessary because of load balancing on the salesforce.com servers.
It should be possible to go through the www front door of salesforce.com's api with a URL such as...
"https://www.salesforce.com/services/Soap/u/13.0";

where the 13 represents the version of their API you are targetting.  However, all users are actually assigned to a specific server, so the front door should redirect the login request to the approriate place, and it doesn't if you are coming from Flex.
A workround is to specify your server in the URL, such as...
"https://na5.salesforce.com/services/Soap/u/13.0";

...which is what I was doing.  That's fine if you are a single user accessing the same resources continually and your account remains attached to that server.  However if...

*

*You are distributing your app so anyone who has a salesforce.com enterprise account can log in OR

*Your account gets moved because of some internal load balancing (which is what happened to me)

then the approach of providing a fixed server won't work.
The bug (as far as I understand it) is that the www route doesn't adequately redirect to your host server.  Last intelligence was that it will be fixed "soon".
I wish I could mark this as the answer...


Q: Call Python from Julia I am new to Julia and I have a Python function that I want to use in Julia. Basically what the function does is to accept a dataframe (passed as a numpy ndarray), a filter value and a list of column indices (from the array) and run a logistic regression using the statsmodels package in Python. So far I have tried this:
using PyCall

py"""
import pandas as pd
import numpy as np
import random
import statsmodels.api as sm
import itertools
def reg_frac(state, ind_vars):
    rows = 2000
    total_rows = rows*13
    data = pd.DataFrame({
    'state': ['a', 'b', 'c','d','e','f','g','h','i','j','k','l','m']*rows, \
    'y_var': [random.uniform(0,1) for i in range(total_rows)], \
    'school': [random.uniform(0,10) for i in range(total_rows)], \
    'church': [random.uniform(11,20) for i in range(total_rows)]}).to_numpy()
    try:
        X, y = sm.add_constant(np.array(data[(data[:,0] == state)][:,ind_vars], dtype=float)), np.array(data[(data[:,0] == state), 1], dtype=float)
        model = sm.Logit(y, X).fit(cov_type='HC0', disp=False)
        rmse = np.sqrt(np.square(np.subtract(y, model.predict(X))).mean())
    except:
        rmse = np.nan
    return [state, ind_vars, rmse]
"""

reg_frac(state, ind_vars) = (py"reg_frac"(state::Char, ind_vars::Array{Any}))

However, when I run this, I don't expect the results to be NaN. I think it is working but I am missing something.
reg_frac('b', Any[i for i in 2:3])

  0.000244 seconds (249 allocations: 7.953 KiB)
3-element Array{Any,1}:
    'b'
    [2, 3]
 NaN

Any help is appreciated.

A: In Python code you have strs while in Julia code you have Chars - it is not the same.
Python:
>>> type('a')
<class 'str'>

Julia:
julia> typeof('a')
Char

Hence your comparisons do not work.
Your function could look like this:
reg_frac(state, ind_vars) = (py"reg_frac"(state::String, ind_vars::Array{Any}))

And now:
julia> reg_frac("b", Any[i for i in 2:3])
3-element Array{Any,1}:
  "b"
  [2, 3]
 0.2853707270515166

However, I recommed using Vector{Float64} that in PyCall gets converted in-flight into a numpy vector rather than using Vector{Any} so looks like your code still could be improved (depending on what you are actually planning to do).


Q: Loading Large Datasets in Parallel With Python Multiprocessing TLDR;

*

*I want to read many files from disk in parallel

*My code loads these files very quickly, but merging them into the main process' memory is slow

*Am I doing this correctly? Is there a better way to share memory across processes?

Background:
I'm currently working on a project with a private hospital dataset (only 3 GB!) and would like to be able to load it faster (their disks are slow). I work on a 36 CPU server, so I should be able to speed it up using multiple processes. However, I am having trouble seeing an improvement.
The setup:
I have split my dataset over 12 binary PyTorch files ('.pt') which I load with torch.load(filename). These files each contain a list of images inside a dict E.G. the 0th list: {0:ListOfImages}. I would like to load these files simultaneously with different processes, then merge them into a list in their original order. I am currently able to do that, but cannot seem to merge the data into the main process faster than it would take to load sequentially.
Sequential baseline load: 74 seconds
What I tried:

*

*multiprocessing.Pool().map() (150 Seconds)

*multiple iterations of process.start() + process.join() (300 Seconds +)

*multithreading: I load the dataset in exactly the same amount of time as sequentially (74 Seconds)

Multiprocessing code thus far:
import multiprocessing as mp
import time
CORES = 12

def loadWorker(sharedDict,filename):
  t1 = time.time()
  temp = torch.load(filename)
  print("Dict Loaded in :{} seconds".format(time.time()-t1))
  t1=time.time()
  sharedDict.update(temp)
  print("Dict updated in :{} seconds".format(time.time()-t1))

filenames = ["namingconvention{}.pt".format(i) for i in range(CORES)]

jobs=[]
manager = mp.Manager()
sharedDict = manager.dict()
t1 = time.time()
for i,filename in enumerate(filenames):
  print("starting Process: {}".format(i))
  p = mp.Process(target=loadWorker, args=(sharedDict,filename))
  jobs.append(p)
  p.start()

for i,proc in enumerate(jobs):
  print("join Process {}".format(i))
  process.join()

print("dict created of length: {} in {} seconds".format(
  len(sharedDict),time.time()-t1)
)

images = []
for i in range(CORES):
  print("Appending Images: {}".format(i))
  images = images + list(images)

print("Images appended in {} seconds".format(time.time()-t1))

Am I doing something wrong? Is there a better way to share memory between these processes?
OUTPUT:
The output of the above:
Image of the stdout
The output of the above code with CORES=1 and logger.setLevel(mp.SUBDEBUG)
Image of debug stdout


Q: Why delegate protocol method is not recognized in UINavigationController I looked at lots of threads about delegation but couldn't find why this isn't working
I have UINavigationController in storyboard in Xcode  5 and here is how the delegate is assigned:
in MasterViewController I have:
//
// MasterViewController.h
//
@protocol MyViewDelegate
@required
- (void) getBackContacts:(NSArray *)c andEmails:(NSArray *)e;
@end

@interface ListContactsViewController : UITableViewController <MyViewDelegate> {

}
@property (strong, nonatomic) NSString* myString;
@property (strong, nonatomic) ABContact* currentML;

@end

//
// MasterViewController.m
//

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    DetailtViewController *vc = [segue destinationViewController];
    vc.delegate = self;
    vc.currentML = _currentML;
    vc.contacts = _contacts;
    vc.emails = _emails;
}

- (void) getBackContacts:(NSArray *)c andEmails:(NSArray *)e
{
    _contacts = [NSMutableArray arrayWithArray:c];
    _emails   = [NSMutableArray arrayWithArray:e];
}

for DetailViewController I have:
//
// DetailViewController.h
//
@protocol MyViewDelegate;

@interface SelectContactViewController : UITableViewController {
    id< MyViewDelegate > delegate;

}
-(IBAction) save;

@property (nonatomic, strong) id< MyViewDelegate > delegate;
@property (strong, nonatomic) ABContact* currentML;
@property (strong, nonatomic) NSMutableArray* contacts;
@property (strong, nonatomic) NSMutableArray* emails;

//
// DetailViewController.m
//

- (IBAction) save
{
    // *** this line compiles with error
    [delegate getBackContacts:_contacts andEmails:_emails];
}

When I compile compiler says:
No known instance method for selector 'getBackContacts:andEmails:'


Q: Setting  size to be the same as window? I'm trying to use jQuery to set the height of a div so that it takes up the entire window + the height of a header (so that you can scroll the header off the page) but no more than that. I would think the height of the div would be the height of the window + the height of the header I'm trying to hide.
When I set the div to window height, however, it creates overflow. Here's the rough code:

var $body = $("#body"),
  $container = $("#container"),
  $window = $(window),
  $content = $("#mainContent"),
  $header = $("#header"),
  bodyHeight = window.innerHeight + $header.height();

$body.css("height", window.innerHeight);
$container.css("height", bodyHeight);
div {
  display: block;
  width: 100%;
  margin: 0;
}
#body {
  overflow-y: scroll;
}
#container {
  overflow-y: hidden;
}
#header {
  overflow: hidden;
}
#navbar {
  height: 10px;
  background-color: brown;
}
#mainContent {
  height: 200px;
  overflow-y: scroll;
}
#contentP {
  height: 400px
}

Header

This is content

Why is there overflow if the div is sized to fit in the window?
EDIT: So far, answers haven't helped. This is the site I'm working on. It's joomla. I want the nav bar to lock at the top of the screen.
$(document).ready(function() {

//Declare some variables
var $window = $(window),
    $body = $(".body"),
    $mainContent = $("#maincontent"),
    headerGap = parseFloat($("#headerimg").css("margin-top")),
    headerHeight = headerGap + $("#header").height() + parseFloat($("#navbar").css("margin-top")),
    navbarHeight = $("#navbar").height(),
    footerHeight = $("#footer").height();

//set the height of the body and the maincontent
resizePage();

//Set the listeners for resizing and scrolling
$window.resize(resizePage);
$window.scroll(scrollHandler);

//When you scroll, see if the navbar is at the top. Set maincontent overflow
//to scroll when the navbar is at the top of the window. Set it to hidden otherwise
function scrollHandler() {
    if ($window.scrollTop() < headerHeight - 1) {
        $mainContent.css("overflow", "hidden");
    } else {
        $mainContent.css("overflow", "auto");
    }
}

//Set the body and the mainContent to be the correct sizes when the window size is changed. In theory, the body should be:
// windowHeight + headerHeight
// maincontent should be:
// windowHeight - (headerHeight + navbarHeight + footerHeight)
// But that doesn't quite work out.
function resizePage() {
    //Deal with the changing CSS due to media queries
    if ($(window).width() > 768) {
        headerGap = parseFloat($("#headerimg").css("margin-top"));
        headerHeight = headerGap + $("#header").height() + parseFloat($("#navbar").css("margin-top")) - 1;
        $(".nav.menu.nav-pills").css("width", "92.5%");
    }
    else {
        headerHeight = $("#header").height();
    $(".nav.menu.nav-pills").css("width", $window.width());
    }
    //The header and navbar height change at certain sizes, so grab them again to be safe.
    navbarHeight = $("#navbar").height();
    footerHeight = $("#footer").height();
    var windowHeight = $window.height(),
        contentHeight = windowHeight - (footerHeight + navbarHeight);
            //if we account for headerHeight too, maincontent is too big
    resizeContent(contentHeight);
    resizeBody(windowHeight);
}

//The body should take up the whole height of the window, plus the header
//and margin heights at the top. This way, you scroll to the navbar.
// But it doesn't work this way.
// -7 and -27 are from eyeballing it.
function resizeBody(windowHeight) {
    if($window.width() > 728) {
        $body.css("height", windowHeight - 7);
        }
    else {
        $body.css("height", windowHeight - 27);
    }
}

// The content should go from the bottom of the navbar to the bottom of the footer.
//
function resizeContent(contentHeight) {
    $mainContent.css("top", (headerHeight + navbarHeight));
    $mainContent.css("bottom", (0 - headerHeight));
//For the background slideshow on the Furniture page
// Again, + 5 was eyeballed
    $("div.moduletable").css("height", contentHeight + 5);
    if ( (contentHeight + 5) < ($(window).width()) /2 ) {
        $(".wk-slideshow img").css("width", "100%");
        $(".wk-slideshow img").css("height", "auto");
        }
    else {
        $(".wk-slideshow img").css("height", contentHeight + 5);
        $(".wk-slideshow img").css("width", "auto");
    }
}
});

It works for a lot of sizes, but one you get to small resolutions it falls apart.
EDIT 2: I was able to get the effect I was going for by adding another div. I set the body to be the height of the window and the new div to be the size of the body + the height of the header. The body has "overflow-y: scroll". The container would have "overflow-y: hidden" (See updated snippet). This doesn't totally answer my question, but at least it helps?

A: I've taken a look at your code and altered it. Try this and see if this is what you're looking for.
In my example i'm looking for the element by getElementById and then I set it's style.height to window.innerHeight - 10px without taking the 10px it wouldn't show the border fully on the page. So you just remove 10px's. The example has been tested on different screen sizes.
Javascript example:

function autoResizeDiv() {
  document.getElementById('body').style.height = window.innerHeight - 10 + 'px';
  console.log(window.innerHeight - 10 + 'px');
}
window.onresize = autoResizeDiv;
autoResizeDiv();
#body {
  display: block;
  border: 5px solid black;
}
body {
  overflow: hidden;
  margin: 0;
}

A: The following worked for me:
$(".body").height($(window).height());

A: I figured out the biggest problem. I was using some absolutely positioned elements without giving a parent any other position. This made things show up wonky when I was trying to size other things. I also needed to have an extra div as a container for all the content on the page that would be the height of the window + the height of the header.
Thanks to everyone who answered, it helped!


Q: Redirection to base url with GET array in codeigniter I'm trying to make the pagination work with the get parameter. Only that, the rest of the site will use uri.
The problem is this, as soon as I append ?something=zyx it redirects to the base url.
Config:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-&=';
$config['allow_get_array']      = TRUE;

htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|lib|robots\.txt|upload)
RewriteRule ^(.*)$ /mysite/index.php/$1 [L]

Why does this happen?
Thanks
EDIT: AFTER A LONG RESEARCH I FOUND THE PROBLEM.
I post it here in case somebody else has the same problem.
If you are planning to use GET vars in whatever form, even a hybrid solution like mine you must set:
$config['uri_protocol'] = "PATH_INFO";
in the config file.

A: Since you only want to use query strings while using pagination, the following code should be enough:
$this->load->library('pagination');

...
$config['page_query_string'] = TRUE;
...

$this->pagination->initialize($config);

echo $this->pagination->create_links();

You should check the rest of the Pagination Class documentation.


Q: How to add an Internet Gateway to a VPC using AWS CDK? I am trying to produce the correct CDK scripts (TypeScript) to create an environment with a Lambda (accessed via API Gateway) that can call an RDS (Sql Server instance).
I believe I have it mostly working, but I wanted to connect to the RDS instance from my development machine to run some queries and check on a few things.
My RDS instance is in a private subnet, and so I believe in order to connect to it I need to add an Internet Gateway and security group to allow access on the appropriate ports.
For the life of me I can figure out the last piece, how to add the internet gateway using CDK.
The latest script I have tried is as follows:
const privateSubnectConfiguration = {
  cidrMask: 26,
  name: 'private-subnet',
  subnetType: SubnetType.PRIVATE,
};

const publicSubnectConfiguration = {
  cidrMask: 26,
  name: 'public-subnet',
  subnetType: SubnetType.PUBLIC,
};

const vpc = new Vpc(this, props.generateId('vpc'), {
  maxAzs: 2,
  subnetConfiguration: [privateSubnectConfiguration, publicSubnectConfiguration],
  natGateways: 1,
});

vpc.addGatewayEndpoint(props.generateId('internet-gateway'), {
  service: { name: "ig-service" }
})

Which then errors with The Vpc Endpoint Service 'ig-service' does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidServiceName;
I see references to the CfnInternetGateway in the docs, but just can't figure out how to attach a new one to my VPC?
Can you please help with the syntax?

A: First of all, you cannot directly access a database in a private subnet. You have to deploy a proxy instance in your public subnet and forward the required ports to access your database.
When using CDK VPC construct, an Internet Gateway is created by default whenever you create a public subnet. The default route is also setup for the public subnet.
So you should remove addGatewayEndpoint() from your code, which adds a Gateway VPC Endpoint that you don't need.
You may also consider using SubnetType.ISOLATED to create a private subnet without a NAT GW, which may be redundant in your case. SubnetType.PRIVATE creates a NAT Gateway by default.


Q: how do i select value from dropdownlist to mode or to controller mvc Model
public class Company
{
    public int ID { get; set; }
    ....
    public int WorkZoneID { get; set;  }
    public IEnumerable<SelectListItem> WorkZones { get; set; }

Controller:
ViewBag.Workzones = cmpRep.GetWorkzoneDrop();

Repository:
public List<SelectListItem> GetWorkzoneDrop()
{
    SqlDataReader DR;
    DR = Ado.ExecDataReaderProc("WorkZoneSelectActive");
    List<SelectListItem> selectWorkZoneListItems = new     List<SelectListItem>();
    CompanyVMList C = new CompanyVMList();
    C.Companies = new List<Company>();
    while (DR.Read())
    {
        SelectListItem selectListItem = new SelectListItem
        {
            Text = Convert.ToString(DR["Name"]),
            Value = Convert.ToString(DR["ID"]),
        };
        selectWorkZoneListItems.Add(selectListItem);
    }
    return selectWorkZoneListItems;
}

View
@Html.DropDownList("Workzones")

I want to assign selected dropdownlist value to int work zone int the mode how do i select value from dropdownlist to model or to controller

A: You need to bind your dropdownlist to property WorkZoneID
@Html.DropDownListFor(m => m.WorkZoneID, Model.Workzones)

and if your wanting to preselect an option, you need to set the value in the controller before you pass the model to the view. And since your model contains a property for the SelectList, then use it (don't use ViewBag)
Company model = new Company
{
    WorkZoneID = 1 // set to a value that matches one of your options
    Workzones = cmpRep.GetWorkzoneDrop();
};
return View(model);

and when you submit to
[HttpPost]
public ActionResult Edit(Company model)

the value of model.WorkZoneID will contain the value of the selected option.


Q: How to decouple user Identity from the application data I am part of a new startup with some friends from school, and I am developing a REST API as back-end for a web application/website. I have recently gratuated and does not have much experience with large projects.
Without going in detail about the specific business idea, it will be sort of a "share economy" service, like for example uber or airbnb, where users register as either a customer or provider of a specific service. So users need to register an account and have data related to that account.
The API is developed with ASP.NET Web API. For authentication/authorization I am using ASP.NET Identity and JWT as Oauth bearer tokens with OWIN OAuth middleware.
I have used a guide for part of the setup, with some changes to fit our
project. (Just search "bitoftech Implement OAuth JSON Web Tokens Authentication in ASP.NET Web API and Identity 2.1" to find it if you are interested).
For those that don't know, the ASP.NET Identity database looks like this:
ASP.NET Identity database diagram.
So we have an AppUser table that represents the user, with roles, claims and logins attached in different tables in the Identity database.
Now, the user has much other data related to his account in our application, like messages (users can message each other), events (like a ride if this was uber), categories, reviews, files, and other data. All in separate tables.
So, since all these other tables are related to the user identity, what I did was put all these other tables in the same database with a Foreign Key to the Id in the AppUser table.
Each user has a role of either Customer or Provider (as in customer or driver in the Uber example) in the IdentityRole table.
This way I can authorize users based on role, and also query data based on role.
Now for the catch: Unexpected requirement changes. The company has decided that they (we) want to create a similar service (with customers and providers), but in a different business domain, and with the same user identity. So users that have already registered with one site should not be required to register again with a new account for the other site, but just use their existing account (and maybe sign up for the new site by clicking a button in their profile or something).
So if the first site was uber, now we want to create airbnb (not really, but as an example).
The data in the new site will be very similar to the first site. Users will have messages, events, categories, files, etc. But the events table will maybe be a little different, and maybe some new or different tables for the new site. We will try to keep the data very similar at first, so we can use much of the existing code, but we expect – if the the site(s) become popular – that they will drift apart (in terms of code and data) in time.
So first I thought: "how can I change the existing database schema so that it will fit both services?". But as I thought more about it, I think this will maybe only create problems in the future.
In the Oauth flow diagram, you have a separate resource server and authorization server. Even though I use Oauth now, my API is both a Resource Server and Authorization Server I guess, and that would probably be ok if they had not had been coupled in the way I have described?
So my question after all this is this is:
1: Should I use one (separate) database for the User Identity (IdentityDbContext),
and another database for all the other data (events, messsages etc..)?
That way Identity can run on a totally different server if need be, and not be coupled to any specific domain/site/service. Is that a good idea?
2: If so, how would I create a relationship between databases?
The only thing I can think of is to create a separate user table with only the UserId (from the Identity database) in the "Uber" database, and this will be created the first time a user registers for a site, and all the other data is related to this key. Then I would need to query data from two databases and put them together for some operations, for example, when a user queries his incoming messages, the message itself would be in one database and the name of the sender in another. Is there a better way?
3: Should I use separate databases for the first and second website/service (One for Uber and one for Airbnb, as in the example)? Or is there a better way?
4: Is there a different solution that I have not thought about that would be better?
Many people have probably faced these problems before, so I would appreciate if any experienced developers could tell me what is the best practice.
Last, it is not unprobable that even more services will be "attached" to the user Identity in the future if our current endevours are successful, so I really need a future-proof solution to this problem.
Thank you for any responses.

A: This approach seems somewhat common:

*

*Maintain a completely separate identity database.  There should be no connection at all with any of the Line-Of-Business (LOB) databases.

*Each LOB database should have its own user table, with appropriate referential integrity constraints with other LOB tables, e.g. events or messages in your case.

*When a user hits one of your LOB web sites for the first time, he should be "enrolled" in the LOB database.  A LOB user record is inserted.  Use the access token to call the identity server to get any demographic information your LOB site will need.

*When a user hits one of your LOB web sites for the Nth time, you can use the access token to call the identity server and get the most recent, up-to-date demographic information, just in case any of it has changed since his last visit. You can then store this information in the LOB user table so that it is available to you offline, e.g. if you need to push marketing emails you'll have a copy of the email address.
The advantage of this approach is separation of concerns and the ability to support more than one authentication provider (e.g. in the future you could support Facebook or Google+ logins as well).
Also you avoid any dependencies between the identity server and the LOB servers, so you can add or remove lines of business as needed, and you keep the identity server nice and lightweight.


Q: Checking if a directory exists in Linux using perl
I am programming in linux using perl. I am creating a program where a user can input a directory and a filename. The program will then check if the given directory exists or not and also searches the given filename in that directory. But my problem is verifying if the inputted directory is valid.

A: You must have specified if the path to the directory is absolute or relative. If it is absolute, you can check with -e to see if it exists and with -d if the input given it is a directory or not.
if ( -e $dir and -d $dir) {
    print "\nyour folder exists";
}

If the path is relative, then you must create the absolute path. For that you will have to use as $base your drvives (you need to do that for each drive) and after, use rel2abs to find an absolute path for the given relative path. If the folder exists, $abs_path will contain the absolute path, else it's value will be undef. Bellow as an example for searching your folder with a relative path on drive c:\:
$base = 'c:\';
$abs_path = File::Spec->rel2abs( $relative_path ) ;
$abs_path = File::Spec->rel2abs( $relative_path, $base ) ;
if ( defined $abs_path ) {
    print "\n folder exists ";
}

For more options, see perldoc -f -X


Q: Python - filtering in Django I'm new in python/django and i have a problem, i'm trying to use checkbox filtering in my html table and i don't really know how to do it.
This is what i have now
I want to add these
models.py
class Tags(models.Model):
    tag_frequency = models.CharField(max_length=250)

views.py
@login_required(login_url='/login/')
def index(request):
    title = 'Tags'
    all_tags = Tags.objects.all()
    return render(request, 'tag/index.html' ,{'all_tags':all_tags, 'title':title})

How do i use filter with these, i tried something like this but doesn't work:
LF = 125 - 134.2 KHz
HF = 13.56 MHz
UHF = 860 - 960 MHz

LF = Tags.objects.filter(tag_frequency__gt=125, tag_frequency__lt=134.2)

A: In order to make your query works, you have to change your field to FloatField:
class Tags(models.Model):
    tag_frequency = models.FloatField(default=0.00, null=True, blank=True)

Set null, blank and default values based on your needs.
Then, put your checkboxes (or radio inputs) in your html form like this:
<form action="" method="post">

<input type="checkbox" name="is_lf" id="input_lf"> LF

<input type="checkbox" name="is_hf" id="input_hf"> HF

<input type="checkbox" name="is_uhf" id="input_uhf"> UHF

  <input type="submit" value="Submit"/>
</form>

Then in your view, you can try something like this:
def form_view(request):
    if request.method == 'POST':
        # these strings come from HTML Elements' name attributes
        is_lf = request.POST.get('is_lf', None)
        is_hf = request.POST.get('is_hf', None)
        is_uhf = request.POST.get('is_uhf', None)

        # Now make your queries according to the request data
        if is_lf:
            LF = Tags.objects.filter(tag_frequency__gt=125, tag_frequency__lt=134.2)

        if is_hf:
            # another query here

        # and rest of your view


Q: How to have MySQL return multiple column of values based on a different benchmark? I have a MySQL database table (sales) consisting of sales data with their dates.
| Sales ID |    Date     | Values |
|---------------------------------|
| 1        | 01/01/2020  |  1,500 |
| 2        | 02/01/2020  |  2,000 |
| 3        | 07/02/2020  |  1,000 |
| 4        | 12/03/2020  |  2,000 |
| 5        | 21/06/2020  |  1,000 |
| 6        | 11/08/2020  |  4,200 |

I have a SQL query that relies on a specific date benchmark.
```
SET @benchmark = "31/01/2020";

SELECT SUM(Values) FROM sales
WHERE (date < @benchmark);
```

This query supposedly returns only one numeric value. Now I set the condition to be dependant on the benchmark. The problem is, I don't want this benchmark to stay constant. I need the query to return 14 values for each end of month benchmark from January 2020 to February 2021.
So the result would probably be something like this,
|              SUM(Values)            |
|-------------------------------------|
|(result for benchmark = "31/01/2020")|
|(result for benchmark = "29/02/2020")|
|(result for benchmark = "31/03/2020")|
                   ⋮
|(result for benchmark = "31/01/2021")|
|(result for benchmark = "28/02/2021")|

Which sets the benchmark for every end of the month. Note that I do not have access to CREATE anything.
I was thinking of a while loop or a temporary table, but those require me to CREATE something which always returns "Error Code: 1142. CREATE command denied to the user ...." or "Error Code: 1044. Access denied for the user ....".
Thanks for any help or feedback.

A: You can list the dates you want and aggregate:
select m.eom, sum(s.sales)
from (select '2020-01-31' as eom union all
      select '2020-02-29' union all
      . . .
     ) m left join
     sales s
     on s.date < m.eom
group by m.eom;

Note that you can also generate the dates using a recursive CTE or calendar table.
For this particular query, you could also use a cumulative sum:
select last_day(date) as eom, sum(sales),
       sum(sum(sales)) over (order by last_day(date))
from sales
group by eom;

That works for your particular example, but might not work for other logic.


Q: do a task for each server from a specific group I have a host file with:
[synology]
192.168.1.111 ansible_sudo_pass='dfg78G67'

[web]
139.59.xx:8682 server_name=do1 sql_server_id=1 sql_auto_increment_increment=1
139.59.xx:8682 server_name=do2 sql_server_id=2 sql_auto_increment_increment=2

For each server I have his ssh public key
I would like to add it to my synology
- name: "Add ssh key"
   authorized_key: user=admin key="{{ lookup('file', 'ssh_keys/id_rsa_{{ item.server_name }}.pub') }}"
   with_items: "{{ groups['web'] }}"

but Ansible responds
TASK [synology_init : Add ssh key] **********************
fatal: [192.168.1.111]: FAILED! => {"failed": true, "msg": "'unicode object' has no attribute 'server_name'"}

Thx

A: - name: "Add ssh keys"
  authorized_key: user=admin key="{{ lookup('file', 'ssh_keys/id_rsa_{{ hostvars[item].server_name }}.pub') }}"
  with_items: "{{ groups['web'] }}"


Q: Best way to support large dropdowns Say I have a report that can be restricted by specifying some value in a dropdown. This dropdown list references a table with > 30,000 records. I don't think this would be feasible to populate a dropdown with! So, what is the best way to provide the user the ability to select a value given this situation? These values do not really have categories and even if I subdivided (by having some nesting dropdown situation) by the first letter of the value, that may still leave a few thousand entries.
What's the best way to deal with this?

A: Search, don't categorise.
You can display the control as a simple text box, and when the user types in a few characters, you could pop up an autocomplete-like dropdown to select the final value. Here's a link to the jQuery plugin for autocomplete.

A: I really wouldn't have a 30,000 element drop-down. The GUI is supposed to make it easier on the user rather than harder.
If you have no other way to categorise the data other than alphabetically, you're not restricted to using a two-stage approach with just the first character. Make it reliant on the first two characters.
This would give you at most 676 (assuming alphas only) in the first drop-down and (on average) 44 in the second.
We've actually taken two approaches to this problem. BIRT (which we use) allows for cascading parameters which can easily run that second-level query whenever you change the first drop-down box.
However, some of our customers care absolutely zero for nice GUI stuff (other than the output of nice 9-point Verdana and beautiful charts to placate management, of course). They prefer a free-form text entry field where they can just type in "SYS_PAX_%" to change their queries.
Of course, these are the customers that know exactly what data is in their database and use values which lend themselves to categorisation with SQL LIKE clauses. Others prefer the ability to search.

A: I had this same question about 2 years ago concerning a asp.net dropdown box.
Trust me, don't even try it. Use the auto complete suggestions above. I've found that displaying anything above 5000 records tends to crash the browser.
Just my 2 cents.

A: +1 @pax.  Still i'd like to see a 30K dropdown!  :)
@JustAProgrammer, perhaps you could do a text box where people can type in the beginning of what they are looking for and you can filter as they type in.

A: If you're asking from a performance perspective rather than a usability perspective I would consider using a live-list approach that loads only a subset of the list items on demand as you scroll up or down.  If the user clicks down the list quickly, to say the middle, it will load another 10 elements corresponding to that position.  Both render time and load time will be much faster.
Like paging, but 'fluid'.

A: Auto complete drop down as suggested above is best to have. But it will require the users to have some idea about the type of entries to start with. If the users are familiar with data, go for it.
Alternatively, if you can categorize your data, then you can start with the categories first and then based on the selection you can populate the dependent drop down with actual values which will be a subset of original values.


Q: adding/embedding youtube videos in asp.net page I want to add youtube videos thumbnails to my asp.net website like the videos section in http://jtsplatmaster.com/. On this website, If you click the right thumbnails, video will start playing in the main section without page refresh. Which control so I need to use. I know that object tag can be used to embed youtube videos in asp.net page.
Please suggest.

A: I found this API http://youtube.codeplex.com/. May be helpful for someone in future.
Regards,
Asif Hameed