text:
Q: Haciendo un Módulo Nativo de React Native para usar el Garmin SDK para iOS Estoy intentando implementar el SDK de Garmin para iOS en un módulo nativo para conectar un reloj Garmin a mi aplicación de react-native. He hecho todo lo que dicen los documentos para crear un módulo nativo y puedo inicializar y comenzar a escanear (esto no arroja ningún error y le pide al usuario que habilite el bluetooth, por lo que definitivamente está haciendo algo). Pero el método de la clase que tengo que implementar (didScanDevice) el cuál debería ser llamado cuando encuentra un dispositivo no recibe la llamada. De nuevo, sin arrojar ningún error. Este método si funciona cuando lo levanto en un proyecto native en swift (sin react-native).
Mi pregunta es, ¿podría haber algún problema con los módulos nativos que no permitan que mi clase que implementa el SDK de Garmin se ejecute correctamente?
El módulo nativo se implementa de la siguiente manera:
//AppDelegate.m
#import "AppDelegate.h"
#import <companion/companion.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"swc"
                                            initialProperties:nil];

  if (@available(iOS 13.0, *)) {
      rootView.backgroundColor = [UIColor systemBackgroundColor];
  } else {
      rootView.backgroundColor = [UIColor whiteColor];
  }

  GHInitializer *initializer = [GHInitializer sharedManager];
  [initializer initializeLicense:@"SDK_KEY"];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

//RNGarmin.swift
import Foundation
import companion

@objc(RNGarmin)
class RNGarmin: NSObject, GHDeviceConnectionDelegate, GHScanDelegate, GHPairingDelegate {

  public var supportedDevices: [NSNumber] = [NSNumber(value: GHDeviceTypes.venu.rawValue), NSNumber(value: GHDeviceTypes.venu2.rawValue), NSNumber(value: GHDeviceTypes.venu2s.rawValue), NSNumber(value: GHDeviceTypes.venuSq.rawValue), NSNumber(value: GHDeviceTypes.vivoactive3.rawValue), NSNumber(value: GHDeviceTypes.vivoactive3m.rawValue), NSNumber(value: GHDeviceTypes.vivoactive4.rawValue), NSNumber(value: GHDeviceTypes.vivoactive4Legacy.rawValue), NSNumber(value: GHDeviceTypes.vivoactive4s.rawValue), NSNumber(value: GHDeviceTypes.vivoactiveHr.rawValue), NSNumber(value: GHDeviceTypes.vivosmart3.rawValue), NSNumber(value: GHDeviceTypes.vivosmart4.rawValue), NSNumber(value: GHDeviceTypes.vivosmartHr.rawValue), NSNumber(value: GHDeviceTypes.vivomove3.rawValue), NSNumber(value: GHDeviceTypes.vivomove3s.rawValue), NSNumber(value: GHDeviceTypes.vivomoveHr.rawValue), NSNumber(value: GHDeviceTypes.vivomoveLuxe.rawValue), NSNumber(value: GHDeviceTypes.vivomoveStyle.rawValue), NSNumber(value: GHDeviceTypes.vivosport.rawValue), NSNumber(value: GHDeviceTypes.fenix5.rawValue), NSNumber(value: GHDeviceTypes.fenix5s.rawValue), NSNumber(value: GHDeviceTypes.fenix5x.rawValue), NSNumber(value: GHDeviceTypes.fenix5Plus.rawValue), NSNumber(value: GHDeviceTypes.fenix5sPlus.rawValue), NSNumber(value: GHDeviceTypes.fenix5xPlus.rawValue), NSNumber(value: GHDeviceTypes.fenix6.rawValue), NSNumber(value: GHDeviceTypes.fenix6Pro.rawValue), NSNumber(value: GHDeviceTypes.fenix6ProSolar.rawValue), NSNumber(value: GHDeviceTypes.fenix6s.rawValue), NSNumber(value: GHDeviceTypes.fenix6sPro.rawValue), NSNumber(value: GHDeviceTypes.fenix6xPro.rawValue), NSNumber(value: GHDeviceTypes.forerunner245.rawValue), NSNumber(value: GHDeviceTypes.forerunner245m.rawValue), NSNumber(value: GHDeviceTypes.forerunner645.rawValue), NSNumber(value: GHDeviceTypes.forerunner645m.rawValue), NSNumber(value: GHDeviceTypes.forerunner945.rawValue), NSNumber(value: GHDeviceTypes.forerunner945lte.rawValue), NSNumber(value: GHDeviceTypes.instinct.rawValue), NSNumber(value: GHDeviceTypes.lily.rawValue), NSNumber(value: GHDeviceTypes.tactixCharlie.rawValue), NSNumber(value: GHDeviceTypes.tactixDelta.rawValue), NSNumber(value: GHDeviceTypes.marqDriver.rawValue), NSNumber(value: GHDeviceTypes.marqAviator.rawValue), NSNumber(value: GHDeviceTypes.marqCaptain.rawValue), NSNumber(value: GHDeviceTypes.marqExpedition.rawValue), NSNumber(value: GHDeviceTypes.marqAthlete.rawValue), NSNumber(value: GHDeviceTypes.marqCommander.rawValue)]

  @objc
  func startScanning() -> Void {
    GHDeviceManager.shared().add(self);
    GHDeviceManager.shared().setScannerDelegate(self);
    GHDeviceManager.shared().scan(forDevices: self.supportedDevices);
    print("Started scanning");
  }

  @objc
  func stopScanning() -> Void {
    GHDeviceManager.shared().stopScan();
    print("Scanning ended");
  }

  func didConnect(_ device: GHRealTimeDevice) {
    print("didConnect");
  }

  func didDisconnectDevice(_ device: GHRealTimeDevice) {
    print("didConnect");
  }

  func didScanDevice(_ device: GHScannedDevice) {
    print("didConnect");
  }

  func didPairDevice(_ device: GHRealTimeDevice) {
    print("didConnect");
  }

  func didFail(toPairDevice deviceId: UUID, error: Error) {
    print("didConnect");
  }

  func didPausePairing(_ completion: GHPairingCompletion) {
    print("didConnect");
  }

  func scanDidFailWithError(_ error: Error) {
      print("scanDidFailWithError")
      print(error)
  }
}

//RNGarmin.m
#import <React/RCTBridgeModule.h>

@interface RCT_EXTERN_MODULE(RNGarmin, NSObject)

RCT_EXTERN_METHOD(startScanning)
RCT_EXTERN_METHOD(stopScanning)

@end

//swc-Bridging-Header.h
#import <React/RCTBridgeModule.h>

La salida al correr la aplicación y llamar la siguiente función:
useEffect(() => {
    RNGarmin.startScanning();
}, []);

es:
2021-06-29 09:07:37.366641-0300 swc[2573:736288] Connection 1: received failure notification
2021-06-29 09:07:37.366723-0300 swc[2573:736288] Connection 1: failed to connect 1:50, reason -1
2021-06-29 09:07:37.366757-0300 swc[2573:736288] Connection 1: encountered error(1:50)
2021-06-29 09:07:37.368547-0300 swc[2573:736284] Task <C9118789-39B4-49D1-8BFA-783C2867AAD9>.<1> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
2021-06-29 09:07:37.373417-0300 swc[2573:736288] Task <C9118789-39B4-49D1-8BFA-783C2867AAD9>.<1> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x280ad0540 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <C9118789-39B4-49D1-8BFA-783C2867AAD9>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <C9118789-39B4-49D1-8BFA-783C2867AAD9>.<1>"
), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=http://192.168.2.119:8081/status, NSErrorFailingURLKey=http://192.168.2.119:8081/status, _kCFStreamErrorDomainKey=1}
2021-06-29 09:07:37.377921-0300 swc[2573:736116] [native] Module RNGarmin requires main queue setup since it overrides `init` but doesn't implement `requiresMainQueueSetup`. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.
2021-06-29 09:07:37.384174-0300 swc[2573:736116] [native] Running application swc ({
    initialProps =     {
    };
    rootTag = 1;
})
2021-06-29 09:07:37.412353-0300 swc[2573:736284] Connection 2: received failure notification
2021-06-29 09:07:37.412389-0300 swc[2573:736284] Connection 2: failed to connect 1:50, reason -1
2021-06-29 09:07:37.412410-0300 swc[2573:736284] Connection 2: encountered error(1:50)
2021-06-29 09:07:37.413011-0300 swc[2573:736286] Task <1FC30C05-7B91-4BC1-97DB-348216E88FE8>.<2> HTTP load failed, 0/0 bytes (error code: -1009 [1:50])
2021-06-29 09:07:37.413253-0300 swc[2573:736284] Task <1FC30C05-7B91-4BC1-97DB-348216E88FE8>.<2> finished with error [-1009] Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x280ae6220 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <1FC30C05-7B91-4BC1-97DB-348216E88FE8>.<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
    "LocalDataTask <1FC30C05-7B91-4BC1-97DB-348216E88FE8>.<2>"
), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=http://192.168.2.119:8081/status, NSErrorFailingURLKey=http://192.168.2.119:8081/status, _kCFStreamErrorDomainKey=1}
2021-06-29 09:07:37.524201-0300 swc[2573:736284] [connection] nw_socket_handle_socket_event [C3.1:1] Socket SO_ERROR [61: Connection refused]
2021-06-29 09:07:37.524375-0300 swc[2573:736284] [connection] nw_socket_handle_socket_event [C4.1:1] Socket SO_ERROR [61: Connection refused]
2021-06-29 09:07:37.525439-0300 swc[2573:736284] [connection] nw_socket_handle_socket_event [C3.2:1] Socket SO_ERROR [61: Connection refused]
2021-06-29 09:07:37.525566-0300 swc[2573:736284] [connection] nw_socket_handle_socket_event [C4.2:1] Socket SO_ERROR [61: Connection refused]
2021-06-29 09:07:37.525849-0300 swc[2573:736286] [connection] nw_connection_get_connected_socket [C3] Client called nw_connection_get_connected_socket on unconnected nw_connection
2021-06-29 09:07:37.525934-0300 swc[2573:736286] TCP Conn 0x283388580 Failed : error 0:61 [61]
2021-06-29 09:07:37.526277-0300 swc[2573:736286] [connection] nw_connection_get_connected_socket [C4] Client called nw_connection_get_connected_socket on unconnected nw_connection
2021-06-29 09:07:37.526464-0300 swc[2573:736286] TCP Conn 0x28338c9a0 Failed : error 0:61 [61]
2021-06-29 09:07:37.684259-0300 swc[2573:736290] [javascript] Running "swc" with {"rootTag":1,"initialProps":{}}
2021-06-29 09:07:37.687782-0300 swc[2573:736283] [connection] nw_socket_handle_socket_event [C5.1:1] Socket SO_ERROR [61: Connection refused]
2021-06-29 09:07:37.688130-0300 swc[2573:736283] [connection] nw_socket_handle_socket_event [C5.2:1] Socket SO_ERROR [61: Connection refused]
2021-06-29 09:07:37.688593-0300 swc[2573:736284] [connection] nw_connection_get_connected_socket [C5] Client called nw_connection_get_connected_socket on unconnected nw_connection
2021-06-29 09:07:37.688724-0300 swc[2573:736284] TCP Conn 0x283388580 Failed : error 0:61 [61]
2021-06-29 09:07:37.786838-0300 swc[2573:736116] [native] [GESTURE HANDLER] Initialize gesture handler for root view <RCTRootContentView: 0x15de0dba0; reactTag: 1; frame = (0 0; 390 844); gestureRecognizers = <NSArray: 0x280adf510>; layer = <CALayer: 0x2804b31c0>>
Started scanning

