text:
Q: Differences between CKAN and GeoNode in spatial data infrastructures We are planning to develop a spatial data infrastructure with some webGIS tools integrated. It would serve much vector and satellite data in numerous users. Until now, we are planning to create a project based on GeoNode because we are familiar with the platform and its components (Django, Geoserver, Postgresql, Pycsw etc). But during our research in large open data projects we realize that CKAN dominates as open data platform. Also last years it has been developed many extensions for geospatial world. So we are in a dilemma.
What are the differences between them and which is more suitable for large geospatial projects ?
At one hand we have a data management system (with spatial extensions)(CKAN) and on the other hand, a geospatial content management system (a complete package of geospatial components)(GeoNode).
I know that CKAN can harvest from GeoNode and we can use both but at first I'd like to learn about the differences between them.

A: We use CKAN as frontend for open geodata. As the backend we use Web GIS based on http://nextgis.com service.
The example of such integration was Primorsky Kray Open geodata portal (http://docs.nextgis.ru/docs_ogportal/source/user.html). Sorry the text is in Russian, but you can google translate it.
CKAN is great tool for open geodata but rather complicated user interface. To get spatial functionality (geodata preview on map or table) you need to install several extensions.
CKAN have nice API to share metadata with other catalogs and search systems. Also there is nice plugin in QGIS (https://plugins.qgis.org/plugins/CKANBrowser/).


text:
Q: Find basis for irreps I have six-dimensional (complex) matrices which span a representation of $S_4$ that decomposes into the two three-dimensional irreducible representations of the group. I would like to find out the basis vectors such that my representation matrices will be block-diagonal, however I am failing to do so … Is there a trick or algorithm one could use?
Thanks!

A: You could compute the matrices $M_\chi=\frac{1}{24}\sum_{g \in S^4} \chi(1)\chi(g^{-1})M_g$ which correspond to the primitive central idempotents of the two representations. These will turn out to be projection maps to the two three-dimensional irreducible components, from which you can get the basis vectors you want.
I don't know how numerically stable all of this will be, though. It should work in the general case, but if the two components turn out to be nearly parallel you may need to work harder.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Haskell Accelerate replicate matrix How can I replicate matrix in Haskell Accelerate?
For example, I have a matrix mat :: Matrix (Z :. 2 :. 5) .... I want to get a three-dimensional array with shape Z :. 9 :. 2 :. 5.
I tried to use A.replicate (A.lift (Z :. 9 :. All)) mat, but I get an error

Couldn't match type 'Z' with 'DIM0 :. Int'
Expected type: Acc (Array (SliceShape ((Z :. Int) :. All)) a)
Actual type: Acc (Matrix a)

What does that mean?
And similarly, if I have a matrix with shape Z :. 9 :. 5, how can I get a three-dimensional array with shape Z :. 9 :. 2 :. 5?

A: The problem is that the slice needs to have the same rank (number of dimensions) as the input array. All does not mean 'all the rest of the dimensions', but it only means 'all the elements in this dimension'. So you can solve your issue with:
A.replicate (A.lift (Z :. 9 :. All :. All)) mat

This also gives some intuition about how you might answer your second question:
A.replicate (A.lift (Z :. All :. 2 :. All)) mat

I don't know if there is a way to say 'all the rest of the dimensions'.
The error message Couldn't match type 'Z' with 'DIM0 :. Int' means that the rank of your shape is not correct. You need to add another dimension. Maybe it would be easier to read if it said: Couldn't match type 'Z' with 'Z :. Int'.


text:
Q: Insert or update query executed successfully but data are not persistent I'm trying to insert or update elements in an existing Firebird database using JDBC. I access the database with the default credentials (SYSDBA and masterkey).
The request are done successfully according to JDBC, but the database is not modified (when I execute a select my data does not appear). I also tried to modify the database content using software like RazorSQL, the result is the same (the database is modified during the session, but if I disconnect and reconnect to the database my modifications are lost).
Does anybody have an idea how to solve this problem?

A: Most likely you are running with autoCommit disabled. In that case you need to explicitly call commit() on the Connection. Also be aware that a transaction can only see changes from transactions that were committed before it started.
See also the Jaybird JDBC Driver Java Programmer's Manual, chapter "Using transactions".


text:
Q: OAuth 2.0 (or similar) without security token This article about oAuth 2.0 says , that user must provide security token to log in.
Can i somehow disable usage of security tokens? I don't want my users to perform unnecessary operation.
Or may be there is some alternative way to find out , if user's login\password are valid in salesforce
My code to authorize (may be there is another issue why i have an error like
{"error_description":"expired access/refresh token","error":"invalid_grant"}  )
    private const string ClientId = "3MVG9A2kN3Bn17huRprJBCInrodPdsyHERlP1nUDPXnApOiQURGxtr9pxl...."; // Consumer Key from SFDC account
    private const string ClientSecret = "43802039754906815..."; // Consumer Secret from SFDC account
    private const string RedirectUrl = "https://localhost:8443/...."; // Redirect URL configured in SFDC account
    private const string  SfOAuthUrl = "https://login.salesforce.com/services/oauth2/token";

public static void AuthenticateToSalesforce()
    {
        var username = "myMail@gmail.com";
        var password = "MyPassword_Without_Security toke";

        var parameters = "grant_type=password"
                                  + "&client_id=" + ClientId
                                  + "&client_secret=" + ClientSecret
                                  + "&redirect_uri=" + RedirectUrl
                                  + "&username=" + username
                                  + "&password=" + password;

        var result = HttpPost(@SfOAuthUrl, @parameters);
    }

    public static string HttpPost(string URI, string Parameters)
    {
        var req = WebRequest.Create(URI);
        req.ContentType = "application/x-www-form-urlencoded";
        req.Method = "POST";

        var data = Encoding.ASCII.GetBytes(Parameters);
        req.ContentLength = data.Length;
        var os = req.GetRequestStream();
        os.Write(data, 0, data.Length);
        os.Close();

        try
        {
            var resp = req.GetResponse();
            var sr = new StreamReader(resp.GetResponseStream());
            return sr.ReadToEnd().Trim();
        }
        catch (WebException ex)
        {
            var resp = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
            Console.WriteLine(resp);
        }
        return string.Empty;
    }

I've also set the range of trusted IPs which, according to the article, should disable usage of security tokens, but error is still the same

A: Security Tokens are not required from Trusted IP addresses.
You can make a single range of IP address 'trusted' in Setup > Security Controls > Network Access.
You can blat out multiple ranges like 0.0.0.0 to 255.255.255.255 (not recommended) on a Profile too.
Keith C's commentary is well placed; holding user credentials (and security token) may be a red flag.

A: The token's only required if you use user/pass flow, which is not recommended for normal, production-ready OAuth2 implementations (it's the same as trying to make a SOAP login() call). Instead, use the user-client flow, which follows the normal Identity Confirmation flow (e.g. a SMS or email verification code). In C#, for example, you can use a WebBrowser control to present the OAuth2 login. If the user's default browser is Internet Explorer, and they are already logged in through another window, and they've already granted access, the login will complete automatically with no interaction from the user at all.


text:
Q: How to populate a tree in KendoUI? I am currently using the code:
@foreach (var table in Model.TableData)
{
    foreach(var field in table.Fields)
    {
        var tableName = table.TableName;
        var fieldName = field;

        @(Html.Kendo().TreeView().Name("DatabaseTables").DragAndDrop(true)

        .Items(treeview =>
          {
              treeview.Add().Text(tableName).Expanded(false).Items(fields =>
              {
                  fields.Add().Text(fieldName);
              });
          }))
    }
}

This is supposed to create a node for each table, and populate it with the fields but is obviously creating one tree per field in the table.

A: The trouble is your nesting. I typically don't use the html helpers, however I believe the correct use would look like the following.
    @(Html.Kendo().TreeView().Name("DatabaseTables").DragAndDrop(true)

    .Items(treeview =>
      {
          foreach (var table in Model.TableData)
           {
            var tableName = table.TableName;
            treeview.Add().Text(tableName).Expanded(false).Items(branch=>
            {
            foreach(var field in table.Fields)
              {
                var fieldName = field;
                 branch.Items(fields =>
                 {
                 fields.Add().Text(fieldName);
                 });
           }});}
      }))

Your treeview creation is in your for loop and it needs to be on the outside, otherwise you will generate duplicate trees for each iteration.


text:
Q: How can I add in the variable a pre-configured "valid from" and "valid until" date? I have been playing around with using GraphQL and I want to introduce to the variable two fields:
a) one that is "valid from" and is the current time/date
b) and one for "valid until" which is one month after the current time/date. In a hardcoded way it should have been something like that:
{ "variable": {
     "valid_from": "2022-05-22T07:51:38.36"
     "valid_until": "2022-06-22T07:51:38.36"

How can I make this dynamic?


text:
Q: Facebook JS SDK Log in to another account I've been scratching my head for the past day trying to solve this one, and cant seem to find anything on the internet related to this relative common use case.
I have an app built using React(JavaScript) and I am making use of Facebook's JavaScript SDK to bring in Facebook authentication to one of my pages.
The issue I'm having is around this specific scenario whereby a person logs into Facebook, then logs into your app. Upon calling FB.login from my app it doesn't ask the user for any details and automatically logs him in, upon calling FB.logout from your app, the person is still logged into Facebook.
I want to be able to give the ability to my user to essentially switch to a different account from my app, so if the user is logged into his personal Facebook account upon calling FB.login from the app rather than it automatically taking his personal account the user will have the ability to enter in the details to another account, or at least when calling FB.logout rather than just invalidating the access token in the current app it will force logout the user from Facebook so that on FB.login this time he will be promoted for login details.
Any idea on how this can be accomplished with the Facebook SDK?
Thanks
James

A: You can remove permissions FB.api('/me/permissions', 'delete', function(response) {}); and if after that you will login again then you will have the posibility to switch the facebook account. enter image description here But you will loose the access token for current account.


text:
Q: Docker swarm scale I have a cluster built with docker-swarm in which we run apache spark apps. In the cluster, I have a manager node and 3 worker nodes.In this cluster, we have a master container for spark and a lot of worker containers. I can scale the number of worker nodes by using following command.
sudo docker service scale spark_worker=<number of workers>

When I increase the number of worker, I want to create new containers on worker node not on manager node.

A: Two options:

*

*docker node update --availability=drain <nodename> this will stop containers on the node and start them somewhere else, and prevent future containers from running on that node. Note that pause only prevents new containers on that node, and doesn't move existing ones.
However, that method is quite limited. If you ever wanted to run anything on the manager like monitoring, logging, management GUI's, etc. you wouldn't be able to.

*A more flexible method is to update the existing service to only run on worker nodes: docker service update --constraint-add 'node.role==worker' <servicename>. Then later if you wanted to run a service just on managers you could use node.role==manager on it.

A: There is opportunity to specify replicas property inside deploy section.
So scale argument is not allowed. So one of  my services in  docker-compose.yml looks like this:
xxx_nginx:
  image: nginx
  tty: true
  command: ["sh", "-c", "usermod -u 1000 nginx && nginx -g 'daemon off;'"]
  volumes:
    - "/home/pi/images:/usr/share/nginx/html:ro"
    - "/var/log/nginx:/var/log/nginx"
    - "/etc/localtime:/etc/localtime:ro"
  deploy:
    replicas: 2
    placement:
      constraints:
        - "node.hostname==raspberrypi151"

So now I dont have to scale each time my service.


text:
Q: Running grunt "concurrent:test" Aborted due to warnings I'm using a Yeoman angular generator and when I run this code I get grunt exiting with a warning. I'm running inside debian wheezy and have run these commands before running grunt:
sudo apt-get install ruby           &&
sudo gem install sass compass       &&
npm install                         &&
sudo npm install -g grunt-cli       &&
sudo npm install -g bower           &&

gruntfile.js:
 grunt.registerTask('test', [
    'clean:server',
    'concurrent:test',
    'autoprefixer',
    'connect:test',
    'karma'
  ]);

 test: {
        options: {
          port: 9001,
          base: [
            '.tmp',
            'test',
            '<%= yeoman.app %>'
          ]
        }
      },

Warning:
Running "concurrent:test" (concurrent) task
    Warning:  Use --force to continue.

        Aborted due to warnings.

Execution Time (2014-04-02 13:58:03 UTC)
concurrent:test  1.1s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 99%
Total 1.1s
Process finished with exit code 6

A: Grunt exit code 6 is less than helpful, but the real point it is trying to tell you is that your tests had warnings (read: problems) in them and you should look at them. I would also suggest turning on JSHint or JSLint in your IDE and see what it comes up with. Running tests on a fresh install should work right out of the box, and having them failing is usually a sign of bad configuration, so check that too. Lastly, you might try re-installing Yeoman and making sure that every module installs without a problem.

A: I just experienced this as well.
After reading this thread I looked into my grunt file and found that concurrent:test was running compass.
I ran 'grunt compass' and saw a better error message.


text:
Q: CGI script not running on server I am learning to work with the cgi package on python and for that purpose I have created the following script:
#!/usr/bin/env python
import cgi

print("<title>HeyHey</title>")

print("")
print("
This is an example web server.
")
print("")

The script is saved as server.py in /var/www/cgi-bin.
The output of ls -l is the following:
-rwxr-xr-x 1 vagrant vagrant 170 Apr 21 08:18 server.py

So then I start my server with the following command:
sudo python3 -m http.server --cgi

And when I open the page by going to 0.0.0.0:8000/server.py the code is not being executed instead it is just shown.
Any ideas what am I doing wrong?
P.S: I am working on Debian.

A: Are you sure you have configured httpd.conf file properly in ordert to execute CGI so it looks something like this?
<Directory "/var/www/cgi-bin">
   AllowOverride None
   Options ExecCGI
   Order allow,deny
   Allow from all
</Directory>

<Directory "/var/www/cgi-bin">
Options All
</Directory>

You can also follow the steps mentioned here -> https://www.knowledgehut.com/tutorials/python-tutorial/python-cgi


text:
Q: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils As am working on WildFly 8, am getting an error like
java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils
Log:
{"JBAS014671: Failed services" => {"jboss.undertow.deployment.default-server.default-host./Sample" => "org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./Sample: Failed to start service
    Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils
    Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils
    Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.core.io.support.VfsPatternUtils"}}

This is applicationContext.xml file Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:c="http://www.springframework.org/schema/c"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:flow="http://www.springframework.org/schema/webflow-config"`
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:jms="http://www.springframework.org/schema/jms"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xmlns:osgi="http://www.springframework.org/schema/osgi"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
          http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
          http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-4.0.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.0.xsd
          http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
    <context:annotation-config/>
    <context:component-scan base-package="com.rss.master" use-default-filters="false">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
    </context:component-scan>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@localhost:1521:XE"/>
        <property name="username" value="RSS"/>
        <property name="password" value="12345"/>
    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource"/>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="format_sql">true</prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>hbm/ExRateMaster.hbm.xml</value>
            </list>
        </property>
    </bean>
    <bean id="exRateMasterDao" class="com.rss.master.dao.impl.ExRateMasterDaoImpl">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="exRateMasterBo" class="com.rss.master.bo.impl.ExRateMasterBoImpl">
        <property name="exRateMasterDao" ref="exRateMasterDao"/>
    </bean>
</beans>


text:
Q: Why my ionic app FCMPlugin.onNotification() does not get called for incoming push notifications I'm using cordova-plugin-fcm for handling push notification subscriptions and watching for incoming notifications.
This was all working when I set it up about a month ago. I still receive push notifications when the app is closed or in the background.
But if the app is in the foreground I get no notification. Which is actually fine because I was handling that with FCMPlugin.onNotification callback when everything was working.
And FCMPlugin.onNotification callback, success or error in my $ionPlatform.ready() never run no matter the state of the app.
Subscribe factory - Used in Rooms factory
myApp.factory('pushSubscribe', [
  '$firebaseArray',
  function ($firebaseArray) {
  return $firebaseArray.$extend({
    $$added: function(room){
      // Room topic is the $id of the chat room
      FCMPlugin.subscribeToTopic(room.key,
        function(success){
          //Success is being ran here with "OK" response
          //when a new chat room is added
        },
        function(error){
          // Not seeing any errors here
        }
      );
    },
    $$removed: function(room){
      FCMPlugin.unsubscribeFromTopic(room.key);
    }
  });
}]);

Rooms factory - registers chatters for push notifications
myApp.factory('Rooms', [
  '$firebaseArray',
  '$firebaseObject',
  'userService',
  'pushSubscribe',
  function ($firebaseArray, $firebaseObject, userService, pushSubscribe) {
  var ref = firebase.database().ref(),
      user = userService.getUser();
      userRoomsRef = firebase.database().ref('user-rooms').child(user.$id),
      roomsRef = firebase.database().ref('/rooms'),
      userRoom = new pushSubscribe(userRoomsRef);// Subscribes the current user to push notifications for all of their user-rooms
  return {
  // CRUD methods for rooms here
  }
}]);

app.js .run() - Supposed to listen for incoming notifications and handle them according to the state of the app but it isn't.
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
     FCMPlugin.onNotification(
       function(data){ //callback
         if(data.wasTapped){
           //Notification was received on device tray and tapped by the user.
           console.log( JSON.stringify(data) );
         } else {
           //Notification was received in foreground. Maybe the user needs to be notified.
           console.log( JSON.stringify(data) );
         }
       },
       function(msg){ //success handler
         console.log('onNotification callback successfully registered: ' + msg);
       },
       function(err){ //error handler
         console.log('Error registering onNotification callback: ' + err);
       }
     );
   });

node-gcm push router - Hosted on Heroku all chats hit routers url
var router = require('express').Router();
var firebase = require('firebase');
var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
var gcm = require('node-gcm');
var sender = new gcm.Sender('MY_AUTH_TOKEN');

router.get('/', function(req, res){
  res.status(200).json({ message: 'GET route on router'});
});

router.post('/', jsonParser, function(req, res){
  firebase.auth().verifyIdToken(req.body.token)
  .then(function(user){
    var message = new gcm.Message({
      priority: 'high',
      notification: {
        click_action: "FCM_PLUGIN_ACTIVITY",
        title: req.body.sender_name,
        body: req.body.message
      },
      data: {
        state: req.body.state,
        roomId: req.body.roomId,
        sender_imgUrl: req.body.sender_imgURL
      }
    });
    sender.send(message, { topic: req.body.topic }, function(err, response){
      if(err){
        res.status(500).json({ error: err });
      } else {
        res.status(200).json({ response: 'Push notification sent' });
      }
    });
  })
  .catch(function(err){
    res.status(500).json({ response: err });
  });
});

module.exports = router;

The send message method
$scope.sendMessage = function() {
        // Get the users auth jwt to verify them on the node router
        firebase.auth().currentUser.getToken(true)
        .then(function(userToken){
            $http({
                method: 'POST',
                url:'MY_HEROKU_HOSTED_NODE_ROUTER_URL',
                data:{
                    token: userToken,
                    message: $scope.IM.textMessage,
                    sender_name: $scope.user.name,
                    topic: '/topics/' + $state.params.roomId,
                    state: 'app.room',
                    roomId: $state.params.roomId,
                    sender_imgURL: $scope.user.pic,
                    chatters: chatters
                }
            })
            .then(function(res){
                //Chats factory updates Firebase chat record
                Chats.send($scope.user, $scope.IM.textMessage);
                $scope.IM.textMessage = "";
            })
            .catch(function(err){
                debugger;
            });
        });
    };


text:
Q: Как реализовать метод? У меня есть HashSet<Region>. Хочу определить принадлежит ли текущий регион тем, что лежит в сете. Делаю это вот так:
    HashSet<Region> reg = new HashSet<Region>();
    Region r1 = new Region();
    r1.setValue(Region.Regions.region1);
    Region r2 = new Region();
    r2.setValue(Region.Regions.region2);
    reg.add(r1);
    reg.add(r2);

    Region r = new Region();
    r.setValue(Region.Regions.region1);

    out.println(reg.contains(r));

Почему то выдает false. В чем проблема?
Вот как реализован класс Region
public class Region {

private Regions value;

public Regions getValue() {
    return value;
}

public void setValue(Regions value) {
    this.value = value;
}

static enum Regions {
    region1("region - 1"),
    region2("region - 2"),
    region3("region - 3"),
    region4("region - 4");

    private String value;

    Regions(String value) {
        this.value = value;
    }
    public String toString() {
        return value;
    }
}

}
A: У класса Region необходимо переопределить метод equals(), который наследуется от класса Object. Именно он используется для сравнения объектов при поиске.
Внутри него объекты должны сравниваться по значениям полей или каким-либо другим свойствам (в вашем случае, достаточно сравнить value, я думаю)


text:
Q: Keeping all versions of a row, marking only one as current I am new to SQL and trying to achieve something.
I have a table having fields like:

CustId   Fname   Lname    Address1    Address2  Zip    State  LoadDate   Flag
1        John     Leo      xxx        xxx       34532    VA    1/1/2012   Y
2        Mike     Saunder  xxx        xxx       94090    CA    1/1/2012   Y

Everytime I insert a new record it will set its flag to Y but lets say if any of the record value changes then new one will be set to Flag Y and old one to N. So for example if Mikes address1 is changed.

CustId   Fname   Lname    Address1    Address2  Zip    State  LoadDate   Flag
1        John     Leo      xxx        xxx       34532    VA    1/1/2012   Y
2        Mike     Saunder  xxx        xxx       94090    CA    1/1/2012   N
3        Mike     Saunder  rrr        xxx       94090    CA    2/1/2012   Y

A: Assuming that you're trying to say that the Fname/Lname pair is a unique key that lets you match rows:
declare @Folks as table ( CustId int, Fname varchar(10), Lname varchar(10),
  Address1 varchar(10), Address2 varchar(10),
  Zip varchar(9), State varchar(2), LoadDate date, Flag char(1) )
insert into @Folks ( CustId, Fname, Lname, Address1, Address2, Zip, State, LoadDate, Flag ) values
  ( 1, 'John', 'Leo', 'xxx', 'xxx', '34532', 'VA', '1/1/2012', '-' ),
  ( 2, 'Mike', 'Saunder', 'xxx', 'xxx', '94090', 'CA', '1/1/2012', '-' ),
  ( 3, 'Mike', 'Saunder', 'rrr', 'xxx', '94090', 'CA', '2/1/2012', '-' )

-- Before setting the Flag.
select * from @Folks

-- Computing a flying flag rather than using a stored value.
select *, case when LoadDate = ( select MAX(LoadDate) from @Folks as S where S.Fname = O.Fname and S.Lname = O.Lname ) then 'Y' else 'N' end as 'FlyingFlag'
  from @Folks as O

-- Updating all stored values.  Every bloody row.
update @Folks
  set Flag = case when LoadDate = ( select MAX(LoadDate) from @Folks as S where S.Fname = O.Fname and S.Lname = O.Lname ) then 'Y' else 'N' end
  from @Folks as O

-- Showing the result.
select * from @Folks

EDIT:
I still think this is not the direction you want to be heading.  For example, it doesn't gracefully accomodate more than one update per customer per day unless you rely on the CustId to be a tie breaker.
A marginally better solution would be to replace Flag with a PreviousId field that is NULL in the first row for a customer and in later rows contains the CustId of the row that is being superseded.  That links together the changes for each customer and provides a well defined order in the event that a customer is updated repeatedly on a single date.

A: I'm assuming that custid is an identity column that auto increments.
update table set flag="N" where CustId= (insert Mike's current CustId here);

then
insert into table(Fname, Lname, Address1, Address2, Zip, State, LoadDate, Flag)
values(Mike, Saunder, rrr, xxx, 94090, CA, 2/1/2012, Y);


text:
Q: What are the uses for the carry flag and the overflow flag in the EFLAGS register? The EFLAGS register have a carry flag and an overflow flag, I am wondering what are the uses for these flags.
I can think of the following uses:

*

*If I am adding two unsigned integers, and I want to know if the
addition was successful (that is, the the result fitted in the specified register/memory), then I would check if the carry flag is set
(if it is not set, then the addition was successful).

*If I am adding two signed (two's complement) numbers, and I want to
know if the addition was successful (that is, the the result fitted in the specified register/memory without overflowing the sign bit), then I would check if the
overflow flag is set (if it is not set, then the addition was
successful).
Are these uses correct? and are there any other uses?

A: The flags are the only ways to control condition instructions which are, conditional jumps (jCC) and conditional moves (cmovCC and fcmovCC). Thus, whenever you want to make a choice depending on some condition like

*

*are two numbers equal?

*is one number larger than the other?

*is a number zero?

*is a certain bit set in a number?

*is the number's parity even or odd?

You need the flags register. For this purpose, the cmp instruction exists. It subtracts its operands, discards the result and sets the flags. This way, you can compare numbers and do something according to the result. See this table for how the order of two numbers affects the flags.
Lastly, you can also use the flags (especially the carry flag) to do large number addition. This is facilitated using the adc and sbb instructions which carry over the carry or borrow from lesser digits to higher digits.


text:
Q: Can't access static resources with Spring Boot According to the Spring Boot documentation, resources located in the static folder will be served up automatically by Spring Boot with no additional configuration or request mapping.
I am trying to access a javascript file by going to http://localhost:8080/js/filter.js

Here is a screenshot of that section of that part of the Spring documentation.

Here is a screenshot of my current resources directory structure.

Here is my pom.xml to show that I'm using the latest Spring Boot release.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>velocity-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>velocity-demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Here is my Application class
package com.example

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class VelocityDemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(VelocityDemoApplication.class, args);
    }

}

A: In my controller I changed @PostMapping to @PostMapping("/foo") and now I can get all of my resources. It was essentially blocking all my requests.
I'll leave this question up, unless of course it gets deleted, because I never would have thought that the controller being configured that way would be blocking all other requests. Someone else may have this issue one day.
@RestController
public class MainController {

    TemplateService templateService;

    public MainController(TemplateService templateService) {
        this.templateService = templateService;
    }

    @GetMapping("/")
    public String getIndex() {
        return templateService.getTemplate("index.vm");
    }

    @PostMapping("/updateFilter") // was @PostMapping
    public String updateFilter() {
        System.out.println("updating filter");
        return "success";
    }
}


text:
Q: Looping through images in jQuery Sorry, but I am a newbie in programming jQuery. I have a page with some images and I simply want to circle them around.
I mean, I would like to move the first image in place of the second one, the second one in place of the third one and so on, till the last one which would be moved at the first place. This should happen everytime I hit a button.
In Javascript this is pretty straitforward, something like this for example:
V = document.getElementsByTagName("img");
K = V[V.length - 1].src
for (i = V.length - 1; i > 1; i--)
{
    V[i].src = V[i - 1].src;
}
v[0].src = K;

Now I'am trying to realize the same shift in jQuery and I wonder if there is some simple trick to use. Anyone can help me?

A: Actually with plain javascript it is even easier than you wrote (no need for jquery, it adds a heavy load).
const images = document.getElementsByTagName("img");
let nextImageSrc = images[images.length - 1].src;

Array.from(images).forEach((img) => {
   const tmp = img.src;
   img.src = nextImageSrc;
   nextImageSrc = tmp;
});

If you do use jquery you can do the same thing:
const $images = $("img");
let nextImageSrc = $images.last().attr('src');

$images.each((i, img) => {
   const tmp = img.src;
   img.src = nextImageSrc;
   nextImageSrc = tmp;
});

A: I personally wouldn't couple it so tightly to just img.  You add another image to the page and get undesired results.
jQuery .each() documentation.
Untested, but something like this would work:
$(document).ready(function() {
  $('js-image-swap').on('click', function() {

    var $images = $('img.swap-image');

    var lastIndex = $images.length - 1;

    $images.each(function(index, $img) {
      if (index == lastIndex)
        $img.attr('src', $images.first().attr('src'));
      else
        $img.attr('src', $images.get(index +1).attr('src'));
    });
  });
});

Not exactly pretty..


text:
Q: Powershell read metadata of large files I've got a script that loops through a load of images that I've taken and reads the Focal Length & Camera Model, presenting a graph of focal lengths and totals (which is great for helping determine the next lens purchase, but that's besides the point).
This works absolutely fine for JPG images under 10 MB but as soon as it hits a RAW file (like Canon's CR2 format) nearer 20 MB, it spits out "Out of Memory" errors.
Is there a way to either increase the memory limit in Powershell, or just read a file's metadata without loading the entire file..?
This is what I'm currently using:
# load image by statically calling a method from .NET
$image = [System.Drawing.Imaging.Metafile]::FromFile($file.FullName)

# try to get the ExIf data (silently fail if the data can't be found)
# http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/EXIF.html
try
{
  # get the Focal Length from the Metadata code 37386
  $focalLength = $image.GetPropertyItem(37386).Value[0]
  # get model data from the Metadata code 272
  $modelByte = $image.GetPropertyItem(272)
  # convert the model data to a String from a Byte Array
  $imageModel = $Encode.GetString($modelByte.Value)
  # unload image
  $image.Dispose()
}
catch
{
  #do nothing with the catch
}

I have tried using the solution here: http://goo.gl/WY7Rg but CR2 files just return blanks on any property...
Any help greatly appreciated!

A: The problem is that the image object is not getting disposed when an error occurs. Execution exits the try block when an error occurs, meaning the Dispose call never executes and the memory is never returned.
To fix this, you must to put the $image.Dispose() call inside a finally block at the end of your try/catch. Like this
try
{
  /* ... */
}
catch
{
  #do nothing with the catch
}
finally
{
  # ensure image is always unloaded by placing this code in a finally block
  $image.Dispose()
}

A: I use this module for get EXIF data on image.
I had never test it on .CR2 but on .CRW of  about 15MB.
Try it and let me know.


text:
Q: How to make SCTP checksum non-zero using C programming I wrote a simple SCTP client/server, and I observed SCTP handshaking via Wireshark. The checksums of all SCTP packets are always zero in Wireshark.
How do I make a non-zero SCTP checksum?
The following are installed libraries on Ubuntu 18.04
libsctp-dev:amd64    1.0.17+dfsg-2
libsctp1:amd64       1.0.17+dfsg-2
lksctp-tools         1.0.17+dfsg-2

sctp-server.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>

int main(int argc, char** argv)
{
    int sockfd, client_sockfd;
    struct sockaddr_in serv_addr, client_addr;
    struct sctp_initmsg initmsg;
    int len;
    int addr_count = 1;

    sockfd = socket(AF_INET,SOCK_STREAM,IPPROTO_SCTP);
    if(sockfd < 0)
    {
        fprintf(stderr,"socket descriptor is invalid.");
        exit(1);
    }

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = INADDR_ANY;
    serv_addr.sin_port = htons(12345);

    int brst = sctp_bindx(sockfd,(struct sockaddr*)&serv_addr,addr_count,SCTP_BINDX_ADD_ADDR);
    if(brst == -1)
    {
        fprintf(stderr,"error while binding address.");
        exit(1);
    }

    memset(&initmsg,0,sizeof(initmsg));
    initmsg.sinit_max_instreams = 2;
    initmsg.sinit_num_ostreams = 2;
    brst = setsockopt(sockfd,IPPROTO_SCTP,SCTP_INITMSG,&initmsg,sizeof(initmsg));
    if(brst != 0)
    {
        fprintf(stderr,"error while setting sctp options.\n");
        exit(1);
    }

    listen(sockfd,5);
    while (1)
    {
        len = sizeof(client_addr);
        client_sockfd = accept(sockfd, (struct sockaddr*)&client_addr, &len);

        if(client_sockfd == -1)
        {
            fprintf(stderr,"error while accepting connection, continue.\n");
            continue;
        }
        else
        {
            printf("New client\n");
            close(client_sockfd);
        }
    }
}

sctp-client.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>

int main(int argc, char** argv)
{
    sctp_assoc_t associd;
    int sockfd;
    struct sockaddr_in serv_addr;
    struct sockaddr_in *addrs;
    int brst;
    struct sctp_initmsg initmsg;

    sockfd = socket(AF_INET,SOCK_STREAM,IPPROTO_SCTP);
    if(sockfd < 0)
    {
        fprintf(stderr,"error while initializing socket.\n");
        exit(1);
    }

    addrs = malloc(sizeof(struct sockaddr_in));
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = inet_addr("192.168.1.197");
    serv_addr.sin_port = htons(12345);

    memcpy(addrs,&serv_addr,sizeof(struct sockaddr_in));
    memset(&initmsg, 0, sizeof(initmsg));
    initmsg.sinit_max_instreams = 2;
    initmsg.sinit_num_ostreams = 2;

    brst = sctp_connectx(sockfd, (struct sockaddr*) &serv_addr, 1, &associd);
    if(brst < 0)
    {
        fprintf(stderr, "can not connect to host.\n");
        exit(1);
    }
    else
    {
        printf("connect ok %d\n", brst);
    }

    close(sockfd);
}

Compile
$ gcc sctp-server.c -lsctp -o server
$ gcc sctp-client.c -lsctp -o client

Wireshark
Frame 828: 100 bytes on wire (800 bits), 100 bytes captured (800 bits)
Linux cooked capture
Internet Protocol Version 4, Src: 192.168.1.197, Dst: 192.168.1.197
Stream Control Transmission Protocol, Src Port: 49208 (49208), Dst Port: 12345 (12345)
    Source port: 49208
    Destination port: 12345
    Verification tag: 0x00000000
    [Association index: 0]
    Checksum: 0x00000000 [unverified]
    [Checksum Status: Unverified]
    INIT chunk (Outbound streams: 10, inbound streams: 65535)
        Chunk type: INIT (1)
            0... .... = Bit: Stop processing of the packet
            .0.. .... = Bit: Do not report
        Chunk flags: 0x00
        Chunk length: 52
        Initiate tag: 0xd15eb4e4
        Advertised receiver window credit (a_rwnd): 106496
        Number of outbound streams: 10
        Number of inbound streams: 65535
        Initial TSN: 1069541083
        IPv4 address parameter (Address: 192.168.1.197)
        IPv4 address parameter (Address: 172.17.0.1)
        Supported address types parameter (Supported types: IPv4)
        ECN parameter
        Forward TSN supported parameter

A: There is a chance you disabled SCTP checksums in the linux kernel as mentioned in this patch. To verify this run the command sysctl /sys/module/sctp/parameters/sctp_checksum_disable. If the output is 1 then change it to 0 and try your test again.


text:
Q: php arrays to CSV I have an array of arrays
$numbers= array(3) {
  [months]=>
    array(3) {
      ["1"]=>
      string(7) "Jan"
      ["2"]=>
      string(7) "Feb"
     ["3"]=>
     string(7) "Mar"
  }
[dates]=>
  array(3) {
    ["1"]=>
    string(7) "12th"
    ["2"]=>
    string(7) "19th"
    ["3"]=>
    string(7) "22nd"
 }
  [people]=>
  array(3) {
    ["1"]=>
    string(7) "Bill"
    ["2"]=>
    string(7) "Ted"
    ["3"]=>
    string(7) "Gary"
 }
 }

I want to write the contents of these arrays into a CSV file in the form of a table
so I get an output like:
 months,  dates, people
 Jan,     12th,   Bill
 Feb,     19th,   Ted
 Mar,     22nd,   Gary

I want to try and put it directly from the array into the CSV in one move it it's possible but I can't find a way to do it without cutting it up.

A: $mi = new MultipleIterator();
$headers = array();
foreach($numbers as $header => $data) {
    $mi->attachIterator(new ArrayIterator($data));
    $headers[] = $header;
}

$fh = fopen('myfile.csv', 'w');
fputcsv($fh, $headers);
foreach($mi as $values) {
    fputcsv($fh, $values);
}
fclose($fh);

A: <?php
// transform the array
$keys = array_keys($numbers);
array_unshift($numbers, null);
$output = call_user_func_array('array_map', $numbers);
array_unshift($output, $keys);

// from php.net
$fp = fopen('file.csv', 'w');

foreach ($output as $fields) {
    fputcsv($fp, $fields);
}

fclose($fp);


text:
Q: Get name of clicked rectangle in WPF I am trying to get the name of a clicked Rectangle in my WPF application.
I tried first this:
XAML:
<Canvas Width="1680" Height="800" MouseLeftButtonDown="canvas_MouseLeftButtonDown">

XAML.cs
private void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    string selectedRect;
    if (e.OriginalSource is Rectangle)
    {
        Rectangle ClickedRectangle = (Rectangle)e.OriginalSource;

        var mouseWasDownOn = e.Source as FrameworkElement;
        string elementName = mouseWasDownOn.Name;
        selectedRect = elementName.ToString();
    }
}

It works well, but then I don't know how to pass the selectedRect string to my ViewModel
So I tried to pass directly the Relay command from xaml to Viewmodel:
<UserControl  x:Class="G.View.MapView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
      xmlns:extended="clr-namespace:G.ViewModel">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width=".7*" />
            <ColumnDefinition Width=".3*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height=".8*" />
            <RowDefinition Height=".2*" />
        </Grid.RowDefinitions>
        <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" Grid.Column="0" Grid.Row="0" Margin="10,10,0,0">
            <ItemsControl ItemsSource="{Binding CaskList}" HorizontalAlignment="Left" VerticalAlignment="Top">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas Width="1680" Height="800">
                            <Canvas.InputBindings>
                                <!-- One type of implementation -->
                                <KeyBinding Key="{Binding MouseLeftButtonDown.GestureKey}" Command="{Binding Path=HandleMyEvent}"/>
                            </Canvas.InputBindings>
                        </Canvas>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemContainerStyle>
                    <Style TargetType="ContentPresenter">
                        <Setter Property="Canvas.Left" Value="{Binding Left}"/>
                        <Setter Property="Canvas.Top" Value="{Binding Top}"/>
                    </Style>
                </ItemsControl.ItemContainerStyle>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Rectangle Stroke="Black" Width="64" Height="64" Fill="{Binding Color}"></Rectangle>
                            <Label Content="{Binding ID}" FontSize="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </Grid>
    </UserControl>

It works, I enter correctly in my method when I click the canvas, but I can not get the rectangle name, not having the event MouseButtonEventArgs e.
Can you help me?
EDIT: added complete xaml

A: Try this:
private void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    string selectedRect;
    if (e.OriginalSource is Rectangle)
    {
        Rectangle ClickedRectangle = (Rectangle)e.OriginalSource;

        var mouseWasDownOn = e.Source as FrameworkElement;
        string elementName = mouseWasDownOn.Name;
        selectedRect = elementName.ToString();

        //ViewModel code
        var vm = this.ViewModel as YourViewModel;
        vm.RectangleName = elementName.ToString();
    }
}


text:
Q: AS3 - Specific frame eventlistener? I have the following code to generate a new explosion movie clip. Unfortunately, the GameEvent.EXPLOSION_FINISHED event is never triggered. Is there a special event listener for each frame?
var exp:Explosion = new Explosion();
exp.addFrameScript(exp.totalFrames - 1, function():void {exp.stop();dispatchEvent( new GameEvent( GameEvent.EXPLOSION_FINISHED));});
exp.addEventListener(GameEvent.EXPLOSION_FINISHED, tidyUp, false, 0, true);

A: I think your problem is that your not dispatching the event on the exp object, but the object your chunk of code is in.  Try this:
exp.addFrameScript(exp.totalFrames - 1, function():void {exp.stop();exp.dispatchEvent( new GameEvent( GameEvent.EXPLOSION_FINISHED));});

A: stage.addEventListener(GameEvent.EXPLOSION_FINISHED,tidyUp);
...
function tidyUp(e:Event):void {
    var s:Object=e.target;
    if (s is Explosion) {
        var expl:Explosion=s as Explosion;
        // process your "expl" Explosion object here
    }
}

Should do.


text:
Q: Device to device communication using socket.io in android is not working? I am working on an android messaging application .I have used  compile 'io.socket:socket.io-client:0.6.2' library to implement this.I am successful in sending messages from android application to web application and receiving messages from web application to  android application .But when i installed the same app on another mobile phone, device to device communication did not work.I am not able to understand why this is not working.I am using socket.io here .Event listener is working when i receive messages from web application but wen android application from device A sends message to android application of device B,event listeners are not working perhaps.My code is given below :
1. ChatActivity.java
public class ChatActivity extends Activity {
public static final String TAG = ChatActivity.class.getSimpleName();
EditText edMessage;
Button sendMessage;
private Socket mSocket;
String sID, lID, md5StringRoomID, message, friendName, loggedInUser;
String frndID;
int smallerID, largerID;
AlmaChatDatabase almaChatDatabase;
// Chat messages list adapter
private MessagesListAdapter adapter;
private List<Message> listMessages;
private ListView listViewMessages;
boolean isSelf = false; // to check whether the message is owned by you or not.true means message is owned by you .
Message msg;
int loggedInUserID;
private String URL_FEED_Message = "";
APIConfiguration apiConfiguration;

{
    try {
        mSocket = IO.socket(Constants.CHAT_SERVER_URL);
        Log.e("Socket", String.valueOf(mSocket));
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    sendMessage = (Button) findViewById(R.id.btnSendMessage);
    almaChatDatabase = new AlmaChatDatabase(getApplicationContext());
    loggedInUserID = almaChatDatabase.getUserID(); // Getting ID of the Logged in user from the database
    Log.e("UserID", "Id of Logged in user  " + loggedInUserID);

    listMessages = new ArrayList<Message>();
    adapter = new MessagesListAdapter(getApplicationContext(), listMessages);
    listViewMessages = (ListView) findViewById(R.id.list_view_messages);
    listViewMessages.setAdapter(adapter);

    // Getting the ID of the friend from the previous screen using getExtras
    Bundle bundle = getIntent().getExtras();
    frndID = bundle.getString("ID");
    Log.e("FriendID", frndID);
    final int friendID = Integer.parseInt(frndID);
    friendName = bundle.getString("name");
    Log.e("FriendName", friendName);
    loggedInUser = almaChatDatabase.getUserName(); // Name of logged in user
    Log.e("LoggedInUser", loggedInUser);
    // Converting first lowercase letter of every word in Uppercase
    final String loggedInUpper = upperCase(loggedInUser);
    //To find the current time
    Date d = new Date();
    final long time = d.getTime();
    // Comparing the loggedInUserId and friendID
    if (friendID < loggedInUserID) {
        smallerID = friendID;
        largerID = loggedInUserID;
    } else {
        smallerID = loggedInUserID;
        largerID = friendID;
    }
    sID = String.valueOf(smallerID);
    lID = String.valueOf(largerID);
    String combinedID = sID + lID;
    Log.e("combined ID", combinedID);
    md5StringRoomID = convertPassMd5(combinedID); // Encrypting the combinedID to generate Room ID
    Log.e("md5StringRoomID", md5StringRoomID);

    // Using the API for loading old chat messages
    apiConfiguration = new APIConfiguration();
    String api_message = apiConfiguration.getApi_message(); // Getting the API of messages
    URL_FEED_Message = api_message + md5StringRoomID; // md5String is the encrypted room ID here
    Log.e("URL_FEED_MESSAGE", URL_FEED_Message);

    Log.e("Network request", "Fresh Request");
    // We first check for cached request
    Cache cache = AppController.getInstance().getRequestQueue().getCache();
    Cache.Entry entry = cache.get(URL_FEED_Message);
    if (entry != null) {
        // fetch the data from cache
        try {
            String data = new String(entry.data, "UTF-8");
            try {
                parseJsonFeed(new JSONArray(data));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

    } else {

        JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(URL_FEED_Message, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray jsonArray) {
                Log.e("JsonArray", String.valueOf(jsonArray));
                if (jsonArray != null) {
                    parseJsonFeed(jsonArray);
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.e("ErrorResponse", String.valueOf(volleyError));
            }
        }
        );
        // Adding request to volley request queue
        AppController.getInstance().addToRequestQueue(jsonArrayRequest);
    }

    edMessage = (EditText) findViewById(R.id.edtMessage);
    //Listening on Events
    mSocket.on(Socket.EVENT_CONNECT, onConnect);
    mSocket.on(Socket.EVENT_CONNECT_ERROR, onConnectionError);
    mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect);
    mSocket.on("send:notice", onReceive); // Listening event for receiving messages
    mSocket.connect(); // Explicitly call connect method to establish connection here
    mSocket.emit("subscribe", md5StringRoomID);

    sendMessage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //mSocket.emit("subscribe", md5String);
            message = edMessage.getText().toString().trim();
            Log.e("messageSent", message);
            if (!message.equals("")) {
                edMessage.setText(" ");
                JSONObject jsonObject = new JSONObject();
                try {
                    jsonObject.put("room_id", md5StringRoomID);
                    jsonObject.put("user", loggedInUpper);
                    jsonObject.put("id", friendID);
                    jsonObject.put("message", message);
                    jsonObject.put("date", time);
                    jsonObject.put("status", "sent");

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                isSelf = true; // Boolean isSelf is set to be true as sender of the message is logged in user i.e. you
                attemptToSend(loggedInUpper, message, isSelf);
                mSocket.emit("send", jsonObject); // owner i.e LoggedIn user is sending the message
            } else {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Please enter some text", Toast.LENGTH_LONG).show();

                    }
                });
            }
        }

    });

}

//Adding message in the arrayList
public void attemptToSend(String senderName, String message, boolean isSelf) {
    msg = new Message(senderName, message, isSelf);
    listMessages.add(msg);
    adapter.notifyDataSetChanged();
    playBeep();
}

// Playing sound when the message is sent by the owner
public void playBeep() {
    try {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
        r.play();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

// encrypting string into MD5
public static String convertPassMd5(String pass) {
    String password = null;
    MessageDigest mdEnc;
    try {
        mdEnc = MessageDigest.getInstance("MD5");
        mdEnc.update(pass.getBytes(), 0, pass.length());
        pass = new BigInteger(1, mdEnc.digest()).toString(16);
        while (pass.length() < 32) {
            pass = "0" + pass;
        }
        password = pass;
    } catch (NoSuchAlgorithmException e1) {
        e1.printStackTrace();
    }
    return password;
}

// Converting first lowercase letter of every word in Uppercase
String upperCase(String source) {
    StringBuffer res = new StringBuffer();
    String[] strArr = source.split(" ");
    for (String str : strArr) {
        char[] stringArray = str.trim().toCharArray();
        stringArray[0] = Character.toUpperCase(stringArray[0]);
        str = new String(stringArray);
        res.append(str).append(" ");
    }
    return res.toString().trim();
}

// Event Listeners
private Emitter.Listener onConnect = new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        Log.e("Socket", "Connected");
    }
};

private Emitter.Listener onConnectionError = new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        Log.e("Error", "Error in connecting server");
    }
};
private Emitter.Listener onDisconnect = new Emitter.Listener() {
    @Override
    public void call(Object... args) {
        Log.e("Disconnect", "Socket Disconnected");
    }
};

// Event Listener for receiving messages
private Emitter.Listener onReceive = new Emitter.Listener() {
    @Override
    public void call(final Object... args) {
        Log.e("Receive", "Message received");
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                JSONObject data = (JSONObject) args[0];
                Log.e("DATA", String.valueOf(data));
                try {
                    JSONArray ops = data.getJSONArray("ops");
                    for (int i = 0; i < ops.length(); i++) {
                        JSONObject object = ops.getJSONObject(i);
                        String roomID = object.getString("room_id");
                        Log.e("RoomID", roomID); // Getting room ID from JSON array
                        Log.e("Md5RoomID", md5StringRoomID); // Getting room id which we have created using logged in user ID and room id of the user through which chat has to be done
                        //Comparing the room IDs
                        if (md5StringRoomID.equals(roomID)) {
                            String senderName = object.getString("user");
                            Log.e("Sender Name", senderName);
                            String senderID = object.getString("id");
                            Log.e("SenderID", senderID);
                            JSONObject message = object.getJSONObject("message");
                            String messageReceived = message.getString("text");
                            Log.e("Message Received", messageReceived);
                            String loggedInUSerNAme = almaChatDatabase.getUserName();
                            //If the message is sent by the owner to other from webapp ,then we need to check whether the sender is the loggedinUSer in the App or not and we will right align the messages .
                            if (loggedInUSerNAme.equalsIgnoreCase(senderName)) {
                                isSelf = true;
                                msg = new Message(senderName, messageReceived, isSelf);
                                listMessages.add(msg);
                                Log.e("List Elements", String.valueOf(listMessages));
                                adapter.notifyDataSetChanged();
                                playBeep();
                            } else {
                                isSelf = false;
                                msg = new Message(senderName, messageReceived, isSelf);
                                listMessages.add(msg);
                                Log.e("List Elements", String.valueOf(listMessages));
                                adapter.notifyDataSetChanged();
                                playBeep();
                            }
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    // Playing sound when the message is sent by other
    public void playBeep() {
        try {
            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

};

// Parsing JSon Array which corresponds to the old chat messages
public void parseJsonFeed(JSONArray jsonArray) {
    for (int i = 0; i < jsonArray.length(); i++) {
        try {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            String roomID = jsonObject.getString("room_id");
            Log.e("RoomID", roomID);
            Log.e("Md5RoomID", md5StringRoomID);
            // If Room ID(created using id of logged in user and id of friend) matches with the room id obtained from JSON String
            if (md5StringRoomID.equals(roomID)) {
                String userName = jsonObject.getString("user");
                Log.e("Name", userName);
                String loggedInUSerNAme = almaChatDatabase.getUserName();
                Log.e("LoggedInUSer", loggedInUSerNAme);
                //If the message is sent by the owner to other from webapp ,then we need to check whether the sender is the loggedinUSer in the App or not and we will right align the messages .
                if (loggedInUSerNAme.equalsIgnoreCase(userName)) {
                    String message = jsonObject.getString("message");
                    Log.e("message", message);
                    isSelf = true;
                    msg = new Message(userName, message, isSelf);
                    listMessages.add(msg);
                    adapter.notifyDataSetChanged();
                    //playBeep();
                } else {
                    JSONObject jsonMessage = jsonObject.getJSONObject("message");
                    String message = jsonMessage.getString("text");
                    isSelf = false;
                    msg = new Message(userName, message, isSelf);
                    listMessages.add(msg);
                    adapter.notifyDataSetChanged();
                    // playBeep();
                }
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        // notify data changes to list adapter
        //adapter.notifyDataSetChanged();
    }
}

}
2.Constants.java
public class Constants {
 public static final String CHAT_SERVER_URL = "http://192.168.2.250:3000/";

}
Please help me to resolve the issue .How can i implement device to device communication here.


text:
Q: Python: Pandas DataFrame Manipulation Problem
I have a dataframe with image_ids and their respective hash_values. The columns represent the difference of that image_id w.r.t. other image ids as shown below:

These differences have been calculated to find which images are similar. The images having difference value less than 15 are considered as similar images.
Objective
I want to obtain the dataframe with only unique image_ids i.e., delete the image_ids which are similar and only keep one of them.
Example
As an example, in the dataframe images 1.jpg and 2.jpg are similar as their difference is 33 which is greater than 15 but images 3.1.jpg, 3.2.jpg, 3.3.jpg are similar as their difference values are less than 15.
Desired Output
The desired output should be the dataframe with only the image_ids as 1.jpg, 2.jpg, 3.1.jpg.
3.2.jpg and 3.3.jpg should be deleted as they are similar.
I wrote the below code, but it is removing any image having a similar value i.e., it removes 3.1.jpg, 3.2.jpg, 3.3.jpg all of them from the dataframe.
# For every image_id, find the column values having value < 15 more than once and delete respective rows

def remove_duplicates(df):

        for i in range(len(df.image_ids)):
            clean_df = df.drop(df[df[f"diff_{df.image_ids[i]}"] < 15].index)

        return clean_df

clean_df = remove_duplicates(df)

The output of the code is:

As it can be clearly observed that the image 3.1.jpg is absent in the dataframe whereas it should be present.
How to fix this?

A: Here what I have come up with. I firmly believe it's not the best idea, but might be a solution to your problem:
import pandas as pd
import re
df = pd.DataFrame({"image_ids": ["1.jpg", "2.jpg", "3.2.jpg", "3.1.jpg", "3_3.jpg"]})
checkList = []
newDf = pd.DataFrame()
for index, row in df.iterrows():
  id = row["image_ids"]
  m1 = re.search(r"^(\d+)\.jpg$", id)
  m2 = re.search(r"^(\d+)\.(\d+)\.jpg$", id)
  if m1:
    if m1.group(1) in checkList:
      continue
    else:
      checkList.append(m1.group(1))
      newDf = newDf.append(row)
  elif m2:
    if m2.group(1) in checkList:
      continue
    elif m2.group(2) == "1":
      checkList.append(m2.group(1))
      newDf = newDf.append(row)

Note that, to have an example data, I wrote df dataframe. You have to change this line to load your dataframe.
Explanation
In this code, I have used regex to extract the id of each image. The first regex will catch the image's name which has a pattern like 5.jpg. The second regex will capture if the image's name is something like 52.3.jpg. Having appended the ids to a variable named checkList, I check if the image id has been selected before.

A: If the difference columns for the images that have been removed isn't needed, dropping that image's difference column is a simple solution.
def remove_duplicates(df):

    for i in range(len(df.image_ids)):
        # This is the column that we want to drop
        col = 'diff_' + df[image_ids].iloc[i]

        clean_df = df.drop(df[df[f"diff_{df.image_ids[i]}"] < 15].index)

        # Dropping the column
        clean_df = clean_df.drop(columns=col)

    return clean_df

Note: The code might not work as I believe you're deleting all of the similar images at the same time. But I believe you can fix this by only deleting only the image at the current index whilst iterating and not deleting the other images.
I didn't do this myself as I didn't understand this line
clean_df = df.drop(df[df[f"diff_{df.image_ids[i]}"] < 15].index)

Still, removing only the current index's image and not the other similar images is a trivial task but I'm too lazy to do that from scartch.


text:
Q: How to save data in cassandra table using spark's saveToCassandra? I'm using Cassandra with spark and I want to save data in Cassandra table. I want to insert data into a below table -
cqlsh:users> select * from subscription ;

 pk | a | b
----+---+---

(0 rows)
cqlsh:users> desc subscription ;

CREATE TABLE users.subscription (
    pk uuid PRIMARY KEY,
    a text,
    b text
)

Program Code (consumer_demo.py)-
from pyspark import SparkConf
import pyspark_cassandra
from pyspark_cassandra import CassandraSparkContext

conf = SparkConf().set("spark.cassandra.connection.host", "localhost")
sparkContext = CassandraSparkContext(conf = conf)
rdd = sparkContext.parallelize([{"pk":"uuid()", "a":"aaa", "b":"bbbb" }])
rdd.saveToCassandra("users", "subscription", {"pk", "a", "b"})

Command I'm using to execute above code -
sudo /usr/local/spark/bin/spark-submit --packages TargetHolding/pyspark-cassandra:0.3.5 consumer_demo.py

I'm facing below error -
Traceback (most recent call last):
  File "consumer_demo.py", line 8, in <module>
    rdd.saveToCassandra("users", "subscription", {"pk", "a", "b"})
  File "/root/.ivy2/jars/TargetHolding_pyspark-cassandra-0.3.5.jar/pyspark_cassandra/rdd.py", line 83, in saveToCassandra
  File "/root/.ivy2/jars/TargetHolding_pyspark-cassandra-0.3.5.jar/pyspark_cassandra/util.py", line 93, in helper
  File "/usr/local/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1133, in __call__
  File "/usr/local/spark/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py", line 319, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o26.newInstance.
: java.lang.NoSuchMethodError: scala.reflect.api.JavaUniverse.runtimeMirror(Ljava/lang/ClassLoader;)Lscala/reflect/api/JavaMirrors$JavaMirror;
    at com.datastax.spark.connector.types.TypeConverter$.<init>(TypeConverter.scala:114)
    at com.datastax.spark.connector.types.TypeConverter$.<clinit>(TypeConverter.scala)
    at pyspark_cassandra.PythonHelper.<init>(PythonHelper.scala:36)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:280)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:214)
    at java.lang.Thread.run(Thread.java:745)

Cassandra version-
cqlsh:users> show VERSION;
[cqlsh 5.0.1 | Cassandra 2.2.3 | CQL spec 3.3.1 | Native protocol v4]

Spark version-
>spark-submit --version
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 2.1.0
      /_/

Using Scala version 2.11.8, Java HotSpot(TM) 64-Bit Server VM, 1.8.0_91
Branch
Compiled by user jenkins on 2016-12-16T02:04:48Z
Revision
Url
Type --help for more information.

Python version -
>python --version
Python 2.7.6

Questions -

*

*Why I'm getting this error?

*How to solve this error?

Edit - Error
>>>    spark.read.format("org.apache.spark.sql.cassandra").options(table="temp", keyspace="users").load().show()
17/04/06 10:57:34 ERROR Executor: Exception in task 0.0 in stage 0.0 (TID 0)
java.lang.NoClassDefFoundError: scala/runtime/AbstractPartialFunction$mcJL$sp
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.datastax.spark.connector.rdd.CassandraLimit$.limitForIterator(CassandraLimit.scala:21)
    at com.datastax.spark.connector.rdd.CassandraTableScanRDD.compute(CassandraTableScanRDD.scala:367)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
    at org.apache.spark.scheduler.Task.run(Task.scala:99)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:282)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: scala.runtime.AbstractPartialFunction$mcJL$sp
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 31 more
17/04/06 10:57:34 WARN TaskSetManager: Lost task 0.0 in stage 0.0 (TID 0, localhost, executor driver): java.lang.NoClassDefFoundError: scala/runtime/AbstractPartialFunction$mcJL$sp
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.datastax.spark.connector.rdd.CassandraLimit$.limitForIterator(CassandraLimit.scala:21)
    at com.datastax.spark.connector.rdd.CassandraTableScanRDD.compute(CassandraTableScanRDD.scala:367)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
    at org.apache.spark.scheduler.Task.run(Task.scala:99)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:282)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: scala.runtime.AbstractPartialFunction$mcJL$sp
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 31 more

17/04/06 10:57:34 ERROR TaskSetManager: Task 0 in stage 0.0 failed 1 times; aborting job
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/spark/python/pyspark/sql/dataframe.py", line 318, in show
    print(self._jdf.showString(n, 20))
  File "/usr/local/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1133, in __call__
  File "/usr/local/spark/python/pyspark/sql/utils.py", line 63, in deco
    return f(*a, **kw)
  File "/usr/local/spark/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py", line 319, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o37.showString.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 0.0 failed 1 times, most recent failure: Lost task 0.0 in stage 0.0 (TID 0, localhost, executor driver): java.lang.NoClassDefFoundError: scala/runtime/AbstractPartialFunction$mcJL$sp
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.datastax.spark.connector.rdd.CassandraLimit$.limitForIterator(CassandraLimit.scala:21)
    at com.datastax.spark.connector.rdd.CassandraTableScanRDD.compute(CassandraTableScanRDD.scala:367)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
    at org.apache.spark.scheduler.Task.run(Task.scala:99)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:282)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: scala.runtime.AbstractPartialFunction$mcJL$sp
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 31 more

Driver stacktrace:
    at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1435)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1423)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1422)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
    at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1422)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:802)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:802)
    at scala.Option.foreach(Option.scala:257)
    at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:802)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.doOnReceive(DAGScheduler.scala:1650)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1605)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessLoop.onReceive(DAGScheduler.scala:1594)
    at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)
    at org.apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:628)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:1918)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:1931)
    at org.apache.spark.SparkContext.runJob(SparkContext.scala:1944)
    at org.apache.spark.sql.execution.SparkPlan.executeTake(SparkPlan.scala:333)
    at org.apache.spark.sql.execution.CollectLimitExec.executeCollect(limit.scala:38)
    at org.apache.spark.sql.Dataset$$anonfun$org$apache$spark$sql$Dataset$$execute$1$1.apply(Dataset.scala:2371)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:57)
    at org.apache.spark.sql.Dataset.withNewExecutionId(Dataset.scala:2765)
    at org.apache.spark.sql.Dataset.org$apache$spark$sql$Dataset$$execute$1(Dataset.scala:2370)
    at org.apache.spark.sql.Dataset.org$apache$spark$sql$Dataset$$collect(Dataset.scala:2377)
    at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2113)
    at org.apache.spark.sql.Dataset$$anonfun$head$1.apply(Dataset.scala:2112)
    at org.apache.spark.sql.Dataset.withTypedCallback(Dataset.scala:2795)
    at org.apache.spark.sql.Dataset.head(Dataset.scala:2112)
    at org.apache.spark.sql.Dataset.take(Dataset.scala:2327)
    at org.apache.spark.sql.Dataset.showString(Dataset.scala:248)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:280)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:214)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: scala/runtime/AbstractPartialFunction$mcJL$sp
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.datastax.spark.connector.rdd.CassandraLimit$.limitForIterator(CassandraLimit.scala:21)
    at com.datastax.spark.connector.rdd.CassandraTableScanRDD.compute(CassandraTableScanRDD.scala:367)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.rdd.MapPartitionsRDD.compute(MapPartitionsRDD.scala:38)
    at org.apache.spark.rdd.RDD.computeOrReadCheckpoint(RDD.scala:323)
    at org.apache.spark.rdd.RDD.iterator(RDD.scala:287)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
    at org.apache.spark.scheduler.Task.run(Task.scala:99)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:282)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: scala.runtime.AbstractPartialFunction$mcJL$sp
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 31 more

A: This is most likely a Scala Version error coupled with various other Spark Version mismatch errors. The TargetHolding lib stopped being updated at the end of last year so it is unlikely that it will work in the future.
So the first error is that the Spark Cassandra Connector being bundled with that library uses Scala 2.10 while the default version of Spark 2.1.0 uses Scala 2.11. These are incompatible (especially in reflection) which is why you see the above error.
The solution to this is to either start maintaining that package and update it to Spark 2.1.0 and Scala 2.11 but this would require a considerable amount of work. You could instead try a DataFrame approach using just the Spark Cassandra Connector which supports Spark 2.1.0.


text:
Q: How to get the absolute path of a script using its PPID - Bash I am trying the absolute path of a given PPID from a shell script.
However, the Parent Process may be any type of script (bash/csh/zsh/tsh/Makefile).
The child process is always a bash script and is the only script I have access on to edit.
I have tried:

*

*ps --no-headers -o command $PPID but it only gets the command that invoked the parent process. This isn't what I need because the parent may have caused some cd's inside the script and I won't be able to resolve the relative path in the command to it.

*ls -l /proc/$PPID/fd/255 and this was the closest to what I want but this is specific to bash scripts and as I mentioned, I don't have access to know my parent process' script type.

*/proc/$PPID/exe returns the binary exe, and I need the script's absolute path that is using this binary.

A: *

*There isn't such thing as "the" absolute path. There may be several way to access the same file. And some times, none of them (or more than one of them, depends how you look at it) are "the" main name.
I am thinking of hard links here, for example.

*Makefile is never the path of a script. It is just a configuration file. That is read by default by the executable. Which is probably /usr/bin/make. To find a path to the Makefile file, you need to read arguments of make. Or to find a Makefile among open files (assuming there is only one, and that it is named Makefile, and that is not certain). And the strategy to guess what is the Makefile of a make process is specific to make. You need another strategy to guess what is the script file executed by a bash process, Another to find what is the python file executed by a python command (which could be a shebang python "executable", a python ../somerealtive/path/somefile.py a python /some/absolute/paht a python -m somemodele, a python -c "import somemod ; somemod.run()"  etc.)

*Now, since you've mentioned /proc/$PPID/exe, you can get the file "pointed" by this, using
path=$(readlink -f /proc/$PPID/exe)
Again, that is linux solution, more than a bash one. You have no guarantee from bash that the system on which you run this command have a /proc filesystem
I must add that I suspect a XY problem here. What are you trying to do exactly?


text:
Q: Matlab fprintf to keep significant figures and rightmost zeroes Let's say I have a random variable a=1.2400, and I want to print it with four significant figures, i.e., 1.240. How would I go about that?
fprintf('%0.4g',a) % drops rightmost zero
fprintf('%0.3f',a) % give too many sig figs if a >= 10

Using '%g' drops the important zeros, and with '%f' I can only specify the number of digits after the decimal, which results in too many significant figures if, say, a=10.04. I'm not too familiar with formatting ,but there has to be a simple method. I haven't found it in my searches.

A: If the values to be printed are all less than 10000, you can do the following. (Sorry, only tested in octave.)
octave:62> a = 1.24
a =  1.2400
octave:63> sprintf('%.*f\n', 3-floor(log10(abs(a))), a)
ans = 1.240

octave:64> a = 234.56
a =  234.56
octave:65> sprintf('%.*f\n', 3-floor(log10(abs(a))), a)
ans = 234.6

For more about the expression floor(log10(abs(a))), see How can I get the exponent of each number in a np.array?
If you don't mind exponential notation, another alternative is to use '%.3e' to always get the same number of signficant digits:
octave:70> a = 1.24
a =  1.2400
octave:71> sprintf('%.3e\n', a)
ans = 1.240e+00

octave:72> a = 234.56
a =  234.56
octave:73> sprintf('%.3e\n', a)
ans = 2.346e+02

A: I decided to build on the answer by Warren, and I wrote a function that should work for both small and large numbers alike. Perhaps someone will improve on this, but I am pleased with it.
function str=sigfigstr(a,sigfigs)

numdecimal = floor(log10(abs(a)));

if sigfigs - numdecimal < 0
    str=sprintf('%.0f',round(a,sigfigs,'significant'));
else
    str=strip(sprintf('%.*f\n', sigfigs-floor(log10(abs(a))), a));
end

Here are a few examples if it in action in Matlab
>> sigfigstr(.000012431634,3)
ans = '0.0000124'
>> sigfigstr(26666,3)
ans = '26700'


text:
Q: How to use Java to start a bat file on windows and sh file on linux to run from a specific directory I am trying to make a program which will execute a bat file when run on windows and a sh file when run on linux, but I need the bash/sh file to start running from a specific directory.
For example:
My program is located at C:\Program\test.jar
My bash file is located at C:\File\start.bat
I want to make the java runnable execute the start.bat file from its folder and not test.jar running directory.
I tried using Runtime.getRuntime().exec("cmd /C start \"\" \"C:\File\start.bat""); and it works, but it runs the bat file from C:\Program\test.jar, and for what the bat file does, I need it to run from C:\File\start.bat.
I also need to do the same for Linux, so I am asking here because after the bat issue is fixed, this issue will likely stomp me as well.

A: Use ProcessBuilder and set the working directory with ProcessBuilder::directory


text:
Q: Laravel Passport authorization for only 1 third party web I want to know how can i create a Access Client for a especific website.
I'm trying to create a postback url where a postback route will receive data from a third part website.
The 3rd party website do a Post to my website postback route and send url parameters. (Like id, ip, etc)
I know that I can create a passport client and then use client access tokens. But I don't understand how can I make that this token and this client only works with this 3rd party website and i don't want that if I take a user token generated with email and password to the same postback could send data to this.
I was researching but i can't understand how it works.


text:
Q: Python, opposite function urllib.urlencode How can I convert data after processing urllib.urlencode to dict?
urllib.urldecode does not exist.

A: Python 3 version based on Alex's answer:
>>> import urllib.parse
>>> d = {'a':'x', 'b':'', 'c':'z'}
>>> s = urllib.parse.urlencode(d)
>>> s
'a=x&b=&c=z'
>>> d1 = urllib.parse.parse_qs(s, keep_blank_values=True)
>>> d1
{'a': ['x'], 'b': [''], 'c': ['z']}

The alternative:
>>> sq = urllib.parse.parse_qsl(s, keep_blank_values=True)
>>> sq
[('a', 'x'), ('b', ''), ('c', 'z')]
>>> dict(sq)
{'a': 'x', 'b': '', 'c': 'z'}

parse_qsl is reversible:
>>> urllib.parse.urlencode(sq)
'a=x&b=&c=z'

Keep possible duplicates in mind, when parsing user-input:
>>> s = 'a=x&b=&a=z'
>>> d1 = urllib.parse.parse_qs(s, keep_blank_values=True)
>>> d1
{'a': ['x', 'z'], 'b': ['']}
>>> sq = urllib.parse.parse_qsl(s, keep_blank_values=True)
>>> sq
[('a', 'x'), ('b', ''), ('a', 'z')]
>>> dict(sq)
{'a': 'z', 'b': ''}

*

*The lists in the parse_qs result may have more than one item

*Calling dict on the parse_qsl result may hide values

A: urllib.unquote_plus() does what you want. It replaces %xx escapes by their single-character equivalent and replaces plus signs with spaces.
Example:
unquote_plus('/%7Ecandidates/?name=john+connolly')

yields
'/~candidates/?name=john connolly'.

A: As the docs for urlencode say,

The urlparse module provides the
  functions parse_qs() and parse_qsl()
  which are used to parse query strings
  into Python data structures.

(In older Python releases, they were in the cgi module).  So, for example:
>>> import urllib
>>> import urlparse
>>> d = {'a':'b', 'c':'d'}
>>> s = urllib.urlencode(d)
>>> s
'a=b&c=d'
>>> d1 = urlparse.parse_qs(s)
>>> d1
{'a': ['b'], 'c': ['d']}

The obvious difference between the original dictionary d and the "round-tripped" one d1 is that the latter has (single-item, in this case) lists as values -- that's because there is no uniqueness guarantee in query strings, and it may be important to your app to know about what multiple values have been given for each key (that is, the lists won't always be single-item ones;-).
As an alternative:
>>> sq = urlparse.parse_qsl(s)
>>> sq
[('a', 'b'), ('c', 'd')]
>>> dict(sq)
{'a': 'b', 'c': 'd'}

you can get a sequence of pairs (urlencode accepts such an argument, too -- in this case it preserves order, while in the dict case there's no order to preserve;-).  If you know there are no duplicate "keys", or don't care if there are, then (as I've shown) you can call dict to get a dictionary with non-list values.  In general, however, you do need to consider what you want to do if duplicates are present (Python doesn't decide that on your behalf;-).


text:
Q: Rails: How can my app tell if it is running in MRI or JRuby? In a previous question, I asked how to tell my Gemfile whether to take the JRuby-relevant gems or the MRI-relevant gems. The answer I got was to do the following in the Gemfile:
platforms :jruby do
  gem "activerecord-jdbcsqlite3-adapter"
end

platforms :mri do
  gem "sqlite3"
end

Obviously, the platforms() method in Bundler knows how to figure out if I'm running MRI or JRuby. Is there another way I can tell within my program if I am running JRuby or MRI?

A: Are you able to distinguish between the two like this:
case (RUBY_ENGINE)
when 'ruby'
  # ...
when 'jruby'
  # ...
end

You could write a method to give you a jruby? method if required:
def jruby?
  RUBY_ENGINE == 'jruby'
end

A: With Ruby 2.2.3  Config::CONFIG gives me NameError: uninitialized constant Config, but the following works:
y RbConfig::CONFIG