A: So I finally solved it, at the end I realized the Garmin module had to run on the main thread (not exactly sure why it is that way but since the module is privare and I can only see the interfaces of each module I'am not expecting to get more information).
Once I told react native to run my module on the main thread it started working fine.


text:
Q: peer.js webrtc >> changing stream in runtime I am developing a cross-plattform application with peer.js and webrtc.
I am using cordova, crosswalk.
Additionaly I am using the webrtc adapter (https://github.com/webrtc/adapter)
My code is based on the webrtc-crosswalk sample. (https://github.com/crosswalk-project/crosswalk-samples)
I want to change the videosource of the stream without creating a new call.
My approche is to remove the tracks of the stream and add the new tracks of the other camera.
The result is that the local video shows the right content, but the callee's remote video freezes.
Probably I am doing a very basic mistake, but i can't find a solution.
I am looking forward to your answers and solutions.
My main codefile is attached.
//Notwendig, um die Dialogfunktion zu aktivieren
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(navigator.notification);
    // Now safe to use device APIs
}

document.addEventListener('DOMContentLoaded', function () {
    // PeerJS server location
    var SERVER_IP = '172.20.37.147';
    var SERVER_PORT = 9000;

    // DOM elements manipulated as user interacts with the app
    var messageBox = document.querySelector('#messages');
    var callerIdEntry = document.querySelector('#caller-id');
    var connectBtn = document.querySelector('#connect');
    var recipientIdEntry = document.querySelector('#recipient-id');
    var dialBtn = document.querySelector('#dial');
    var remoteVideo = document.querySelector('#remote-video');
    var localVideo = document.querySelector('#local-video');
    var cameraTurn = document.querySelector('#camera_turn');
    var stop = document.querySelector('#stop');

    // the default facing direction
    var dir = "environment";

    // the ID set for this client
    var callerId = null;

    // PeerJS object, instantiated when this client connects with its
    // caller ID
    var peer = null;

    // the local video stream captured with getUserMedia()
    var localStream = null;

    // DOM utilities
    var makePara = function (text) {
        var p = document.createElement('p');
        p.innerText = text;
        return p;
    };

    var addMessage = function (para) {
        if (messageBox.firstChild) {
            messageBox.insertBefore(para, messageBox.firstChild);
        }
        else {
            messageBox.appendChild(para);
        }
    };

    var logError = function (text) {
        var p = makePara('ERROR: ' + text);
        p.style.color = 'red';
        addMessage(p);
    };

    var logMessage = function (text) {
        addMessage(makePara(text));
    };

    // get the local video and audio stream and show preview in the
    // "LOCAL" video element
    // successCb: has the signature successCb(stream); receives
    // the local video stream as an argument
    var getLocalStream = function (successCb, ask = true) {
        if (localStream && successCb) {
            successCb(localStream);
        }
        else {

                navigator.mediaDevices.getUserMedia({ audio: true, video: { facingMode: dir } })
                    .then(function (stream) {

                        if (localStream == null) {
                            /* use the stream */
                            localStream = stream;
                        }
                        else {

                            stream.getTracks().forEach(function (track) {
                                localStream.addTrack(track);
                            });
                        }

                        localVideo.src = window.URL.createObjectURL(localStream);

                        if (successCb) {
                            successCb(stream);
                        }
                    })
                    .catch(function (err) {
                        /* handle the error */
                        logError('failed to access local camera');
                        logError(err.message);
                    });
            }

    };

    // set the "REMOTE" video element source
    var showRemoteStream = function (stream) {
        remoteVideo.src = window.URL.createObjectURL(stream);
    };

    // set caller ID and connect to the PeerJS server
    var connect = function () {
        callerId = callerIdEntry.value;

        if (!callerId) {
            logError('please set caller ID first');
            return;
        }

        try {
            // create connection to the ID server
            peer = new Peer(callerId, { host: SERVER_IP, port: SERVER_PORT });

            // hack to get around the fact that if a server connection cannot
            // be established, the peer and its socket property both still have
            // open === true; instead, listen to the wrapped WebSocket
            // and show an error if its readyState becomes CLOSED
            peer.socket._socket.onclose = function () {
                logError('no connection to server');
                peer = null;
            };

            // get local stream ready for incoming calls once the wrapped
            // WebSocket is open
            peer.socket._socket.onopen = function () {
                getLocalStream();
            };

            // handle events representing incoming calls
            peer.on('call', answer);
        }
        catch (e) {
            peer = null;
            logError('error while connecting to server');
        }
    };

    // make an outgoing call
    var dial = function () {
        if (!peer) {
            logError('please connect first');
            return;
        }

        if (!localStream) {
            logError('could not start call as there is no local camera');
            return
        }

        var recipientId = recipientIdEntry.value;

        if (!recipientId) {
            logError('could not start call as no recipient ID is set');
            return;
        }

        getLocalStream(function (stream) {
            logMessage('outgoing call initiated');

            var call = peer.call(recipientId, stream);

            call.on('stream', showRemoteStream);

            call.on('error', function (e) {
                logError('error with call');
                logError(e.message);
            });
        });
    };

    // answer an incoming call
    var answer = function (call) {
        if (!peer) {
            logError('cannot answer a call without a connection');
            return;
        }

        if (!localStream) {
            logError('could not answer call as there is no localStream ready');
            return;
        }

        //Asks user to answer the call
        navigator.notification.confirm(
            "Receive a call?",
            function (buttonIndex) {
                if (buttonIndex === 1) {
                    //user clicked "yes"
                    logMessage('incoming call answered');

                    call.on('stream', showRemoteStream);

                    call.answer(localStream);
                }
                else {
                    //user clicked "no"
                    logMessage('incoming call denied');
                }
            }
            ,
            'Incoming Call',
            ['Yes', 'No']
        );

    };

    function turnDirection() {
        if (dir === "user")
            return "environment";
        else
            return "user";
    }

    var turnCamera = function (call) {
        dir = turnDirection();
        localStream.getTracks().forEach(function (track) {
            track.stop();
            localStream.removeTrack(track);
        });
        getLocalStream(false);

    };
    var stopCall = function (call) { };
    // wire up button events
    connectBtn.addEventListener('click', connect);
    dialBtn.addEventListener('click', dial);
    cameraTurn.addEventListener('click', turnCamera);
    stop.addEventListener('click', stopCall);
});

A: If you remove and then add a new track to a PeerConnection you need to renegotiate the offer-answer to get it working. I will recommend you to use the replaceTrack API to avoid the re-negotiation problem while changing the camera input.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Curl and htmlentities stripping XML tags So i'm working on a php script which passes information to a server using Curl and the POST method and then takes back information from that server in the form of XML.I then want to take this information and parse it into a readable format for the user.
I grab the information using curl and load it into a variable ($result) which i then want to load into simpleXML and store in the variable $routeinfo. However when I perform a var_dump($routeinfo) there doesn't appear to be any data stored. I've confirmed that there is data present in $result by echoing it.
I also figured it may have been due to the XML not showing up in the browser when I echoed $result(but it is there if I check the source). Just to check though I used htmlentities but that causes a lot of errors because < is interpreted as it's html equivalent. Anyway I've reached an impass and have logged quite a few hours implementing different suggestions to no avail. My code is below and I would appreciate any help that can be rendered.
<?php
//retrieve form data in a variable
$input = $_POST['stopNo'] ;

//declare other variables needed
$api_key = 'xxxkey' ;
$api_id = 12345 ;
$url = 'url to send data to' ;
$querystring = "appID=". $api_id . "&apiKey=" . $api_key . "&stopNo" . $input ;
$data = urlencode($url) ;

//curl using

$ch = curl_init() ;

//set up curl

curl_setopt($ch, CURLOPT_URL, 'urlsendingdatato');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'appID='.urlencode($api_id).'&apiKey=' .urlencode($api_key) . '&stopNo=' .urlencode($input) );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0 ) ;
curl_setopt($ch, CURLOPT_ENCODING, "UTF-8") ;
curl_setopt($ch, CURLOPT_BINARYTRANSFER , TRUE) ;

//execute and gather info
$result = curl_exec($ch) ;

//close connection
curl_close($ch) ;

//format data
//ent at the moment serves no purpose doesn't render the information correctly
$ent = htmlentities($result);
$routeinfo = new SimpleXMLElement($result) ;

//print data
echo "
 $result
" ;
var_dump($routeinfo) ;

?>

A: It seems that the problem is arising when the simpleXML object is created.
So you can try creating a new simpleXMLElement object with a well defined XML file. If that works that means the fetched xml file is not of proper format.
$xml="<?xml version='1.0'?><book><author>steve</author><price>200</price><name>Its my life</name></book>";
$test= new SimpleXMLElement($xml);
var_dump($test);

This works for me!
But generally if there is an xml parsing issue, simpleXMLElement throws a error . Did it return any error in your case? or maybe you have switched off error reporting (error_reporting(0); ).


text:
Q: mulitiindexing in python: how to select level0-index based on multiple values in level1 rows I'm working on a multiindex pivot table with 470 columns >7000 rows:
    pivot.head()
    Componentnr               1    2      3      4      5      6      7      8
Genename
A2M      Mediancoverage  84.5  281    156    131     11   81.5    251    101
         inhouse3-5       NaN  NaN    NaN    NaN     1    NaN    NaN    NaN
A2ML1    Mediancoverage   146  156   4.75  124.5  208.5  111.5  136.5  164.5
         inhouse3-5         5    0      0      0      0      0      0      0
A4GALT   Mediancoverage   165  NaN    NaN    NaN    NaN    NaN    NaN    Na

I want to select those level-0 index names that have 'Mediancoverage'<20 and 'inhouse3-5'>0 (excl. NaN)  for the same componentnr (=columns).
Thus for the example above the result should be  'A2M' because of column 5
Until know, I managed to select for row in which any value meets the criteria:
apply(lambda row: any(i<20 for i in row), axis=1)
apply(lambda row: any(i>=1 for i in row), axis=1)

but in this way I don't know if both criteria were met in the same column
Does anyone have an idea?

A: I slightly modified/reformated your data frame example to make it easier to work with:
                            1       2       3       4       5       6       7
Genename    Filter
A2M         Mediancoverage  84.5    281.0   156.00  131.0   11.0    81.5    251.0
            inhouse3-5      NaN     NaN     NaN     NaN     1.0     NaN     NaN
A2ML1       Mediancoverage  146.0   156.0   4.75    124.5   208.5   111.5   136.5
            inhouse3-5      5.0     0.0     0.00    0.0     0.0     0.0     0.0

You can use groupby/apply here to filter your relevant genes:
def filter_gene(sub_df):
    # drop multiindex for easier selection
    sub_df = sub_df.reset_index(0, drop=True)

    # define your filters
    bool_coverage = sub_df.loc["Mediancoverage", :] < 20
    bool_inhouse = sub_df.loc["inhouse3-5", :] > 0

    # if any column fulfills both filter requirements, return True
    if (bool_coverage & bool_inhouse).any():
        return True

# groupby by gene, apply filter, and remove non-hits
result = df.groupby(level="Genename").apply(filter_gene).dropna().index

print(result)
Index(['A2M'], dtype='object', name='Genename')

The idea is simple. You iterate over your genes, apply the filter, and keep those which fulfill your filter requirements.


text:
Q: Data from local json is not displayed in a FlatList I'm trying to display information from a local json file I have.
The json data does gets logged to the console, and seems fine, but I can't get it to display as a FlatList.
This is my json file:
{
"countries": [
    {
        "id": 0,
        "code": "US",
        "display_name": "USA",
        "area_code": 123
    },
    {
        "id": 1,
        "code": "FR",
        "display_name": "FRANCE",
        "area_code": 123
    },
    {
        "id": 2,
        "code": "AUS",
        "display_name": "AUSTRALIA",
        "area_code": 123
    }
]
}

This is my FlatList:
//@ts-ignore
import CountryList from '../utils/countries.json';

const CountryPicker = () => {
    return (
        <View style={pickerStyles.container}>
            <Text style={pickerStyles.title}>Pick your location</Text>

            <FlatList
                    data={CountryList}
                    //@ts-ignore
                    renderItem={CountryList.countries.map(country => {
                        return (
                            <Text>{country.display_name}</Text>
                        );
                    })}
                    keyExtractor={country => country.id}
                />
        </View>
    );
}

A: You Should do like below, as Data prop expects an array and you are passing an object.
     <FlatList
                data={CountryList.countries}
                //@ts-ignore
                renderItem={({item}) => {
                    return (
                        <Text>{item.display_name}</Text>
                    );
                })}
                keyExtractor={item => item.id}
            />


text:
Q: How can I get the current Test with Split AB Testing I started a test with the Split AB Testing gem, which renders two different templates like
@test = ab_test("test", "template_1", "template_2")

At this point @test gives me the desired template name.
But I don't want to pass this parameter to the place I need it.
Is there a possibility to directly get the current test?

A: I found out that the helper method
active_experiments()

provides all active experiments for the current user, which is exactly what I need. Thanks for your efforts.

A: Under the Experiment Configuration heading in the documentation, it says you can do something like this:
<% ab_test("my_first_experiment") do |alternative, meta| %>
  <%= alternative %>
  <small><%= meta['text'] %></small>
<% end %>

You could wrap that in an if admin or something so only you see it.


text:
Q: Code to help change data in the SQL Server from lower case to upper case? I require help to use data from the SQL Server to extract it then decrpyt it, convert it to capital and then encrypt it and send back to database. Is there code to help upper case the columns in the database?
// connection string
static string connStr = ConfigurationManager.ConnectionStrings["tmsdbConnection"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);

protected Cryptography a = new Cryptography();

protected void btnUpdate_Click(object sender, EventArgs e)
{
    conn.Open();
    // Response.Write("Connection Established");
    this.getdataTable();
    this.getDataSet();

    // retrieve data
    SqlCommand command;

    String sql, Output = " ";
    sql = "SELECT applicantId, fullName, idNumber, idType, nationality, race, gender, birthDate, highestEducation, spokenLanguage, getToKnowChannel FROM applicant";

    // command = new SqlCommand(sql, conn);
    command = new SqlCommand("SELECT applicantId, fullName, idNumber, idType, nationality, race, gender, birthDate, highestEducation, spokenLanguage, getToKnowChannel FROM applicant");

    Cryptography c = new Cryptography();
    lblRecords.Text = c.encryptInfo(lblRecords.Text);
}

These are the database methods:
public DataTable getDataTable(SqlCommand cmd)
{
    cmd.Connection = getDBConnection();
    cmd.Connection.Open();
    cmd.CommandTimeout = 1200;

    SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    dataAdapter.Fill(dt);
    cmd.Connection.Close();

    return dt;
}

public DataSet getDataSet(SqlCommand cmd)
{
    cmd.Connection = getDBConnection();
    cmd.Connection.Open();
    cmd.CommandTimeout = 1200;

    SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();

    dataAdapter.Fill(ds);
    cmd.Connection.Close();

    return ds;
}

and these are the cryptography methods:
public string encryptInfo(string inputText)
{
    cipherData = AES_256.encryptStringToBytes(inputText, keyBytes, ivBytes);
    string userinfo64Text = Convert.ToBase64String(cipherData);
    return userinfo64Text;
}

public string decryptInfo(string outputText)
{
    byte[] inputbytes = Convert.FromBase64String(outputText);
    string plainText = AES_256.decryptStringFromBytes(inputbytes, keyBytes, ivBytes);
    return plainText;
}

A: There is a built-in SQL Server Function called UPPER:
SELECT UPPER('myvalue')


text:
Q: Sharing strings and variables throughout ios app I'm making an app for a final project for class and I need to share strings, integers and floats throughout different views in my application.  I have to create an app that a waiter/waitress would use on the job.  I need different views for different types of items to order (beverages, appetizers, entrées, etc.) and need to keep the items chosen, the price and the quantity of each accessible to different views to keep a running total available in each view (one view for each type of item) and finally for a view that displays an itemized list of what was ordered plus the total.
From what I understand I wouldn't want to use a tab bar application layout because typically users don't expect information to be the same between different tabbed views, so I was thinking of using a segmented controller for this.  To get the strings, integers and floats shared between views could declare them in the AppDelegate?  I've read that I could use singletons but we haven't covered that in my class so I think that may just add more complexity than I need.  If I were to declare them in the AppDelegate would I have to synthesize them in the AppDelegateViewController.m to make them available throughout?  I can't imagine I'd have to synthesize them for each different ViewController.  Or would NSUserDefaults be perfect for this situation?
If I declared an instance variable in the AppDelegate would that essentially make it a global variable?  I know that this is against encapsulation practices but that won't make a big difference with this app, it's not going to be in the App Store and the overhead shouldn't make a big difference considering this is going to be a relatively small app.
Thanks in advance everyone.  Good luck with your finals if you still have them approaching!

Edit

I guess I should say that this is going to be a janky, terrible app off the bat, we didn't cover a lot of the more advanced topics such as the MVC paradigm for iOS so I'm pretty limited with what I can do compared to what we're supposed to do.  Stupid class, I regret signing up for it when I really could have gone about this myself and gotten a better understanding of Objective-C, which we were taught nothing about, and a better understanding of the iOS framework.
Basically, if I declare the variables in the AppDelegate, even though it's a faux pas, would that work to access the strings and such from the different views?  Or would the NSUserDefaults be a better solution in this case?  I'm leaning towards NSUserDefaults and declaring them in the projects ViewController.

A: A typical Objective C MVC solution is to put all your related shared strings and variables into a Model object (create a new class for this object) as properties.  Then share that Model object with all the Controllers that need to access those variables or strings.
Using the AppDelegate as a model object is "over-sharing", and clutters up the app delegate with non-delegate related stuff.  A slightly cleaner solution is to have the app delegate hold a getter to a Model object that is widely used throughout the app.  A solution that can cause code reuse problems, and is otherwise considered politically-incorrect, is to assign the model object, and/or the shared variables themselves, to C global variables (be careful with your retains).  (But this usually generates the fastest and smallest amount of code, if you care about such things.)

A: As hotpaw2 said, using a distinct model class is the best way to go.
But, as this is a small app (while you are learning the basics) implementing these few variables in the app delegate wouldn't hurt and is perhaps a little easier.
If the app grows then you'll probably want to move the model out of the app delegate and into it's own class.
An even easier and simpler method would be to store this small amount of data in nsuserdefaults:
save to nsuserdefaults:
[[NSUserDefaults standardUserDefaults] setObject:howManyDrinks forKey:@"howManyDrinks"];
[[NSUserDefaults standardUserDefaults] synchronize];

retrieve from nsuserdefaults:
NSString *howManyDrinks = [[NSUserDefaults standardUserDefaults] objectForKey:@"howManyDrinks"];

A: You can utilize the facility of Delegation pattern using Protocols in Objective C.

A: You could also store these values in a plist, which can then be accessed and edited from anywhere within the app. It is easier to implement than a singleton. And since you can set the plist up visually in XCode, it's relatively easy for beginners. I even created a wrapper for my plist to make editing the data simple. Here's a tutorial for plists.

A: I'm not an expert in this yet, but I've been using a singleton, with an object inside. As far as I have experienced, the values inside that object is held. To create a singleton, you'd do something like this:
Create a normal Object, and add this to the header file:
+ (id)sharedManager;

Then in the .m file, add this:
+ (id)sharedManager {
    static SharedInfo *sharedMyManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedMyManager = [[self alloc] init];
    });
    return sharedMyManager;
}
- (id)init {
    if (self = [super init]) {
        self.myStuff = [[NSMutableDictionary alloc]init];
  //This is where you initialise your variables. The example above is for a
 //property that I have declared in the .h file
    }
    return self;
}

And then, throughout your app you'd use this:
[[[SharedInfo sharedManager] myStuff] addObject: SomethingTocreate];

Make sure you include the SharedInfo.h in the viewcontroller that you want to use it in.
I hope this helped.


text:
Q: QGIS coordinates not displaying correctly Making my first Print in QGIS, and for some reason the coordinates are all over the place (see image). Does anyone know what would be causing this?
All of my settings seem quite standard, I will post these as well. This area should be bounded by a rectangle of just a few minutes in span.

A: Unfortunately I am not sure of the version of QGIS you are running, but this should apply to most QGIS 3.x versions.
When you add a map to the layout, you can access the map item properties.
From the screenshot provided, you seem to be accessing the "Map Grid Properties".
The item properties for your map will have icons under the map name - default is "Map 1".
These icons may look different depending on version, but in 3.10 they are a "refresh", boxes with arrows and some page extent controllers.
Click on the "Set Map Extent to Match Canvas Extent" button, this will change the map to the extent of your canvas.
Make sure the canvas is at an extent you feel you can use, you can then tweak it as you go.

A: All,
After watching several videos / learning more about the process for adding grids on the map, I realized I was using the wrong CRS as Erik pointed out. I switched to EPSG6345 and everything started working properly. Thank you all!


text:
Q: How to add clone of a java object to list I have an arraylist and I want to add some objects with little changes to this arraylist.
Here is my code;
Student student = createSampleStudent();
List<Student> studentList= new ArrayList<Student>();

for(int i = 0; i < 5; i++) {
    student.setId(getRandomId());
    studentList.add(student);
}

I want to add students to studentList with different ids.I can't create student in for loop because it takes too long to create a student. I have found that there is a clone method but Student object has many fields(most of them refers to another object). Is there any idea?

A: I just tell you a creepy method to copy object, you must not use it in production code, but I think it will be work. You can use Unsafe, the Sun's backdoor. All that you need to do is get Unsafe instance:
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
Unsafe unsafe = (Unsafe) f.get(null);

Ignore your IDE, it will warn you about access restriction, but if you run this code everything will work. If the error is annoying, ignore errors in preferences. After this you can do a copy of object on low-level memory copying.
private static long normalize(int value) {
    if(value >= 0) return value;
    return (~0L >>> 32) & value;
}

public static long sizeOf(Object object){
    return getUnsafe().getAddress(
        normalize(getUnsafe().getInt(object, 4L)) + 12L);
}

private static long toAddress(Object obj) {
    Object[] array = new Object[] {obj};
    long baseOffset = getUnsafe().arrayBaseOffset(Object[].class);
    return normalize(getUnsafe().getInt(array, baseOffset));
}

private static Object fromAddress(long address) {
    Object[] array = new Object[] {null};
    long baseOffset = getUnsafe().arrayBaseOffset(Object[].class);
    getUnsafe().putLong(array, baseOffset, address);
    return array[0];
}

static Object shallowCopy(Object obj) {
    long size = sizeOf(obj);
    long start = toAddress(obj);
    long address = getUnsafe().allocateMemory(size);
    getUnsafe().copyMemory(start, address, size);
    return fromAddress(address);
}

After all you can just call in your for loop this construction:
Student student = createSampleStudent();
List<Student> studentList= new ArrayList<Student>();
for(int i = 0; i < 5; i++) {
    student = MyUnsafeUtil.shallowCopy(student);
    student.setId(getRandomId());
    studentList.add(student);
}

Remember, this is a really bad and dark magic in java.


text:
Q: how can I find the qutient of this subgroup? Let $G$ be a finite group and $N\lhd G$. For every $x\in G-N$ we have
$$C_G(x)N/N\leq C_{G/N}(Nx)$$
where $C_G(x)$ is the centralizer of $x$ in $G$. But I don't know what is the qutient.
In fact I want to know the $[C_{G/N}(Nx):C_G(x)N/N]$.
It is more important when $N=Z(G)$.


text:
Q: 3-complexes not embeddable in 3-space My question is about embeddability of 3-dimensional complexes in R^3. Do we have something like Kuratowski's theorem for complexes in 3-space which specifies a set of minors for non-embeddability?

A: No, in higher dimensions there is no analogue of Kuratowski's theorem. See thesis of Anna Gundert for a leisurely overview, and the references. There is also a recent work of Matoušek, Tancer and Wagner that addresses how to determine if a complex is embeddable. They have a nice table for different dimensions on page 4 from it transpires it is not known how hard the problem is.
Addition on 21 Jul 2014: The problem is now known to be decidable. See the recent paper by Matoušek, Sedgwick, Tancer, and Wagner (you want Corollary 1.2).


text:
Q: sed - Remove parts of certain strings across multiple files From the tutorial here, I learned to find and replace text across multiple files from the Linux command line. For example,
find . -name "*.php" -print | xargs sed -i 's/foo/bar/g'

finds all instances of 'foo' in files that end with '.php' and replaces such instances with 'bar'.
Now suppose I have multiple, redundant occurrences of something like assert something.makeAssertion that I want to replace with just something.makeAssertion. Given that something can vary, how do I adapt the script for this? I tried some things with $ to capture something as a variable (?) but haven't figured it out.

A: Superficially, you could use:
find . -name '*.php' -exec \
    sed -i.bak -e 's/assert\(.*\.makeAssertion\)/\1/g' {} +

The regex drops the assert when there's a .makeAssertion later on the line.  The find … -exec runs the sed on the files it finds.  The + indicates 'group a convenient number of files into a single command line', rather like xargs but without some complications.  An alternative using GNU find and xargs would be:
find . -name '*.php' -print0 |
    xargs -0 sed -i.bak -e 's/assert\(.*\.makeAssertion\)/\1/g'

Both these avoid problems with spaces or newlines in file names.


text:
Q: CSS text-align on inline-block element I have this structure:

 This string is left-aligned

  //contains other divs.I used inline block for making this div as large as
  //content ATTENTION: its width is not fixed!

How could I say :
Let me have ONLY the class named "divToCenter" centered in "father" div.
Thanks
Luca

A:

#left {
  float: left;
   background: #eee;
   width: 200px; /* width is optional */
}
#content {
  overflow: hidden;
  text-align: center;
}

This string is left-aligned

Float the left aligned string or block to the left, then with overflow:hidden on the content it will automatically take up the remaining space and you can text-align it how you want.
Either that or convert the left content to an inline block too so it and content are side by side and you will be able to text-align each inline-block separately.

A: div.divToCenter
{
margin: 0 auto;
}

A: .father { text-align: center; }
.father div.divToCenter { margin: 0 auto; }

Update:
.father { text-align: left; }
.father div.divToCenter { width:Xpx; margin: 0 auto; }


text:
Q: Charge density on a plate of a realistic capacitor Suppose we have a realistic capacitor,connected to a constant voltage source, with plates at some distance $d$ and a varying charge density across plate due to edge effects. Is it correct to assume charge density would be greatest in the middle of the plate and drop as we move towards the edges. Also, Is it correct that the charge density would increase with increasing plates distance ( Electric field increases )?

A: First point is that you would normally get more charge at the edges.
Second point - if you increase the gap then the capacitance would be reduce and the quantity of charge that could be stored for a particular potential difference would be reduced.
Remember electric field is charge / distance so decreasing the gap would increase the electric field
You should also look at this question and the answer. The question addresses realistic capacitors and gap. It is related to part of your question, but not the same.


text:
Q: SSRS:Use decimal place in expression I would like to minimize the decimal place in my report.
my expression:
="On: "& Avg(Fields!System.Value) & " OFF: " & avg(Sum(Fields!A1.Value)/Sum(Fields!A2.Value)*100)

I would like to show no decimal place for ON and one deciaml place for OFF.
I tried it with the function of ssrs but that is not possible.
How can I do this in this expression?

A: Try:
="On: "& FORMAT(Avg(Fields!System.Value),"N2") & " OFF: " & FORMAT(avg(Sum(Fields!A1.Value)/Sum(Fields!A2.Value)*100),"N2")

In "Nx" replace x by the number of decimals you want to show.
Let me know if this helps.


text:
Q: display all unique date available first I have a VBA script which takes input from user to perform find and replace, want to display all the unique date available first
I have written this VBA script to perform find and replace but I want to add one more functionality here,it should display me the list of all the distinct dates available in the column first and after that we can perform find and replace*
Sub dateupdation()

Dim sht As Worksheet
Dim fnd As Date
Dim rplc As Date

fnd = InputBox("Enter date")
rplc = InputBox("Enter updated date")

For Each sht In ActiveWorkbook.Worksheets
    sht.Cells.Replace what:=fnd, Replacement:=rplc, _
    LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
    SearchFormat:=False, ReplaceFormat:=False
Next sht
End Sub


text:
Q: asyncio start_server timeout issue I have a TCP server implemented in Python using asyncio's create_server.
I call the coroutine start_server with a connection_handler_cb.
Now my question is this: let's say my connection_handler_cb looks something
like this:
   def connection_handler_cb(reader, writer):
       while True:
           yield from reader.read()
           --do some computation--

I know that only the yield from coroutines are being run "concurrently"  (I know it's not really concurrent), all the "--do some computation--" part is being called sequentially and is preventing everything else from running in the loop.
Let's say we are talking about a TCP server with multiple clients trying to send. Can this situation cause send timeout from the other side - the client side?

A: If your clients are waiting for a response from the server, and that response isn't sent until the computation is done, then it's possible the clients could eventually timeout, if the computations took long enough. More likely, though, is that the clients will just hang until the computations are done and the event loop gets unblocked.
In any case, if you're worried about timeouts or hangs, use loop.run_in_executor to run your computations in a background process (this is preferable), or thread (probably not a good choice since you're doing CPU-bound computations) without blocking the event loop:
  import asyncio
  import multiprocessing
  from concurrent.futures import ProcessPoolExecutor

  def comp_func(arg1, arg2):
       # Do computation here
       return output

  def connection_handler_cb(reader, writer):
       while True:
           yield from reader.read()
           # Do computation in a background process
           # This won't block the event loop.
           output = yield from loop.run_in_executor(None, comp_func, arg1, arg2) #
  if __name__ == "__main__":
      executor =
      loop = asyncio.get_event_loop()
      loop.set_default_executor(
           ProcessPoolExecutor(multiprocessing.cpu_count()))
      asyncio.async(asyncio.start_server(connect_handler_cb, ...))
      loop.run_forever()


text:
Q: Rails3 on Windows I am about to start a new site which needs to reside on a Windows server.
I have done Ruby development in the past and am therefore naturally very keen on using Rails for this project.
Is this a safe option as on Linux/Mac or should I stick to .NET as this is the native choice for the platform?
Also, what about IIS?

A: It works fine, you should be able to use more or less the same kind of deployment scenario as on unix, only problem you might run into is installing gems that contains native (C most of the time) code.


text:
Q: PHP : mailto function gets breaking when populating text having lines and url Hi I am creating a task assignment page, in which after creating the task admin can send a mail to assignee to know the task. I cant use PHP mail function since I cant configure office SMTP mail address. So I am using mailto function.
Issue happens when my Commenst got symbols like " &, ", ' . It will stop executing the remaining part of code
In my mail it just populates the first line. So my comments is getting broken.
Here is my code to mailto function :
';

A: You put everything into one line which brings you into devils kitchen. Instead put the functionality apart (e.g. first load the data from the database), then process the data (e.g. build the mailbox name, the subject and the body) and then finally create the mail URL.
<?php

# load data from database
$assignee = mysql_result($result, $i, 'assignee');
$comments = mysql_result($result, $i, 'comments');

# process data
$mailbox = sprintf('%s@symantec.com', rawurlencode($assignee));
$headers = array(
    'subject' => 'Task Assignment',
    'body' => "Hello $assignee,\n\nDescription : $comments ...\n\nFor more details log in to ...",
);

# generate the mailto URL
$url = sprintf('mailto:%s?%s', $mailbox, http_build_query($headers));

You can then just output the $url:
printf('',
        $url);

A: You need to explicity urlencode everything that is non alphanumeric.
Note, urlencode (the php command) doesn't urlencode everything such as underscore and letters and perhaps other things.
Example:
    $test="this: is it's dog/+_";
    echo "
";
    echo urlencode($test);
    echo "
";
    echo $test;

produces:
this%3A+is+it%27s+dog%2F%2B_
this: is it's dog/+_


text:
Q: C program crashes when trying to refer to struct array I'm trying to make a simple database program, but when I get to this line
int idSearch(product* itens, int id) {
    int i = 0;
    for(i; i < size; i++) {
        if(itens[i].id == id) //<=== This line
            return i;
    }
    return ITEM_NOT_FOUND;
}

the program stops responding.
size is set as a global variable in the begining of the program
FILE* flog;
FILE* db;
FILE* sizef;
int size = 100;

this function is called by
void newProduct(product* itens, char name[64], int id, float price) {
    int pos = idSearch(itens, 0);

    if(idSearch(itens, id) != ITEM_NOT_FOUND) {
        printf("Erro, o produto ja existe");
        return;
    }...

items is defined as
itens = (product*) calloc(sizeof(product), size);

and product is a struct defined as such
typedef struct{
    char    name[64];
    int     id;
    float   price;
    int     amount;
} product;

Firstly I thought the problem was that I was not using the -> operator, but when I tried the compiler says its not right.
I'm using Code::Blocks with GCC compiler on a Windows 7 x64
**EDIT: the whole code can be found here: http://hastebin.com/atulajubar.tex
Hope to hear answers soon, Thanks in advance

A: **EDIT: You're calling calloc() wrong. The signature is: void *calloc(size_t nelem, size_t elsize);
You're giving it the size first, then the number of elements. Switch that around and see if your problem is resolved.
Also, when calling (AFTER THE FIX:) itens = (product*) calloc( size, sizeof(product) );,
it's important to check to see that itens is not NULL after doing this. If calloc isn't able to give you back the right amount of memory, it returns a NULL pointer I believe. Check this, because if you're getting NULL back, that's your issue.
One good, easy, portable way of checking that would be:
if(!itens){
   fprintf(stderr, "Error! Could not allocate memory!\n");
   exit(1);
}

Also, as WhozCraig suggested, please make sure your code contains #include <stdlib.h>, a requirement of calloc() as per its man page.

A: This is wrong:
if((db = fopen(DB_PATH, RB))==NULL)
{
    if((db = fopen(DB_PATH, RWB))==NULL)
    {
        exit(1);
    }
    else
    {
        itens = (product*) calloc(sizeof(product), size);
        fwrite(itens, sizeof(product), size, db);
        rewind(db);
    }
}
fread(itens, sizeof(product), size, db);

If you have a DB_PATH file in the current working directory the first fopen() will succeed and the items allocation will never take place. Only if the file is not found, but is then successfully created will items contain a valid allocation, assuming calloc worked.
That else condition should be removed:
// note calloc parameter order addressed.
itens = calloc(size, sizeof(product));
if (itens == NULL)
{
    perror("Failed to allocate items.");
    exit(EXIT_FAILURE);
}

if((db = fopen(DB_PATH, RB))==NULL)
{
    if((db = fopen(DB_PATH, RWB))==NULL)
        exit(EXIT_FAILURE);

    fwrite(itens, sizeof(product), size, db);
    rewind(db);
}

fread(itens, sizeof(product), size, db);

There is a significant amount of error checking left to handle, but this needs to be addressed regardless.


text:
Q: Unable to save model when using Tensorflow Lattice Canned Estimator I'm trying to run the Tensorflow Lattice Canned Estimators tutorial: https://www.tensorflow.org/lattice/tutorials/canned_estimators#calibrated_lattice_model
when it get to this row:
saved_model_path = estimator.export_saved_model(estimator.model_dir,
                                                serving_input_fn)

I get the following error:
>TypeError                                 Traceback (most recent call last)
<ipython-input-21-1d0ce82d7b37> in <module>
     19 print('Calibrated linear test AUC: {}'.format(results['auc']))
     20 saved_model_path = estimator.export_saved_model(estimator.model_dir,
---> 21                                                 serving_input_fn)
     22 model_graph = tfl.estimators.get_model_graph(saved_model_path)
     23 tfl.visualization.draw_model_graph(model_graph)
>
>~\Anaconda3\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py in export_saved_model(self, export_dir_base, serving_input_receiver_fn, assets_extra, as_text, checkpoint_path, experimental_mode)
    726         as_text=as_text,
    727         checkpoint_path=checkpoint_path,
--> 728         strip_default_attrs=True)
    729
    730   def experimental_export_all_saved_models(self,
>
~\Anaconda3\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py in _export_all_saved_models(self, export_dir_base, input_receiver_fn_map, assets_extra, as_text, checkpoint_path, strip_default_attrs)
    864             save_variables,
    865             mode=ModeKeys.PREDICT,
--> 866             strip_default_attrs=strip_default_attrs)
    867         save_variables = False
    868
>
~\Anaconda3\lib\site-packages\tensorflow_estimator\python\estimator\estimator.py in _add_meta_graph_for_mode(self, builder, input_receiver_fn_map, checkpoint_path, save_variables, mode, export_tags, check_variables, strip_default_attrs)
    932       tf.compat.v1.random.set_random_seed(self._config.tf_random_seed)
    933
--> 934       input_receiver = input_receiver_fn()
    935
    936       # Call the model_fn and collect the export_outputs.
>
~\Anaconda3\lib\site-packages\tensorflow_estimator\python\estimator\export\export.py in serving_input_receiver_fn()
    308     receiver_tensors = {'examples': serialized_tf_example}
    309     features = tf.compat.v1.io.parse_example(serialized_tf_example,
--> 310                                              feature_spec)
    311     return ServingInputReceiver(features, receiver_tensors)
    312
>
~\Anaconda3\lib\site-packages\tensorflow\python\ops\parsing_ops.py in parse_example(serialized, features, name, example_names)
    316 @tf_export(v1=["io.parse_example", "parse_example"])
    317 def parse_example(serialized, features, name=None, example_names=None):
--> 318   return parse_example_v2(serialized, features, example_names, name)
    319
    320
>
~\Anaconda3\lib\site-packages\tensorflow\python\ops\parsing_ops.py in parse_example_v2(serialized, features, example_names, name)
    310   ])
    311
--> 312   outputs = _parse_example_raw(serialized, example_names, params, name=name)
    313   return _construct_tensors_for_composite_features(features, outputs)
    314
>
~\Anaconda3\lib\site-packages\tensorflow\python\ops\parsing_ops.py in _parse_example_raw(serialized, names, params, name)
    357         ragged_split_types=params.ragged_split_types,
    358         dense_shapes=params.dense_shapes_as_proto,
--> 359         name=name)
    360     (sparse_indices, sparse_values, sparse_shapes, dense_values,
    361      ragged_values, ragged_row_splits) = outputs
>
~\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_parsing_ops.py in parse_example_v2(serialized, names, sparse_keys, dense_keys, ragged_keys, dense_defaults, num_sparse, sparse_types, ragged_value_types, ragged_split_types, dense_shapes, name)
    761                           ragged_value_types=ragged_value_types,
    762                           ragged_split_types=ragged_split_types,
--> 763                           dense_shapes=dense_shapes, name=name)
    764   _result = _outputs[:]
    765   if _execute.must_record_gradient():
>
~\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py in _apply_op_helper(op_type_name, name, **keywords)
    693       elif attr_def.type == "list(type)":
    694         attr_value.list.type.extend(
--> 695             [_MakeType(x, attr_def) for x in value])
    696       elif attr_def.type == "shape":
    697         attr_value.shape.CopyFrom(_MakeShape(value, key))
>
~\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py in <listcomp>(.0)
    693       elif attr_def.type == "list(type)":
    694         attr_value.list.type.extend(
--> 695             [_MakeType(x, attr_def) for x in value])
    696       elif attr_def.type == "shape":
    697         attr_value.shape.CopyFrom(_MakeShape(value, key))
>
~\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py in _MakeType(v, attr_def)
    178                     (attr_def.name, repr(v)))
    179   i = v.as_datatype_enum
--> 180   _SatisfiesTypeConstraint(i, attr_def, param_name=attr_def.name)
    181   return i
    182
>
~\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py in _SatisfiesTypeConstraint(dtype, attr_def, param_name)
     59           "allowed values: %s" %
     60           (param_name, dtypes.as_dtype(dtype).name,
---> 61            ", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
     62
     63
>

TypeError: Value passed to parameter 'sparse_types' has DataType int32 not in list of allowed values: float32, int64, string'

A: I couldn't reproduce the error in the Google Colab runtime provided by TensorFlow by default. Would you mind giving it another shot?
In case you are running in a custom runtime: the error message suggests that the data type for the sparse features - in other words, features defined by categorical_column_with_vocabulary_list - is int32 which is not supported. You might be able to solve this issue by specifying the dtype argument for these integer-valued sparse features, for example,
fc.categorical_column_with_vocabulary_list('sex', [0, 1], dtype=tf.int64)


text:
Q: Daily light integral from 20s light intensity MySQL records I record light intensity at 20s intervals as a number of photons. I need to integrate the values over the day. Daily light integral assumes that light intensity is measured every second. Simply doing a SUM() over the day's records and multiplying the result by 20 would work if the records were exactly 20s apart, which unfortunately they are not.
I need to multiply each reading by the difference in time between the record and the previous one.
I would prefer to do this in SQL rather than pulling records one at a time programmatically.
Ideas welcome.
[edit]
Just looked at some real data and the approximation made by assuming the intervals are exactly 20s is less that assuming that sampling every 20s can stand in for sampling every second.
So I withdraw the question

A: Here is a little sample with a table with 3 columns (id, timestamp, cnt)
then you can calculate it like this:
SELECT p.id, p.mytime, p.photons, l.photons
,TIMESTAMPDIFF(SECOND, l.mytime, p.mytime) diffsecs
,p.photons * COALESCE(TIMESTAMPDIFF(SECOND, l.mytime, p.mytime),1) as cnt
FROM photons p
LEFT JOIN photons l ON p.id -1 = l.id
ORDER BY p.id;

SELECT SUM( p.photons * COALESCE(TIMESTAMPDIFF(SECOND, l.mytime, p.mytime),1)) as cnt
FROM photons p
LEFT JOIN photons l ON p.id -1 = l.id
ORDER BY p.id;

sample
mysql> describe photons;
+---------+------------------+------+-----+---------+----------------+
| Field   | Type             | Null | Key | Default | Extra          |
+---------+------------------+------+-----+---------+----------------+
| id      | int(11) unsigned | NO   | PRI | NULL    | auto_increment |
| mytime  | timestamp        | YES  | MUL | NULL    |                |
| photons | int(11)          | YES  |     | NULL    |                |
+---------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> select * from photons;
+----+---------------------+---------+
| id | mytime              | photons |
+----+---------------------+---------+
|  1 | 2020-02-26 12:00:00 |     100 |
|  2 | 2020-02-26 12:00:25 |      80 |
|  3 | 2020-02-26 12:01:00 |     100 |
|  4 | 2020-02-26 12:05:00 |     200 |
|  5 | 2020-02-26 12:05:03 |      22 |
+----+---------------------+---------+
5 rows in set (0.00 sec)

mysql> SELECT p.id, p.mytime, p.photons, l.photons
    -> ,TIMESTAMPDIFF(SECOND, l.mytime, p.mytime) diffsecs
    -> ,p.photons * COALESCE(TIMESTAMPDIFF(SECOND, l.mytime, p.mytime),1) as cnt
    -> FROM photons p
    -> LEFT JOIN photons l ON p.id -1 = l.id
    -> ORDER BY p.id;
+----+---------------------+---------+---------+----------+-------+
| id | mytime              | photons | photons | diffsecs | cnt   |
+----+---------------------+---------+---------+----------+-------+
|  1 | 2020-02-26 12:00:00 |     100 |    NULL |     NULL |   100 |
|  2 | 2020-02-26 12:00:25 |      80 |     100 |       25 |  2000 |
|  3 | 2020-02-26 12:01:00 |     100 |      80 |       35 |  3500 |
|  4 | 2020-02-26 12:05:00 |     200 |     100 |      240 | 48000 |
|  5 | 2020-02-26 12:05:03 |      22 |     200 |        3 |    66 |
+----+---------------------+---------+---------+----------+-------+
5 rows in set (0.00 sec)

mysql> SELECT SUM( p.photons * COALESCE(TIMESTAMPDIFF(SECOND, l.mytime, p.mytime),1)) as cnt
    -> FROM photons p
    -> LEFT JOIN photons l ON p.id -1 = l.id
    -> ORDER BY p.id;
+-------+
| cnt   |
+-------+
| 53666 |
+-------+
1 row in set (0.00 sec)

mysql>


text:
Q: Scrapy Middleware Selenium with meta Basically, I have a working version of middleware to pass all requests through selenium and return HtmlResponse, the problem is I also want to have some meta data to be attached to the request which I can access in parse method of spider. For some reason I can't access it in parse method of spider, could you help me please?
middleware.py
def process_request(self, request, spider):
    request = request.replace(meta={'test': 'test'})
    self.driver.get(request.url)
    body = self.driver.page_source
    return HtmlResponse(self.driver.current_url, body=body, encoding='utf-8', request=request)

spider.py
def parse(self, response):
    yield {'meta': response.meta}

A: In the yield of the first function where we Request URL, there is another argument called meta by which we can pass details from the first function to the second one in a dictionary.
For example, in the first function, we well have:
yield Request(url, callback=self.parse_function, meta={'Date Added':date, 'Category':category})

In the second function, what we yield is rather this meta  dictionary. This will be like this:
yield response.meta

What about the details we get from the second function? We should first add them to the dictionary before yield, just as adding to any dictionary, like this:
response.meta['Brand'] = brand
response.meta['Model'] = model
response.meta['Price'] = price


text:
Q: JSON to MySQL in Python I need to instert all response from a Websocket Cilent to a MySQL Database.
Unfortunately, I did not find anything on the internet that could help me.
My code so far:
    def to_db(self):
    cur = self.db.cursor()
    db = self.db
    while True:
        data = self.ws.recv()
        print(data)
        sql = f"INSERT INTO `db`.`test` (`output`) VALUES ({data});"
        cur.execute(sql)
        db.commit()
        db.close()

When I run the scripts I get the following error message:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"event":"info","version":2,"serverId":"e7caa4g8-7642-45f5-abc9-c9f3ad325274","pl' at line 1

I created my database like this:
create table websocket_test
(
  output json null
);


text:
Q: Chrome Extension API: chrome.tabs.captureVisibleTab on Background Page to Content Script My overall goal was to take a screenshot via the background page using:
http://developer.chrome.com/extensions/tabs.html#method-captureVisibleTab
and pass it to the content script so I can use the page's HTML DOM to analyze the screenshot and cut it up the way I would like.
However, I can't seem to pass the dataUrl back to the content script with Message Passing:
http://developer.chrome.com/extensions/messaging.html
I tried JSON.stringify() but to no avail.
This works perfectly fine:
background.js

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        sendResponse({imgSrc:'hello'});
    }
);

I switch the code to this and nothing gets through:
background.js

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        chrome.tabs.captureVisibleTab(
            null,
            {},
            function(dataUrl)
            {
                sendResponse({imgSrc:dataUrl});
            }
        )
    }
);

My only proof that the background page is actually taking a screenshot is that I can do
chrome.tabs.captureVisibleTab(null,{},function(dataUrl){console.log(dataUrl);});

and I see
"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAA....etc..."
logged in background.html, which is valid
My question is: How can I send this URL to the content script?
I would prefer not to do all the logic on the background page which can't control anything on the actual visible page.

A: Use chrome.tabs.sendMessage and make sure to return true, not the event listener
background page:
chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        chrome.tabs.captureVisibleTab(
            null,
            {},
            function(dataUrl)
            {
                sendResponse({imgSrc:dataUrl});
            }
        );

        return true;
    }
);

content script
chrome.runtime.sendMessage({msg: "capture"}, function(response) {
  console.log(response.dataUrl);
});


text:
Q: Detect if date is numeric date (and not from relative format) I have some various field from user inpout and from the system. The context is I don't know for all variables if the variable is a date, neither the expected date format from the system.
If the user respond to a field 'when do you need it' by 'now', I don't want the value to be treated as the current date.
Do you have a simple way to detect if the date is a valid date like http://php.net/manual/en/datetime.formats.date.php
but not  a valid string for strtotime?
The test set expected is: [$input, $expected]:
[new \DateTime(), true],
[new \DateTimeImmutable(), true],
['2000-01-01', true],
['31/12/2000', true],
['01-01-1995', true],
['@1306123200', true],
['2010-04-25 02:24:16+12:00', true],

['12/31/2000', false],
['31/31/2000', false],
['now', false],
['next week', false],
[new \DateTimeZone('Europe/Paris'), false],
[false, false],
[0, false],
[true, false],
[1, false],
['1', false],
['1.1', false],
["", false],
[null, false],
[[], false],
[new \stdClass(), false],
["hi", false],

So far I'm checking by checking words:
foreach (['day', 'month', 'year', 'next', 'last', 'previous', 'this', 'ago', 'week', 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'now'] as $needle) {
        $res = strpos($value, $needle);
        if ($res !== false) {
            return false;
        }
    }

Then trying to create a date object
try {
    new \DateTime((string) $value);
    return true;
} catch (\Exception $e) {

Full function:
public function isDate($value)
{
    if ($value instanceof \DateTimeInterface) {
        return true;
    }

    if ($value === false || $value === null || $value === '') {
        return false;
    }

    if (is_numeric($value)) {
        return false;
    }

    //protection for strtotime valid strings
    if (is_string($value)) {
        //1999-19-19 should pass
        if (strpos($value, '-') && !preg_match('/[0-9]-[0-9]/', $value)) {
            return false;
        }
        //2010-04-25 02:24:16+12:00 should pass
        if (strpos($value, '+') && !preg_match('/[0-9]+[0-9]/', $value)) {
            return false;
        }

        foreach (['day', 'month', 'year', 'next', 'last', 'previous', 'this', 'ago', 'week', 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'now'] as $needle) {
            $res = strpos($value, $needle);
            if ($res !== false) {
                return false;
            }
        }
    }

    try {
        new \DateTime((string) $value);
        return true;
    } catch (\Exception $e) {

    }

    return false;
}


text:
Q: Exploiting uniform syntax of value types and references Let's say we have the following Base class, and two derived classes Derived1 and Derived2:
class Base {
// Some declarations ...
};

class Derived1 : public Base {
// Some declarations ...
public:
  vector<int> _array;
};

class Derived2 : public Base {
// Some declarations ...
public:
  vector<int> &_array;
};

That is, we have a common class but the underlying data structures are of different types.
Say that we want to access individual elements of the underlying arrays using a uniform interface from a Base pointer. i.e. something like this:
Base *bPtr = new Derived1(...);
int val = bPtr->index(3);

Having a pure virtual function called index in Base is one solution. However, in that case we would need the same int index(uint x) { return _array[x]; }  implementation in both of the derived classes. This is ugly, and we cannot implement that function in Base since it does not know about _array.
So we must either (1) change the types of _arrays to the same type (say, to a vector<int>*) and have the implementation of index in Base or (2) have two implementations in Derived1 and Derived in order to make use of a common interface. However I cannot afford (1) since it would add an extra indirection layer to Derived1, and I want to avoid that if possible. Having a number of member variables like that makes (2) horrible since that is a lot of boilerplate and replication, and hard to maintain.
I understand that the two index functions are actually different functions, since they operate on different types. In many other scenarios Derived1 and Derived2 would need separate functions since they have different behaviour (and would be compiled to different object codes). However in the case of C++ the implementations are syntactically similar, so I'm wondering whether there is a way to exploit that.
One possible solution is having a free function:
template <class T>
int index(const T &obj, uint x) {
  return obj._array[x];
}

where we declare index a friend of both Derived1 and Derived2. However, this might not be considered elegant since it uses a friend declaration (also declaring friend twice is repetitive).
Hence, my question is:
Is there a more elegant way to implement index, while avoiding performance costs and code repetition?
Addendum:
CRTP is very close to what I want, but it introduces two new types (Base<Derived1> is the first, and Base<Derived2> is the second) while deleting the existing type Base. Such a refactoring would trigger many more changes in the codebase, which is not desirable (such as making functions/classes which utilize Base template functions/classes, or even moving them from headers to source files). What I want ideally wouldn't require making changes to the rest of the codebase.

A: Use CRTP.
template <typename D, typename B = Base>
class CrtpBase : public B
{
    public:
    int index(size_t ind){return static_cast<D*>(this)->_array[ind];}
};

struct Derived1 : public CrtpBase<Derived1>
{
    vector<int> _array = {1,2,3};
};

struct Derived2 : public CrtpBase<Derived2>
{
    vector<int> _arr = {4,5,6};
    vector<int>& _array = _arr;
};

DEMO.


text:
Q: Symfony2 Doctrine database into production Sorry if the question is one of a newb.
When I deliver my symfony2 website to my production webserver. I'm using a low cost hosting service. I cannot access mysql remotely ( only execute statement from their website through phpmyadmin ).
Case 1: Assuming I could access remotely, i should run:
php app/console doctrine:schema:create --env=prod

with appropriate database settings so it would update my db.
Case 2: Assuming I can't access remotely, then i have two option:

*

*I could create an ugly script that would call the above line from the website and remove it after delivery.

*I could get the sql statement printed to a file and execute it. Which seems better to me.

Question:

*

*Is there a pb with the above ?

*Is there a way to get an sql script in a file from:
php app/console doctrine:schema:create --env=prod

A: You can dump the sql statement using the --dump-sql option, and store it in a file:
php app/console doctrine:schema:create --dump-sql > statement.sql


text:
Q: GRUB Rescue During Windows 8.1 Clean Install I was trying to install windows 8.1 (upgrading from windows 7) on my laptop, and in the process remove my Ubuntu partition. During the setup I deleted all existing partitions (windows and ubuntu) and tried to install windows on Drive 0. The install goes fine until it needs to restart, at which point I'm sent to GRUB Rescue.
So far I've tried

*

*bootrec.exe /Fixmbr

*bootrec.exe /fixboot

*Using windows Startup Repair tool

*System Restore.

Am I going to need to reinstall Ubuntu to get this working properly?


text:
Q: Spark Streaming: Aggregating datastream multiple times I have a spark streaming job which reads the data from multiple kafka topics.
Now I want to aggregate data on multiple window intervals and save it to the database.
Is it possible to do this way? Or I will need a separate spark job to do another level of aggregation.
Would data be lost if dataset processed second time?
Aggregation 1:
private void buildStream1(Dataset<Row> sourceDataset) {
      Dataset<Row> query = sourceDataset
        .withWatermark("timestamp", "120 seconds")
        .select(
            col("timestamp"),
            col("datacenter"),
            col("platform")
        )
        .groupBy(
            functions.window(col("timestamp"), 120 seconds, 60 seconds).as("timestamp"),
            col("datacenter"),
            col("platform")
        )
        .agg(
            count(lit(1)).as("count")
        );
      startKafkaStream(query);
  }

Aggregation 2:
private void buildStream1(Dataset<Row> sourceDataset) {
      Dataset<Row> query = sourceDataset
        .withWatermark("timestamp", "10 minutes")
        .select(
            col("timestamp"),
            col("datacenter"),
            col("platform")
        )
        .groupBy(
            functions.window(col("timestamp"), 10 minutes, 5 minutes).as("timestamp"),
            col("datacenter"),
            col("platform")
        )
        .agg(
            count(lit(1)).as("count")
        );
      startKafkaStream(query);
  }

Write both streams:
private void startKafkaStream(Dataset<Row> aggregatedDataset) {
    aggregatedDataset
        .select(to_json(struct("*")).as("value"))
        .writeStream()
        .outputMode(OutputMode.Append())
        .option("truncate", false)
        .format("console")
        .trigger(Trigger.ProcessingTime(10 minutes))
        .start();
  }


text:
Q: How do I untab line (-1 tab)? I am looking for a sign that can untab a line:

*

*\t - tabs a line

*\n - new line

How do I untab a line (-1 tab)? Is there a way to do it?

A: There is no such special character to "untab" a line. If you want to modify a string and remove only one tab, you can do so with str.replace:
mystring = mystring.replace('\t', '', 1)


text:
Q: gwt client session time out I am using gwt 2.3 with gwtp framework.In this application I wan to maintain a session time of 5 mins.This means if current user is not doing up to 5 min and he comes after five min then on his first event/action on screen a he should be be logged out.
In gwt there is class named Timer which can be used in this issues.But I am not getting how to recognize action of user on the screen.I did google on it, & found the code for gwt-ext.Below is the code of gwt-ext
Ext.get("pagePanel").addListener("click", new EventCallback() {
    @Override
    public void execute(EventObject e) {
        MessageBox.alert("On Mouse Click");
    }
});

Ext.get("pagePanel").addListener("keydown", new EventCallback() {

    @Override
    public void execute(EventObject e) {
        MessageBox.alert("On Key Press Click");
    }
});

In above code tag in working properly so I am attaching link from where I got this code.here
Same type of code I am looking in gwt.If there any other better way to do this then please let me know. Thanks in advance

A: If action/event can be really everythin, I would solve it with a
NativePreviewHandler in the following way:
boolean expired;

final Timer logoutTimer = new Timer() {
    @Override
    public void run() {
        expired = true;
    }
};

NativePreviewHandler nph = new NativePreviewHandler() {

    @Override
    public void onPreviewNativeEvent(NativePreviewEvent event) {
        if (!expired) {
            logoutTimer.cancel();
            logoutTimer.schedule(300000);
        } else {
            // do your logout stuff here
        }
    }
};

Event.addNativePreviewHandler(nph);

If the user shell be logged out without a new action after 5 minutes:
final Timer logoutTimer = new Timer() {
    @Override
    public void run() {
        // do your logout stuff here
    }
};

NativePreviewHandler nph = new NativePreviewHandler() {

    @Override
    public void onPreviewNativeEvent(NativePreviewEvent event) {
        // Of course do this only when logged in:
        logoutTimer.cancel();
        logoutTimer.schedule(300000);
    }
};

Event.addNativePreviewHandler(nph);


text:
Q: Avro Json.ObjectWriter - "Not the Json schema" error I'm writing a tool to convert data from a homegrown format to Avro, JSON and Parquet, using Avro 1.8.0. Conversion to Avro and Parquet is working okay, but JSON conversion throws the following error:
Exception in thread "main" java.lang.RuntimeException: Not the Json schema:
{"type":"record","name":"Torperf","namespace":"converTor.torperf",
"fields":[{"name":"descriptor_type","type":"string","
[... rest of the schema omitted for brevity]

Irritatingly this is the schema that I passed along and which indeed I want the converter to use. I have no idea what Avro is complaining about.
This is the relevant snippet of my code:
//  parse the schema file
Schema.Parser parser = new Schema.Parser();
Schema mySchema;
//  tried two ways to load the schema
//  like this
File schemaFile = new File("myJsonSchema.avsc");
mySchema = parser.parse(schemaFile) ;
//  and also like Json.class loads it's schema
mySchema = parser.parse(Json.class.getResourceAsStream("myJsonSchema.avsc"));

//  initialize the writer
Json.ObjectWriter jsonDatumWriter = new Json.ObjectWriter();
jsonDatumWriter.setSchema(mySchema);
OutputStream out = new FileOutputStream(new File("output.avro"));
Encoder encoder = EncoderFactory.get().jsonEncoder(mySchema, out);

//  append a record created by way of a specific mapping
jsonDatumWriter.write(specificRecord, encoder);

I replaced myJsonSchema.avsc with the one returned from the exception without success (and except whitespace and linefeeds they are the same). Initializing the jsonEncoder with org.apache.avro.data.Json.SCHEMA instead of mySchema didn't change anything either. Replacing the schema passed to Json.ObjectWriter with org.apache.avro.data.Json.SCHEMA leads to a NullPointerException at org.apache.avro.data.Json.write(Json.java:183) (which is a deprecated method).
From staring at org.apache.avro.data.Json.java it seems to me like Avro is checking my record schema against it's own schema of a Json record (line 58) for equality (line 73).
58  SCHEMA = Schema.parse(Json.class.getResourceAsStream("/org/apache/avro/data/Json.avsc"));

72  public void setSchema(Schema schema) {
73    if(!Json.SCHEMA.equals(schema))
74      throw new RuntimeException("Not the Json schema: " + schema);
75  }

The referenced Json.avsc defines the field types of a record:
{"type": "record", "name": "Json", "namespace":"org.apache.avro.data",
 "fields": [
     {"name": "value",
      "type": [
          "long",
          "double",
          "string",
          "boolean",
          "null",
          {"type": "array", "items": "Json"},
          {"type": "map", "values": "Json"}
      ]
     }
 ]
}

equals is implemented in org.apache.avro.Schema, line 346:
  public boolean equals(Object o) {
    if(o == this) {
      return true;
    } else if(!(o instanceof Schema)) {
      return false;
    } else {
      Schema that = (Schema)o;
      return this.type != that.type?false:this.equalCachedHash(that) && this.props.equals(that.props);
    }
  }

I don't fully understand what's going on in the third check (especially  equalCachedHash()) but I only recognize checks for equality in a trivial way which doesn't make sense to me.
Also I can't find any examples or notes about usage of Avro's Json.ObjectWriter on the InterWebs. I wonder if I should go with the deprecated Json.Writer instead because there are at least a few code snippets online to learn and glean from.
The full source is available at https://github.com/tomlurge/converTor
Thanks,
Thomas

A: A little more debugging proofed that passing org.apache.avro.data.Json.SCHEMA to Json.ObjectWriter is indeed the right thing to do. The object I get back written to System.out prints the JSON object that I expect. The null pointer exception though did not go away.
Probably I would not have had to setSchema() of Json.ObjectWriter at all since omitting the command alltogether leads to the same NullPointerException.
I finally filed a bug with Avro and it turned out that in my code I was handing an object of type "specific" to ObjectWriter which it couldn't handle. It did return silently though and an error was thrown only at a later stage. That was fixed in Avro 1.8.1 - see https://issues.apache.org/jira/browse/AVRO-1807 for details.


text:
Q: How to disable MongoDB cache for specific collection? I'm running a MongoDB service and some of the collections are data store only and I don't want let MongoDB loads these collections' data into memory. Is there any configuration for that?

A: MongoDB does not load the collection into memory, only the collection's indexes.
By default index is _id field only. You can't remove the _id index.


text:
Q: To water mark videos at bottom right corner using ffmpeg I found some answer here in stack which is indeed using ffmpeg but it is giving me some error.
I ran it in command window and the error is quite like
"Unable to find a suitable output format for 'ΓÇôi'
ΓÇôi: Invalid argument".
my command is as follows
ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=(main_w-overlay_w-10)/2:(main_h-overlay_h-10)/2 [out]" outputvideo.mp4

please suggest some ideas.

A: You can try these out. Should work out for you.
/*
 * At top left watermark
 */
$mark = "ffmpeg -i ".$inputvideo." -i logo.png -filter_complex ". '"overlay=x=(main_w-overlay_w)/(main_w-overlay_w):y=(main_h-overlay_h)/(main_h-overlay_h)"'." ".uniqid()."topleft.mp4";

/*
 * At top right watermark
 */
$mark = "ffmpeg -i ".$inputvideo." -i logo.png -filter_complex ". '"overlay=x=(main_w-overlay_w):y=(main_h-overlay_h)/(main_h-overlay_h)"'." ".uniqid()."topright.mp4";

A: I tried with this command, and it worked for me. hope it will work for you as well.
$mark = "ffmpeg -i inputvideo.mp4 -i watermark.png -filter_complex  'overlay=x=(main_w-overlay_w):y=(main_h-overlay_h)' outputvideo.mp4";
exec($mark);

A: Basically overlay property defines where your watermark image will be posted -
main_w: video width
main_h: video height
overlay_w: overlay width
overlay_h: overlay height.

I guess this should work fine
 $mark = "ffmpeg -i ".$inputvideo." -i logo.png -filter_complex ". '"overlay=x=(main_w-overlay_w):y=(main_h-overlay_h)/(main_h-overlay_h)"'." ".uniqid()."topright.mp4";


text:
Q: to store the output of the command "head" in a variable in expect I have a huge file which has a version number of a particular bug.The version number is on the first line of the file so i use a "head filename" command.When I try to automate it using expect script,i.e.
set var [head filename.txt]

it throws an error saying invalid command name.When I try to do the other thing using expect_out,
send "head filename.txt\r"
expect -re {(n?)^V.*} {
set var $expect_out(0,string)
}

but this hasn't worked either.Can somebody help me resolve this issue?

A: This should work:
set var [exec head -1 filename.txt]

Alternatively, with no external programs needed:
set f [open filename.txt]
gets $f var
close $f

*

*you now have the first line of the file in $var.


text:
Q: how to run python script located on a remote server
*

*I have python script that I run on my cmd local machine.

*now I want to run it also on a remote server(Windows)
How can I do it?

A: It is possible using ssh. Python accepts hyphen(-) as argument to execute the standard input,
cat hello.py | ssh user@192.168.1.101 python -

Run python --help for more info.

A: You can use the ssh approach, but also the PSEXEC approach which is easier to use, although you may need admin privileges on the server to execute processes and both windows machines better share the same user/password.
Download PsExec from here
https://technet.microsoft.com/en-us/sysinternals/bb896649
Run as follows:
psexec /ACCEPTEULA \\servermachine python fullpath_to\python_script.py

fullpath_to\python_script.py should be accessible from the server. If not, you have to copy it first here, or just put the script on a shared/networked drive visible by both machines.
Of course python must be installed on the server as well.
I'm not saying it is the best way. Jenkins is a good way to run stuff on a given server. But it does the job.


text:
Q: Accessing values of a column that are greater than 33, but I also want to be able to access the ID of individuals who have their value greater than 33 I have a large dataset with a bunch of columns. I have one column titled (rowsums), that are the sums of values in a PTSD questionnaire ( greater than 33 is likely PTSD diagnosis). I want to be able to access rowsums that are greater than 33, while also accessing the respective ID's from the id column to find which participants have scored greater than 33 on a PTSD questionaire, and which ID's correspond to a PTSD diagnosis.
for example if column B has the ID's: N1, N2, N3, N4, N5, N6, etc.
And column M has the values: 20, 45, 21, 58, 12, 62
I use column M to imply that there are several other columns between B and M.

COLUMN A
COLUMN B
COLUMN M

1
N1
20

2
N2
45

3
N3
21

4
N4
58

5
N5
12

6
N6
62

I would to extract something that looks like this, returning only the values >33 along with the ID's in column B

COLUMN B
COLUMN M

N2
45

N4
58

N6
62

A: Here is the solution, with some simulated data as in the tables you provided (omitting COLUMN A since I did not get its purpose in the example):
set.seed(1986)

dta = data.frame("columnB" = 1:10, "columnM" = rnorm(10, mean = 33, sd = 2))
your.aim = dta[dta$columnM > 33, ]

Basically, I am just subsetting the original data set dta by choosing only observations featuring a value for columnM (your PTSD rowsums) strictly greater than 33.


text:
Q: Calculate Pitch and Roll and YAW by 4 points detected from a square in Opencv I have a rectangle picture like this image :

But after that I took a photo from the camera like this :

I detected 4 corners of my rectangle by approxPolyDP.
The points that I detected are these values:
308,25
38,99
147,477
412,466

Now how can I calculate Pitch, Roll and Yaw by these 4 points?

A: See How to calculate perspective transform for OpenCV from rotation angles?. You would have to work backwards from that solution.
Getting the transformation matrix is the easy part using getPerspectiveTransform. Figuring out the pitch, roll, and yaw from that matrix would be solving for angles in the single rotation matrix written here: http://planning.cs.uiuc.edu/node102.html for the respective Euler angles.


text:
Q: How can I get every steps of Distributed test logs in Master machine? In jmeter webdriver sampler I am printing some logs. When I run as a simple test it creates logs. But if run as distributed test required logs are not generating, only the logs related to Distributed testing is generated but not what I am printing using webdriver sampler.
2017-11-27 12:09:31,733 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2017-11-27 12:09:31,733 INFO o.a.j.t.JMeterThread: Thread started: FacebookThread 1-1
2017-11-27 12:09:56,630 INFO c.g.j.p.w.s.WebDriverSampler: Actions:login,UserDetails
2017-11-27 12:09:56,632 INFO c.g.j.p.w.s.WebDriverSampler: Timing:11687,203
2017-11-27 12:10:02,312 INFO o.a.j.t.JMeterThread: Thread is done: FacebookThread 1-1
2017-11-27 12:10:02,313 INFO o.a.j.t.JMeterThread: Thread finished: FacebookThread 1-1
2017-11-27 12:10:03,261 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2017-11-27 12:10:03,261 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

But if run it the same test in distributed mode the logs are
2017-11-27 12:12:14,490 INFO o.a.j.e.ClientJMeterEngine: sent test to 192.168.0.5 basedir='.'
2017-11-27 12:12:14,490 INFO o.a.j.e.ClientJMeterEngine: Sending properties {}
2017-11-27 12:12:14,490 INFO o.a.j.e.ClientJMeterEngine: sent run command to 192.168.0.5
2017-11-27 12:12:14,490 INFO o.a.j.e.DistributedRunner: Remote engines have been started
2017-11-27 12:12:14,490 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, 192.168.0.5)
2017-11-27 12:12:42,113 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, 192.168.0.5)

I need to have every step of logs in distributed testing also.
Thank you.

A: Instead of printing values into jmeter.log file I would recommend saving them into JMeter Variables like

*

*In the WebDriver Sampler:
var vars = org.apache.jmeter.threads.JMeterContextService.getContext().getVariables()
vars.put('Actions', 'login,UserDetails') // or whatever relevant action name
vars.put('Timing', '11687,203')

*In the user.properties:
sample_variables=Actions,Timing

Once you run your test you will see 2 extra columns in the .jtl result file having values for Actions and Timing JMeter Variables for each and every sampler.
More information:

*

*Sample Variables

*Configuring JMeter

*The WebDriver Sampler: Your Top 10 Questions Answered

A: The logs related to distributed testing in jmeter will be 2 types. one is jmeter.log which will be created in the single system where we are runnnig the test. but one more log jmeter-server.log will be created in jmeter server systems. you go to bin folder of each system and find jmeter-server.log
If test runs for long time or it is long test your logs will be deleted due to log file configuration. so better idea is have a code in where in it prints the output to a external file which is a better option to track the data.
Thank you.


text:
Q: Proxy error while running vue js and the local API server Proxy error: Could not proxy request //tasks from localhost:8080 to http://localhost:5000/.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).


text:
Q: Which events should I use in Magento? I want to send a mail when a new product is added depending on some criteria.
Where should I put my code so when a product is saved I can:

*

*Get it and its attribute to work with

*Send an email to some customer

Thanks in advance.

A: Magento already includes this functionality in the Mage_ProductAlert functionality.  You could extend that module to take consideration of your extra criteria.  It hooks into the cron system rather than a synchronous call to an Observer which is a much better performance model.

A: You might want to checkout catalog_product_new_action.  Never used it, but it might work for you.  Not sure if it works on duplicating a product.  I have used another event, catalog_product_save_before catalog_product_before_save, which is fired anytime a product is saved.  (use google to search for magento event cheat sheets).  But with both you can get the product in your observer function with
$product = $observer->getEvent()->getProduct();

Then you can get the attribute from the product.
$product->getMyAttribute()

where my_attribute is the attribute you are after.
Sending the email should be simple enough with php's mail() function.  If you want to get all complicated you can use Magento's way of sending transactional emails, but likely you won't need that unless you need it to translatable, etc.


text:
Q: How to show a linear transformation onto/one-to-one? It has already been given that:
$$T\colon P_3\to P_4 \qquad T(p)=(x+2)p(x)$$
$$H\colon P_4\to P_3 \qquad H(p)=p'(x)+p'(0)$$
It is asked to show that $T$ is one-to-one but not onto, and that $H$ is onto but not one-to-one.
How can I show that?

A: Just use the definition to check that $T$ is one-to-one. To show that $T$ is not onto, note that for any $0\neq p(x)\in P_3$, $T(p(x))=(x+2)p(x)$ which is a polynomial having degree at least one. Therefore, for any degree zero polynomial $q(x)$, namely the constant, there does not exists any $p(x)\in P_3$ such that $T(p(x))=q(x)$.
Use the definition to check that $H$ is onto. To do it, you need to solve some linear equations. To show that $H$ is not one-to-one, just note that for any degree zero polynomials $p(x)$, we have $H(p(x))=p'(x)+p'(0)=0$.


text:
Q: cant logout of website with c# webbrowser I am trying to use c# webbrowser control to view mobile version of twitter. I have a button in my windows form which is meant to log me out of the site but i cannot get it to work.
here is the immediate html code:

span class="w-button-common w-button"> input name="commit"
  type="submit" value="Sign out" /

i have tried:
webBrowser1.Document.Forms[0].InvokeMember("submit");
but there are a few buttons with type="submit" on the page.
How do i get it to click the right one?
if you would like me to provide the full source of the page then please ask :)

A: In the past I used the WebBrowser control to interact directly with the DOM using javascript calls like this:
browser.Navigate(string.Format(@"javascript:void({0})", jsAction));

Of course I know you already did something like this with InvokeMemeber() but since I have no further experience with the WebBrowser interface I can just talk about what I've said before. Using javascript I could achieve any result a real user could. With the method I described you may try, in a javascript context, to enumerate the controls you are trying to address and then call the .click function.

A: Mhh try it with the normal click Methode.
Get a HtmlElementCollection with
HtmlElementCollection collection = webBrowser1.Document.getElementsByTagName("select");
Look through it in Debug Mode, until you know which one is your button.
Than perform the click with:
collection[x(whereever your button is)].InvokeMember("click");


text:
Q: Casting an object to a generic type without supplying the parameters Say I have a code like this
let a = new List<int>()
let b = a :> obj :?> List<obj>

It throws an exception saying that it can't do it since one is List<int> while I'm trying to make it an List<obj>.
I understand why that's a problem. It can't just magically create an interface for me that replaces all int types with obj, but what CAN I do here?
I have an object and I know that's it's a List of something. How can I access the elements and just not care about their type?
My concrete example doesn't use Lists so I require a general, not a List specific, solution.

A: In case of lists you can use System.Collections.IList to access elements
open System.Collections
open System.Collections.Generic

let x = List<int>()
let y: IList = downcast (x :> obj)

This approach can also be generalized: make your generic classes implement non-generic interface:
type IT =
    abstract Value: obj

type T<'a>(a: 'a) =
    member val Value = a;
    interface IT with
        member this.Value = upcast this.Value

If this is not an option (i.e. because you cannot make changes in classes) you can always resort to reflection
type T<'a>(a: 'a) =
    member val Value = a;

type Action =
    static member Do(a: T<_>) = printfn "%A" a.Value

let v = T(10)
let mi = typeof<Action>.GetMethod("Do").MakeGenericMethod(v.GetType().GetGenericArguments().[0])
mi.Invoke(null, [|v|])


text:
Q: Using a Java library with Scala reserved words I'm using an external library written in Java (Selenium). One of the function calls has the signature type(String, String), and I keep getting compiler errors when trying to call it from Scala, that is:
selenium.type("ab","abc")

Is there a workaround for this issue?

A: selenium.`type`("ab","abc")


text:
Q: Exclude commits from Git hooks? Is it possible to exclude certain commits from being pushed to a service hook on Github? For example, if I only edit the Readme file of a project, it makes no sense to re-test the entire application on Travis. Is there a way I can tell Git that that particular commit should not be sent to the Travis hook?

A: There isn't a way to tell git push to skip hooks. You could, however, modify the hook to examine the received commit and only run the tests if a source file has been modified. How you do that depends on your project, but it could look for files with a certain extension, files in the src/ directory, etc.

A: To answer the Travis-related part: As explained in the Travis docs you can skip a build if you append [ci skip] to any of the commits you're going to push.