Q: Pass value from internal to external function - Cannot save password I try to hash passwords with crypto and I cannot save them in the database.
I have node.js 4.2.3 express 4.13.3, and my database is PostgreSQL 9.1. The field is character varying (255) and is named pswrd.
This is my code:
var tobi = new User({
    usrnm:'sp',
    pswrd:'an'
});

module.exports = User;

function User(obj){
    for(var key in obj){
        this[key] = obj[key];
    }
}

User.prototype.save = function (fn){
    var user=this;
     //EDIT, added this :
     var psw ;
    var salt = crypto.randomBytes(50).toString('base64');
    crypto.pbkdf2(user.pswrd, salt, 10000, 150, 'sha512',function(err, derivedKey) {
        //user.pswrd = derivedKey.toString('hex');
         //EDIT, added this:
         var justCrypted = derivedKey.toString('hex');
    });

    var query=client.query('INSERT INTO mytable(usrnm,pswrd)VALUES($1,$2) RETURNING mytable_id',[user.usrnm,user.pswrd], function(err, result) {
        if(err) {console.log(err)}
        else {
          var newlyCreatedId = result.rows[0].mytable_id;
        }
    });
    query.on("end", function (result) {console.log(result);client.end();});
}

tobi.save(function (err){
    if (err)throw error;
    console.log("yo");
})

To run this, I type node lib/user. I get no errors, but the password is not saved properly. The first value gets saved, the an, not the hashed one. What am I missing here?
EDIT
AshleyB answer is good, but, please help me understand how to pass data from an internal function (crypto.pbkdf2) to its external (User.prototype.save = function (fn)) , when the internal has predifined, fixed syntax (crypto.pbkdf2) , so I dont know if or how I can edit it.
How can I leave code as is and still pass the justCrypted back to psw (see edits on code) ? If it was a function that I wrote, I could use apply I guess, but, crypto.pbkdf2 is  predifined and I dont know if can add stuff to it.
Thanks

A: The problem is with the scope, currently the query the altered user.pswrd is outside of the scope of the query so it falls back to the value assigned at the top.
By moving the query inside the 'crypto.pbkdf2'... block the user.pswrd value will work as intended. I've updated your code (and made the salt generation asynchronous, as you have used the async version of pbkdf2 anyway).
var tobi = new User({
  usrnm: 'sp',
  pswrd: 'an'
});

module.exports = User;

function User(obj) {
  for (var key in obj) {
    this[key] = obj[key];
  }
}

User.prototype.save = function(fn) {
  var user = this;

  // Changed salt generation to async version
  // See: https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback

  crypto.randomBytes(50, function(ex, buf) {
  if (ex) throw ex;
  salt = buf.toString('base64');

    // password, salt, iterations, keylen[, digest], callback
    crypto.pbkdf2(user.pswrd, salt, 10000, 150, 'sha512', function(err, derivedKey) {
    user.pswrd = derivedKey.toString('hex');

        // Moved the query within the hash function
    var query = client.query('INSERT INTO mytable(usrnm,pswrd)VALUES($1,$2) RETURNING mytable_id', [user.usrnm, user.pswrd], function(err, result) {
      if (err) {
        console.log(err)
      } else {
        var newlyCreatedId = result.rows[0].mytable_id;
      }
    });
    query.on("end", function(result) {
      console.log(result);
      client.end();
    });

  });

    });

}

tobi.save(function(err) {
  if (err) throw error;
  console.log("yo");
})

A: To answer your edit, I think you just need to understand that crypto.pbkdf2 is an asynchronous function that has a callback function as it's last parameter.
So within that callback function, you can access the psw variable, and you are able to do something like psw = newlyCreatedId.  However, in your code the query is most likely called before the callback is.  Therefore, you cannot make use of the psw variable in the query as your code stands.
What Ashley B did is to put your query function within the callback, to ensure that the query is not called until after the crypto function.  You could also structure your code to use events, or promises if you didn't wish to nest the functions.

A: This is to answer your EDIT and to help you understand the passing of data between internal and external functions:
I've modified your code slightly to demonstrate the point. What you must understand is the scope and context of the calling function and how your function gets invoked. Crypto.pbkdf2 function accepts a function as a callback. This function is not part of the regular/sequential flow of control. The pbkdf2 function is an 'asynchronous' function - it returns immediately, but the processing can continue on background. This is why the code marked with '//Output 1: This will be undefined' below, will output 'undefined'. The main thread continues while pbkdf2 continues processing in background.
When the system is done processing, it calls the function you specified as the callback to let you know its done processing. Think of it as an SMS you send to someone vs. making a phone call. They reply back with an SMS whenever they get a chance.
However, when the system invokes the callback function, the "scope" or the "context" is different (think of it as an external entity calling your callback function). Therefore, it does not know what the scope/variables/functions in your context. In order to pass data between callback function and your objects, you can use the 'bind' method along with 'this' keyword:
var tobi = new User({
    usrnm:'sp',
    pswrd:'an'
});
module.exports = User;
function User(obj){
    for(var key in obj){
        this[key] = obj[key];
    }
}
User.prototype.save = function (fn){
    var user=this;

     var psw ; //Change this to this.psw to pass changes back.
     var crypto = require('crypto');
    var salt = crypto.randomBytes(50).toString('base64');
    crypto.pbkdf2(user.pswrd, salt, 10000, 150, 'sha512',function(err, derivedKey) {

         var justCrypted = derivedKey.toString('hex');
         console.log('Finished crypting' + justCrypted);
         this.psw = justCrypted;
//When we use 'this' here, we set the value in the right scope/context.
//The var psw does not exist outside the scope of this function, so the
//external function will not know about it. By defining it in the current
// (this) scope, we ensure that external function is also aware of it.
         this.externalFunction(justCrypted);
//Bind the callback function to the current context - it will remember
//this when the callback gets invoked. Think of it as explicitly specifying
//the 'context' of the call/method.
    }.bind(this));
    //Output 1: This will be undefined as callback has not returned yet.
    console.log('New psw' + this.psw);

    /*var query=client.query('INSERT INTO mytable(usrnm,pswrd)VALUES($1,$2) RETURNING mytable_id',[user.usrnm,user.pswrd], function(err, result) {
        if(err) {console.log(err)}
        else {
          var newlyCreatedId = result.rows[0].mytable_id;
        }
    });
    query.on("end", function (result) {console.log(result);client.end();}); */
}
User.prototype.externalFunction = function (someData) {
    console.log('Data passed from an internal function');
    console.log('New PSW: ' + this.psw);
    console.log('Data from external function: ' + someData);
}
tobi.save(function (err){
    if (err)throw error;
    console.log("yo");
})

If I run the above, I see the following output. Note that data is now being passed between internal and external functions via the callback:
C:\temp\node\npm-test>node index.js
New pswundefined
3f9219ae14f9246622973724ace5cb66b190a4b5e86abf482fce5d7889e6aff870741d672ff78e7765fada25f150c70e5e61
c13b5bcdec634d03830668348b5a7d06cf75f426259dcf804241eb2f4362d10f1ebf23a1aecca28072a3f38fb8a39eba88c9
f055e9e7ccabafcd8caed25d8b26f3726022973175545f77e4024bcbcc657081ea5d1f2baf5e9080cbb20696135f2be8834c

Data passed from an internal function
New PSW: 3f9219ae14f9246622973724ace5cb66b190a4b5e86abf482fce5d7889e6aff870741d672ff78e7765fada25f15
0c70e5e61c13b5bcdec634d03830668348b5a7d06cf75f426259dcf804241eb2f4362d10f1ebf23a1aecca28072a3f38fb8a
39eba88c9f055e9e7ccabafcd8caed25d8b26f3726022973175545f77e4024bcbcc657081ea5d1f2baf5e9080cbb20696135
f2be8834c
Data from external function: 3f9219ae14f9246622973724ace5cb66b190a4b5e86abf482fce5d7889e6aff870741d6
72ff78e7765fada25f150c70e5e61c13b5bcdec634d03830668348b5a7d06cf75f426259dcf804241eb2f4362d10f1ebf23a
1aecca28072a3f38fb8a39eba88c9f055e9e7ccabafcd8caed25d8b26f3726022973175545f77e4024bcbcc657081ea5d1f2
baf5e9080cbb20696135f2be8834c

Have a look here to understand how bind works and here to understand the concept of this and context in javascript.
EDIT: In response to your latest, comment.
if you just wanted to pass the justCrypted from pbkdf2 to the var psw of User.prototype.save, you can use the synchronous version of the same method:
crypto.pbkdf2Sync(password, salt, iterations, keylen[, digest])

Your method will then look like:
User.prototype.save = function (fn){
    var user=this;
    var psw ;
    var crypto = require('crypto');
    var salt = crypto.randomBytes(50).toString('base64');
    psw = crypto.pbkdf2Sync(user.pswrd, salt, 10000, 150, 'sha512');
    var justCrypted = psw.toString('hex');
    console.log(justCrypted);
    ....
    ....
}

The important difference here is that this is an synchronous method and the code will wait for crypto.pbkdf2Sync to finish returning a value before it moves to the next line, thus following a sequential flow.
Hope that helps.
EDIT 2: Here is a little diagram of how async works:

Unfortunately, you just can't do it the way you want without using an external function or a synchronous function.


Q: file upload and download with servlet I want to write an simple java servlet which receives file upload from a simple html page, does something with the file and sends back the manipulated file to the user.
The file upload event is handled by doPost method of a servlet on the server side. The requirements is that "Save as..." window needs to be appear immediately after the file is uploaded and processed on the server side and user can save the generated file to his/her computer.
File upload is handled by doPost and file download is handled by doGet method of a servlet. Is it possible to boundle these two events together somehow?
Can I receive byte content as a response of a file upload event? I upload file with ajax post and I can send back content to the browser and I can show this message on the client side.
Is it possible to write a clever java script code which receives binary content as a response of a post request and forces the web browser to pop up the "save as..." window for save the received bytes to a file?
Another solution could be

*

*file upload with ajax

*on the server side the new generated content is saved to a file into a temporary directory

*id or path of the file on the server is sent back to the client as a response

*client (java script) receives the id of the generated file and makes a new GET request immediately to a file download servlet

*file download servlet receives the id/path of the file and reads it from the temp folder and send i bact to the client web browser.

What is the best practice for this scenario?


Q: What is the importance of collections framework in java for the programming of android and how to benefit from it How to use true data structure in android programming I need good learning resources and examples of applying data structure in certain functions

A: The collections framework was designed to meet several goals, such as −

*

*The framework had to be high-performance. The implementations for the fundamental collections (dynamic arrays, linked lists, trees, and hashtables) were to be highly efficient.

*The framework had to allow different types of collections to work in a similar manner and with a high degree of interoperability.

*The framework had to extend and/or adapt a collection easily.

A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following −
Interfaces − These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy.
Implementations, i.e., Classes − These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.
Algorithms − These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface.
For More Details you can find documents on ORACLE's Collection Documents


Q: Numpy array to Pandas data frame formatting Sorry if this has already been answered somewhere!
I am trying to format an array in numpy to a data frame in pandas, which I have done like so:
# array
a = [[' ' '0' 'A' 'T' 'G']
    ['0' 0 0 0 0]
    ['G' 0 -3 -3 5]
    ['G' 0 -3 -6 2]
    ['A' 0 5 0 -3]
    ['A' 0 5 2 -3]
    ['T' 0 0 10 5]
    ['G' 0 -3 5 15]]

# Output data frame using pandas

   0  1   2   3   4
0     0   A   T   G
1  0  0   0   0   0
2  G  0  -3  -3   5
3  G  0  -3  -6   2
4  A  0   5   0  -3
5  A  0   5   2  -3
6  T  0   0  10   5
7  G  0  -3   5  15

# Output I want

   0   A   T   G
0  0   0   0   0
G  0  -3  -3   5
G  0  -3  -6   2
A  0   5   0  -3
A  0   5   2  -3
T  0   0  10   5
G  0  -3   5  15

Any advice on how to do this would be appreciated! :)

A: Declare the first row to be column names and the first column to be row names:
df = pd.DataFrame(data=a[1:], columns=a[0]).set_index(' ')
df.index.name = None
#   0  A  T  G
#0  0  0  0  0
#G  0 -3 -3  5
#G  0 -3 -6  2
#A  0  5  0 -3


Q: Java - Saving StringTokenizer into arrays for further processing in other methods I've been coding Perl and Python a lot and this time I got an assignment to code in Java instead. So I'm not too familiar with handling data in Java.
My task involves having a input file where I need to check dependencies and then output those with transitive dependencies. Clearer ideas below:
Input File:
A: B C
B: C E
C: G
D: A

Output File:
A: B C E G
B: C E G
C: G
D: A B C E G

So far this is what I've got (separating the first and second token):
import java.util.StringTokenizer;
import java.io.*;

public class TestDependency {

    public static void main(String[] args) {

        try{

        FileInputStream fstream = new FileInputStream("input-file");
        BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
            String strLine;

        while ((strLine = br.readLine()) != null)   {
            StringTokenizer items = new StringTokenizer(strLine, ":");

            System.out.println("I: " + items.nextToken().trim());

            StringTokenizer depn = new StringTokenizer(items.nextToken().trim(), " ");

                while(depn.hasMoreTokens()) {
                    System.out.println( "D: " + depn.nextToken().trim() );
            }
        }

        } catch (Exception e){//Catch exception if any
        System.err.println("Error: " + e.getMessage());
        }
    }
}

Any help appreciated. I can imagine Perl or Python to handle this easily. Just need to implement it in Java.

A: This is not very efficient memory-wise and requires good input but should run fine.
public class NodeParser {

    // Map holding references to nodes
    private Map<String, List<String>> nodeReferenceMap;

    /**
     * Parse file and create key/node array pairs
     * @param inputFile
     * @return
     * @throws IOException
     */
    public Map<String, List<String>> parseNodes(String inputFile) throws IOException {

        // Reset list if reusing same object
        nodeReferenceMap = new HashMap<String, List<String>>();

        // Read file
        FileInputStream fstream = new FileInputStream(inputFile);
        BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
        String strLine;

        // Parse nodes into reference mapping
        while((strLine = br.readLine()) != null) {
            // Split key from nodes
            String[] tokens = strLine.split(":");
            String key = tokens[0].trim();
            String[] nodes = tokens[1].trim().split(" ");
            // Set nodes as an array list for key
            nodeReferenceMap.put(key, Arrays.asList(nodes));
        }

        // Recursively build node mapping
        Map<String, Set<String>> parsedNodeMap = new HashMap<String, Set<String>>();
        for(Map.Entry<String, List<String>> entry : nodeReferenceMap.entrySet()) {
            String key = entry.getKey();
            List<String> nodes = entry.getValue();
            // Create initial node set
            Set<String> outSet = new HashSet<String>();
            parsedNodeMap.put(key, outSet);
            // Start recursive call
            addNode(outSet, nodes);
        }

        // Sort keys
        List<String> sortedKeys = new ArrayList<String>(parsedNodeMap.keySet());
        Collections.sort(sortedKeys);

        // Sort nodes
        Map<String, List<String>> sortedParsedNodeMap = new LinkedHashMap<String, List<String>>();
        for(String key : sortedKeys) {
            List<String> sortedNodes = new ArrayList<String>(parsedNodeMap.get(key));
            Collections.sort(sortedNodes);
            sortedParsedNodeMap.put(key, sortedNodes);
        }

        // Return sorted key/node mapping
        return sortedParsedNodeMap;
    }

    /**
     * Recursively add nodes by referencing the previously generated list mapping
     * @param outSet
     * @param nodes
     */
    private void addNode(Set<String> outSet, List<String> nodes) {
        // Add each node to the set mapping
        for(String node : nodes) {
            outSet.add(node);
            // Get referenced nodes
            List<String> nodeList = nodeReferenceMap.get(node);
            if(nodeList != null) {
                // Create array list from abstract list for remove support
                List<String> referencedNodes = new ArrayList<String>(nodeList);
                // Remove already searched nodes to prevent infinite recursion
                referencedNodes.removeAll(outSet);
                // Recursively search more node paths
                if(!referencedNodes.isEmpty()) {
                    addNode(outSet, referencedNodes);
                }
            }
        }
    }
}

Then, you can call this from your program like so:
    public static void main(String[] args) {
        try {
            NodeParser nodeParser = new NodeParser();
            Map<String, List<String>> nodeSet = nodeParser.parseNodes("./res/input.txt");
            for(Map.Entry<String, List<String>> entry : nodeSet.entrySet()) {
                String key = entry.getKey();
                List<String> nodes = entry.getValue();
                System.out.println(key + ": " + nodes);
            }
        } catch (IOException e){
            System.err.println("Error: " + e.getMessage());
        }
    }

Also, the output is not sorted but that should be trivial.

A: String s = "A: B C D";
String i = s.split(":")[0];
String dep[] = s.split(":")[1].trim().split(" ");
System.out.println("i = "+i+", dep = "+Arrays.toString(dep));


Q: change size of kendo window when pressing the "minimize" button I'm trying to change the width of a kendoui window when the "minimize" button is pushed.  I'm new to kendo and coulnd't find the help in their docs.
Here's the code I've got:
HTML:
Some data here

var thewindow = $("#recon_cont_div");
thewindow.kendoWindow({
                          actions: ["Minimize", "Maximize", "Pin", "Close"],
                          width: "100%",
                          height: "100%",
                          draggable: true,
                          resizable: true,
                          minimize: function(e) {
                                debugger;
                                thewindow.data("kendoWindow").setOptions({width: 250});
                          },

                           close: function(e) {
                            alert("window will close now")
                          },

                          title: "The window"
                    }).data("kendoWindow");

When the "minimize function" runs, the window does not resize...it does nothing?
Any help is appreciated. thanks.

A: The window wrapper is the one you need to change:
$("#dialog").kendoWindow({
  actions: ["Minimize"],
  minimize: function(e) {
    $("#dialog").getKendoWindow().wrapper.css({
        width: 200
    });
  }
});

Example: Window size change


Q: Should "/users" and "/users/" point to the same (RESTful) resource? They do in this and probably any other website, but I'm not sure I understand why.
A popular analogy compares RESTful resources to files in the file system and filename users wouldn't point to the same object as filename users/ static web pages and in a static website users would point to users.html and users/ - to a different file - users/index.html.

A:
filename users wouldn't point to the same object as filename users/.

That is not true. In most filesystems, you cannot have a file named users and a directory named users in the same parent directory.
cd users and cd users/ have the same result.

A: Short answer: they may only identify the same resource if one redirects to the other.
URI's identify resources, but they do so differently depending on the response status code to a GET request in HTTP. If one returns a 3xx to the other, then the two URI's identify the same resource. If the two resources each return a 2xx code, then the URI's identify different resources. They may return the same response in reply to a GET request, but they are not therefore the same resource. The two resources may even map to the same handler to produce their reply, but they are not therefore the same resource. To quote Roy Fielding:

The resource is not the storage object. The resource is not a
mechanism that the server uses to handle the storage object. The
resource is a conceptual mapping -- the server receives the identifier
(which identifies the mapping) and applies it to its current mapping
implementation (usually a combination of collection-specific deep tree
traversal and/or hash tables) to find the currently responsible
handler implementation and the handler implementation then selects the
appropriate action+response based on the request content.

So, should /users and /users/ return the same response? No. If one does not redirect to the other, then they should return different responses. However, this is not itself a constraint of REST. It is a constraint, however, which makes networked systems more scalable: information that is duplicated in multiple resources can get out of sync (especially in the presence of caches, which are a constraint of REST) and lead to race conditions. See Pat Helland's Apostate's Opinion for a complete discussion.
Finally, clients may break when attempting to resolve references relative to the given URI. The URI spec makes it clear that resolving the relative reference Jerry/age against /users/ results in /users/Jerry/age, while resolving it against /users (no trailing slash) results in /Jerry/age. It's amazing how much client code has been written to detect and correct the latter to behave like the former (and not always successfully).
For any collection (which /users/ often is), I find it best to always emit /users/ in URI's, redirect /users to /users/ every time, and serve the final response from the /users/ resource: this keeps entities from getting out of sync and makes relative resolution a snap on any client.

A: There are some nuances on this, while "users" represent one resource while "users/" should represent a set of resources, or operations on all resources "users"... But there does not seem to exist a "standard" for this issue.
There is another discussion on this, take a look here: https://softwareengineering.stackexchange.com/questions/186959/trailing-slash-in-restful-api

A: Technically they are not the same. But a request for /users will probably cause a redirect to /users/ which makes them semantically equal.
In terms of JAX-RS @Path, they can both be used for the same path.


Q: Make Cocoa application respond to simple AppleScript command I am trying to add a trivial AppleScript support to a Cocoa application. The application performs a check periodically and I just want to be able to tell it to perform it on demand.
I am trying to follow the SimpleScriptingVerbs Apple example.
I have subclassed NSScriptCommand as follows:
Header:
#import <Cocoa/Cocoa.h>

@interface rdrNotifierUpdateCommand : NSScriptCommand {

}
-(id)performDefaultImplementation;
@end

Implementation:
#import "rdrNotifierUpdateCommand.h"
#import "rdrNotifierAppDelegate.h"

@implementation rdrNotifierUpdateCommand

-(id)performDefaultImplementation {
  NSLog(@"Works at last");
  [((rdrNotifierAppDelegate *)[[NSApplication sharedApplication] delegate])
   checkForNewItems];  // This just fires the timer
  return nil;
}
@end

My .sdef file goes as follows (and the problem seems to be there, but I cannot find it):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude">
    <xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/>
    <suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities.">
        <command name="do update" code="rdrNUpdt" description="Check for new items">
            <cocoa class="rdrNotifierUpdateCommand"/>
        </command>
    </suite>
</dictionary>

The Info.plist is set up appropriately.
But, when I try to run the following script in AppleScript editor:
tell application "rdrNotifier"
    do update
end tell

I receive an error about variable "update" not being defined.
I can open the dictionary for my application from AppleScript Editor (i.e. it is successfully registered).
Edit: Found a solution
The problem was indeed in the sdef file: I was not specifying that the application can reply to the command. My final definition goes as follows (Obj-C code unchanged):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Dictionary" xmlns:xi="http://www.w3.org/2003/XInclude">
  <!-- I have removed the standard suite as the application does not open, print... -->
  <suite name="rdrNotifier Suite" code="rdrN" description="rdrNotifier application specific scripting facilities.">
    <command name="do update" code="rdrNUpdt" description="Check for new items">
      <cocoa class="rdrNotifierUpdateCommand"/>
    </command>
    <class name="application" code="Capp">
      <cocoa class="NSApplication"/>
      <responds-to name="do update">
        <!-- Note you need to specify a method here,
             although it is blank -->
        <cocoa method=""/>
      </responds-to>
    </class>
  </suite>
</dictionary>

Any improvements/tips/criticisms are still welcome.

A: Thanks for making the effort of adding applescript support to your app! Just a quick observation / criticism: When constructing terminology, by all means include spaces, but if that terminology takes the form of 'verb noun' (like 'do update') appleScripters will be irritated if the noun 'update' is not a properly modelled object, and if 'do' is not a proper command.
I would argue that 'do' is a poor choice for a command name, because it is very vague. What's wrong with just using 'update' as the command? (i.e. treat it as a verb).
This issue is treated in some detail by Apple's own technote 2106 (currently here), which you definitely should read and digest if you hope to please your AppleScripting user community.
Apple themselves are not beyond stupid terminology choices such as updatePodcast and updateAllPodcasts (in iTunes). These are stupid choices because (according to tn2106) they contain no spaces, and because the better choice would be to have a proper podcast class and then have an update command which could be used on an individual podcast, all podcasts, or a particular chosen set of podcasts.


Q: Cython print() outputs before C printf(), even when placed afterwards I'm trying to pick up Cython.
import counter

cdef public void increment():
    counter.increment()

cdef public int get():
    return counter.get()

cdef public void say(int times):
    counter.say(times)

This is the "glue code" I'm using to call functions from counter.py, a pure Python source code file. It's laid out like this:
count = 0

def increment():
    global count

    count += 1

def get():
    global count

    return count

def say(times):
    global count

    print(str(count) * times)

I have successfully compiled and run this program. The functions work fine. However, a very strange thing occured when I tested this program:
int main(int argc, char *argv[]) {
    Py_Initialize();

    // The following two lines add the current working directory
    // to the environment variable `PYTHONPATH`. This allows us
    // to import Python modules in this directory.
    PyRun_SimpleString("import sys");
    PyRun_SimpleString("sys.path.append(\".\")");

    PyInit_glue();

    // Tests
    for (int i = 0; i < 10; i++)
    {
        increment();
    }

    int x = get();
    printf("Incremented %d times\n", x);

    printf("The binary representation of the number 42 is");
    say(3);

    Py_Finalize();
    return 0;
}

I would expect the program to produce this output:
Incremented 10 times
The binary representation of the number 42 is
101010

However, it prints this:
Incremented 10 times
101010
The binary representation of the number 42 is

But if I change the line
printf("The binary representation of the number 42 is");

to
printf("The binary representation of the number 42 is\n");

then the output is corrected.
This seems strange to me. I understand that if I want to print the output of a Python function, I might just as well return it to C and store it in a variable, and use C's printf() rather than the native Python print(). But I would be very interested to hear the reason this is happening. After all, the printf() statement is reached before the say() statement (I double checked this in gdb just to make sure). Thanks for reading.


Q: How to minimize amount of requests for Google API (places) autocomplete? I am using google API - places to autocomplete locations in AutoCompleteTextView. I did couple of tests maybe 20 searches and in my profile on google devs, it's written that I have made 200 API requests.
I understand that it is making request every time I type something or edit typed text. But is there any way how to reduce amount of calls to server?
One of ideas is to define threshold to 3 characters.

A: If you did not find a better solutions( I know it is very late, but I am doing something similar and I found my self in here.)
I think you can "cache" previous results, put them in ArrayList. And then in your adapter when performFiltering is called, start by checking the results you have in your Arraylist and if you receive a number of similar items, dont make a request to the API. I am not sure if it is clear but you can at least save a couple requests like that and for the user side, the autocomplete is always refreshing.
I hope it helps.

A: I think a better implementation to reduce the number of calls to the Places API would be to put in a delay of maybe 0.75 seconds after the last key-press.  That would avoid confusion on the part of a user who after seeing autocomplete after 3 letters, sits and waits after typing his 5th.


Q: Import csv in Rapidminer is not loading data properly Importing csv in Rapidminer is not loading data properly in the attributes/ columns and returns errors.
I have set the parameter values correctly in the 'Data Import Wizard'.
Column Separation is set to comma and when I check the "Use Quotes" parameter I see that there are too many "?" appear in the columns even though there is data in the actual csv file.
And when I do not check the “Use Quotes” option then I notice that the content of the columns are distributed across different columns, i.e., data does not appear in the correct column. It also gives error for the date column.
How to resolve this? Any suggestions please? I saw a lot of Rapidminer videos and read about it but did not help.
I am trying to import twitter conversations data which I exported from a 3rd party SaaS tool which extracts Twitter data for us.
Could someone help me soon please? Thanks, Geeta

A: It's virtually impossible to debug this without seeing the data.
The use quotes option requires that each field is surrounded by double quotes. Do not use this if your data does not contain these because the input process will import everything into the first field.
When you use comma as the delimiter, the observed behaviour is likely to be because there are additional commas contained in the data. This seems likely if the data is based on Twitter. This confuses the import because it is just looking for commas.
Generally, if you can get the input data changed, try to get it produced using a delimiter that cannot appear in the raw text data. Good examples would be | or tab. If you can get quotes around the fields, this will help because it allows delimiter characters to appear in the field.
Dates formats can be handled using the data format parameter but my advice is to import the date field as a polynominal and then convert it later to date using the Nominal to Date operator. This gives more control especially when the input data is not clean.


Q: Print what is not in a join table I have a join table created from 2 other tables.
Say one model is called cat, another is called request, and the join table is called catrequest (this table would have cat_id and request_id)
How would I print all of the cats not intersected in the join table i.e. all of the cats NOT requested using rails. I saw some DB based answers, but I am looking for a rails solution using ruby code.
I get how to print a cat that belongs to a request i.e.:
<% @requests.each do |request| %>
  <% request.cats.each do |cat| %>
    <%= cat.name %>
<% end %>

but I don't understand how to do the reverse of this.

A: To get a list of cats that have never been requested you'd go with:
Cat.includes(:cat_requests).where(cat_requests: { id: nil })
# or, if `cat_requests` table does not have primary key (id):
Cat.includes(:cat_requests).where(cat_requests: { cat_id: nil })

The above assumes you have the corresponding association:
class Cat
  has_many :cat_requests
end

A: It sounds like what you need is an outer join, and then to thin out the cats rows that don't have corresponding data for the requests? If that's the case, you might consider using Arel. It supports an outer join and can probably be used to get what you're looking for. Here is a link to a guide that has a lot of helpful information on Arel:
http://jpospisil.com/2014/06/16/the-definitive-guide-to-arel-the-sql-manager-for-ruby.html
Search the page for "The More the Merrier" section which is where joins are discussed.


Q: Can I parallelise a Python function that returns None with Ray? I have a function that takes in a filename and creates a symlink in a target directory if that filename exists in the "source" directory:
def _symlink_photos(photo_name: str, photos_dir: Path, target_dir: Path) -> None:
    """
    Given a string, checks if it exists in `photos_dir`,
    then creates a symlink in `target_dir`
    """

    photo_path: Path = photos_dir / photo_name
    if photo_path.exists():
        (target_dir / photo_name).symlink_to(photo_path)

This function is meant to be used to iterate over a somewhat big list of filenames (some 70k), like so:
def main() -> None:
    """
    Given a list of photos, checks if they exist in the source directory,
    and symlinks them into the target directory.
    """

    for photo_name in tqdm(photo_list):
        _symlink_photos(photo_name, photo_dir, target_dir)

The brute-force/for-loop approach is taking me too long (tqdm estimates over a day), so I was wondering how to parallelise this job. I knew I could use ray, but in order to use it I would need to write my code like this:
futures = [_symlink_photos.remote(photo_name, photo_dir, target_dir) for photo in photo_list]
result = ray.get(futures)

Yet this does not make sense to me, as my function does not return anything. Can I still use ray? Should I switch to something else, like joblib/threading?
Another alternative I was thinking of is to parallelise the "check if photo_name exists in the source dir" part with ray, i.e. to retrieve the list of photos that actually are in the target directory. Only then I would create the symlinks, hopefully taking less time...

A: You can use Ray in the way that you described. The ray.get call will simply return a list of None values, which you can ignore.
You can also look up ray.wait which can be used to wait for certain tasks to finish without actually retrieving the task outputs.


Q: DirectX 2D grid I have been trying to get a 2D grid going. It's for a game map.
Unfortunately, the grid is not as it should be. And I cannot figure out why.
Does anyone have an idea?
Imports Microsoft.DirectX
Imports Microsoft.DirectX.Direct3D

Public Class clsIsometric

'==================================
' SETTINGS
'==================================

Private tile_size As New Point(64, 64) 'Size of one tile in pixels
Private map_size As New Point(25, 25) 'Amount of tiles in total

Private gDevice As Device
Private bufVertex As VertexBuffer
Private bufIndex As IndexBuffer
Private gVertices() As CustomVertex.TransformedColored
Private gIndices() As Integer

'==================================
' CONSTRUCTOR
'==================================

Public Sub New(vDevice As Device)

    gDevice = vDevice

End Sub

Public Sub dispose()

    bufVertex.Dispose()
    bufIndex.Dispose()
    bufVertex = Nothing
    bufIndex = Nothing

End Sub

'==================================
' RENDERING
'==================================

Public Sub buildMap()

    ' Recreate buffers to fit the map size
    ReDim gVertices((map_size.X + 1) * (map_size.Y + 1))    ' x+1 * y+1
    ReDim gIndices(map_size.X * map_size.Y * 6)             ' x * y * 6
    Dim k As Integer

    For cX = 0 To map_size.X - 1 'Rows
        For cY = 0 To map_size.Y - 1 'Columns

            'VERTEX
            k = cX * map_size.X + cY
            gVertices(k) = New CustomVertex.TransformedColored(cX * tile_size.X, cY * tile_size.Y, 0, 1, Color.Blue.ToArgb)

        Next cY
    Next cX

    Dim vertexPerCol As Integer = map_size.Y + 1

    k = 0
    For ccX = 0 To map_size.X - 1
        For ccY = 0 To map_size.Y - 1

            gIndices(k) = ccX * vertexPerCol + ccY                  ' 0
            gIndices(k + 1) = (ccX + 1) * vertexPerCol + (ccY + 1)  ' 1
            gIndices(k + 2) = (ccX + 1) * vertexPerCol + ccY        ' 2

            gIndices(k + 3) = ccX * vertexPerCol + ccY              ' 3
            gIndices(k + 4) = ccX * vertexPerCol + (ccY + 1)        ' 4
            gIndices(k + 5) = (ccX + 1) * vertexPerCol + (ccY + 1)  ' 5

            k += 6 'Each tile has 6 indices. Increase for next tile

        Next
    Next

    bufVertex = New VertexBuffer(GetType(CustomVertex.TransformedColored), gVertices.Length, gDevice, Usage.Dynamic Or Usage.WriteOnly, CustomVertex.TransformedColored.Format, Pool.Default)
    bufIndex = New IndexBuffer(GetType(Integer), gIndices.Length, gDevice, Usage.WriteOnly, Pool.Default)

End Sub

Public Sub render()

    'RENDER THE MAP

    bufVertex.SetData(gVertices, 0, LockFlags.ReadOnly)
    bufIndex.SetData(gIndices, 0, LockFlags.None)

    gDevice.VertexFormat = CustomVertex.TransformedColored.Format
    gDevice.SetStreamSource(0, bufVertex, 0)
    gDevice.Indices = bufIndex
    gDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, gVertices.Length, 0, CInt(gIndices.Length / 3))

End Sub

End Class

This should output a perfect square grid of 25 by 25 tiles. But the wireframe looks like:
http://i43.tinypic.com/2whf51c.jpg

A: Your loop which build the vertices seems to end too early, because you have n+1 vertices each row/column. It fills the array only to the forelast column, which leads to a shift in the vertices.
For cX = 0 To map_size.X 'Rows
    For cY = 0 To map_size.Y 'Columns

        'VERTEX
        k = cX * (map_size.X + 1) + cY
        gVertices(k) = New CustomVertex.TransformedColored(cX * tile_size.X, cY * tile_size.Y, 0, 1, Color.Blue.ToArgb)

    Next cY
Next cX


Q: What does a function of proper time mean and how do you transform from proper time to real time? A covariant formulation of electromagnetism says the equation of motion of a charged particle in an electromagnetic field is $$m\frac{du_\mu}{d\tau} = qF_{\mu\nu}u^\nu.$$
But this equation is in terms of the proper time of the particle. After solving for the 4-velocity, you have a function in terms of proper time: $u_\mu(\tau)$. How does one go back to lab-frame's time, that is, get to a function $u_\mu(t)$?
The only other rule I can think of is that proper time intervals is related to lab-frame time intervals by $d\tau = dt/\gamma$. But since these are time intervals, I'm hesitant to just substitute $t/\gamma$ everywhere for $\tau$ in the function $u_\mu(\tau)$.
In fact, that proper time is only defined in terms of intervals (at least, this is what it seems to me) makes me wonder what is the exact meaning of $u_\mu(\tau)$ is. Is it the 4-velocity at every moment in time (not interval, but moment) according to the particle's clock?

A: If you have found $u^\mu(\tau)$ then you know $\gamma(\tau)=u^0(\tau)$. You can then integrate $dt=\gamma(\tau)d\tau$ to get $t(\tau)$ and invert it to get $\tau(t)$.


Q: How to convert a MediaWiki installation using MySQL to SQLite? We're running a small own MediaWiki installation based on MySQL here. For simplicity reasons it would be great to convert this installation to an SQLite variant as it then would not require a separate data base instance.
What I'm looking for is a way of how to accomplish this. One idea would be that we could create an XML dump of the data somehow and reinsert it later again. But MediaWiki claims that such dump would not cover the complete data: We'd use user accounts, edit logs and other stuff.
Has anyone any experience in doing such a conversion? What do you think would be the best approach for this?

A: There is a mysql2sqlite.sh script on GitHub
write the script like this,
./mysql2sqlite.sh myDbase | sqlite3 database.sqlite

If you want to know other ways to convert, refer this


Q: What do you call an application that does not come with an installer? what you call a software that requires no installation only unzipping like eclipse where it has no installation only we have to unzip and also for uninstalling just delete the Workspace.

A: That's typically called a portable application.


Q: MomentJs giving NaN result I'm trying to count the days from current date to a certain date, and i'm using momentJs to do it, the problem is that it's giving me NaN result, maybe because of the date formatting!
I'm fetching the end date from an api, and it's in this format "DD MM YYYY" "16/12/2023" but in moment I don't know how it's formatted, some help would be appreciated.
The code i'm using
const start = moment();
  const end = moment(post.validTill);
  const diff = end.diff(start, "days");

I just want to get the days from current date till the end date !

A: You can calculate the duration and request the value in days.

const
  diffInDays = (start, end) => moment.duration(end.diff(start)).asDays(),
  dateFormat = 'DD MM YYYY',
  nextWeek   = moment().add(1, 'weeks').format(dateFormat),
  post       = { validTill: nextWeek },
  diff       = diffInDays(moment(), moment(post.validTill, dateFormat));

console.log('Start of next week:', nextWeek);
console.log('Days until:', diff); // 6.xxx (days)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>


Q: Asp Core 3 - How to allow nullable [FromBody] object in controller method Let's say I have a simple controller with one POST method that accepts an object from its body. However, the presence of this object should be optional in the HTTP request body. I tried to implement this behavior with the following code
public class User
{
    public string Name { get; set; }
}

[ApiController]
[Route("[controller]")]
public class GreetingController : ControllerBase
{
    [HttpPost]
    public string SayHello([FromBody] User user = null)
    {
        return "Hello " + user?.Name;
    }
}

If I make a request with an object in the body, everything works fine. But with this configuration, it is unable to make a POST request with empty body. If I create a request without Content-Type header (as there is actually no content), I get the following error:
{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.13",
    "title": "Unsupported Media Type",
    "status": 415,
    "traceId": "|192e45d5-4bc216316f8d3966."
}

if the Content-Type header has value application/json then the response looks like this:
{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "traceId": "|192e45d6-4bc216316f8d3966.",
    "errors": {
        "": [
            "A non-empty request body is required."
        ]
    }
}

So, how to make the object optional in the request body? It is quite common problem and I am curious if there is a simple solution for that in ASP Core 3. I don't want to read the object from Request stream and deserialize it on my own.

A: Right now, the only way is via a global option, MvcOptions.AllowEmptyInputInBodyModelBinding. It defaults to false, so you just need to do:
services.AddControllers(o =>
{
    o.AllowEmptyInputInBodyModelBinding = true;
});

A: There is now an easier way (since 5.0-preview7)
You can now achieve this per action method, by configuring a FromBodyAttribute property named EmptyBodyBehavior
Demonstration:
public IActionResult Post([FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] MyModel model)

Thanks to LouraQ's comment, which guided me towards the above answer on github

A: I'm not sure about your final intention, but if you don't want to choose the content-type, you can pass an empty json string.
At this time, the user is not empty, but the content of it's field's value is null, and the final result is the same. Maybe you You can try it.
Here is the debug process with the postman:


Q: String that contains $1 I have a script that scrolls through all the folders of unzipped files and get information of the contents.
The problem is in the name of files such as:
filename="SearchView$10.smali"

Because if I want to get the stats the $1 in the string disappears,and I get the following error:
    subprocess.check_output("stat "+ filename,shell=True)
cannot open `SearchView0.smali' (No such file or directory)

How can I fix it?

A: Avoid shell=True, it leads to security issues. And it is also at the root of your problem, as the $1 is interpreted.
Do this instead:
subprocess.check_output(["stat", filename])


Q: Only some Font Awesome glyphs display in WPF I am attempting to use Font Awesome in a WPF app.  It half works. That is, some glyphs are picked up and show, others show a rectangle.
I'm following guides correctly, I think, but something is going wrong!
Here's a code snippet
<Window.Resources>
    <FontFamily x:Key="FontAwesomeRegular">Fonts/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free Regular</FontFamily>
    <FontFamily x:Key="FontAwesomeBrands">Fonts/Font Awesome 5 Brands-Regular-400.otf#Font Awesome 5 Brands Regular</FontFamily>
    <FontFamily x:Key="FontAwesomeSolid">Fonts/Font Awesome 5 Free-Regular-400.otf#Font Awesome 5 Free Solid</FontFamily>
</Window.Resources>

<Grid>
    <StackPanel Orientation="Vertical">
    <TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="" HorizontalAlignment="Left" Foreground="Red" Margin="0" TextWrapping="Wrap" VerticalAlignment="Center" FontSize="100"/>
    <TextBlock FontFamily="{StaticResource FontAwesomeSolid}" Text="" HorizontalAlignment="Left" Foreground="Red" Margin="0" TextWrapping="Wrap" VerticalAlignment="Center" FontSize="100"/>
    </StackPanel>
</Grid>

The fonts are installed in a Fonts directory

And Marked as Resource

And this is what it shows on the screen

You can see that the first icon xf15c; displays as expected but the second one xf15a; does not.  Generally, most do not display.
Why?

A: If you open the .otf file, you can see the name of the font. This is what you need to use to the FontFamily resource, without the file extension.
Try the following code:
<FontFamily x:Key="Icons">pack://application:,,,/{YOUR PROJECT NAME};component/Fonts/#Font Awesome 5 Free Solid</FontFamily>


Q: Backbone: event lost in re-render I have super-View who is in charge of rendering sub-Views. When I re-render the super-View all the events in the sub-Views are lost.
This is an example:
var SubView = Backbone.View.extend({
    events: {
        "click": "click"
    },

    click: function(){
        console.log( "click!" );
    },

    render: function(){
        this.$el.html( "click me" );
        return this;
    }
});

var Composer = Backbone.View.extend({
    initialize: function(){
        this.subView = new SubView();
    },

    render: function(){
        this.$el.html( this.subView.render().el );
    }
});

var composer = new Composer({el: $('#composer')});
composer.render();

When I click in the click me div the event is triggered. If I execute composer.render() again everything looks pretty the same but the click event is not triggered any more.
Check the working jsFiddle.

A: When you do this:
this.$el.html( this.subView.render().el );

You're effectively saying this:
this.$el.empty();
this.$el.append( this.subView.render().el );

and empty kills the events on everything inside this.$el:

To avoid memory leaks, jQuery removes other constructs such as data and event handlers from the child elements before removing the elements themselves.

So you lose the delegate call that binds events on this.subView and the SubView#render won't rebind them.
You need to slip a this.subView.delegateEvents() call into this.$el.html() but you need it to happen after the empty(). You could do it like this:
render: function(){
    console.log( "Composer.render" );
    this.$el.empty();
    this.subView.delegateEvents();
    this.$el.append( this.subView.render().el );
    return this;
}

Demo: http://jsfiddle.net/ambiguous/57maA/1/
Or like this:
render: function(){
    console.log( "Composer.render" );
    this.$el.html( this.subView.render().el );
    this.subView.delegateEvents();
    return this;
}

Demo: http://jsfiddle.net/ambiguous/4qrRa/
Or you could remove and re-create the this.subView when rendering and sidestep the problem that way (but this might cause other problems...).

A: There's a simpler solution here that doesn't blow away the event registrations in the first place: jQuery.detach().
http://jsfiddle.net/ypG8U/1/
this.subView.render().$el.detach().appendTo( this.$el );

This variation is probably preferable for performance reasons though:
http://jsfiddle.net/ypG8U/2/
this.subView.$el.detach();

this.subView.render().$el.appendTo( this.$el );

// or

this.$el.append( this.subView.render().el );

Obviously this is a simplification that matches the example, where the sub view is the only content of the parent. If that was really the case, you could just re-render the sub view. If there were other content you could do something like:
var children = array[];

this.$el.children().detach();

children.push( subView.render().el );

// ...

this.$el.append( children );

or
_( this.subViews ).each( function ( subView ) {

  subView.$el.detach();

} );

// ...

Also, in your original code, and repeated in @mu's answer, a DOM object is passed to jQuery.html(), but that method is only documented as accepting strings of HTML:
this.$el.html( this.subView.render().el );

Documented signature for jQuery.html():
.html( htmlString )

http://api.jquery.com/html/#html2

A: When using $(el).empty() it removes all the child elements in the selected element AND removes ALL the events (and data) that are bound to any (child) elements inside of the selected element (el).
To keep the events bound to the child elements, but still remove the child elements, use:
$(el).children().detach(); instead of $(.el).empty();
This will allow your view to rerender successfully with the events still bound and working.


Q: DocuSign field mandatory/not mandatory per REST request I have a question: is it possible to choose a field to be mandatory or not mandatory per DocuSign REST request when we are forming an envelope?
In some cases I need field to be mandatory, in other - not (or even not usable)

A: Yes, document tabs have parameters required which can be set to true or false.
They also have the parameter readOnly which can also be set to true or false
The API reference has all the parameters in it


Q: Why cannot I create a file in a folder I own with chmod 655, but 755 works? I have a backup folder owned by a system user (mongodb) and chmoded 655. When I try to create files in it, it raises a permission issue:
root@maquina:/var/backups/mongodb# su -s /bin/bash mongodb -c "/usr/bin/touch test.txt"
/usr/bin/touch: cannot touch `test.txt': Permission denied

Chmoding to 755 enables me to create the file.
I guess I probably need to tweak the privileges (+X ?) but cannot find how.
Can anyone shed some light on this ?
Thank you!

A: You need to have execute permissions in the directory in order to do seeks there. Without being able to do a seek, you can't create a file
sudo chmod u+x /var/backups/mogodb


Q: PhantomJS driver is not clicking on element in page, but no errors thrown Lately I have faced on issue with latest phantomjs driver and selenium in java development, so issue is this , we have a web site with list of users where every line of user have a delete button which have js action onclick(). What we are trying to do is to simply remove user, but it is not working on phantomjs, but works perfectly on chrome driver. Note that after clicking on delete button js alert is shown with yes/no, so it must be accepted also.
So here is our current code:
FindBy(css = ".glyphicon.glyphicon-trash.text-blue")
private WebElement customerRemoveButton;
.
.
.
.
Actions mouseAction = new Actions(driver);
mouseAction.moveToElement(customerRemoveButton);
mouseAction.click();
mouseAction.build().perform();
acceptAlert();

driver is properly initialised  (cause obviously for chrome driver it is working perfectly), note that we already tried with clicking on button with JS Executor of webdriver and ofc with click().
So, when we execute it via chrome, user successfully removed, when via phantomjs test is passing without any single issue, but user is not removed.

A: Phantom JS something act weirdly. Check if you have a overlay of custom element over html element. if so try to click on custom element and not on actual html element.
if it doesn't work try to click using Javascript, that is you best bet.


Q: Integral of the Laplace Beltrami operator multiplied by the Heaviside function Let $f \in W^{2,1}_p(U \times [0,T])$ where $U$ is a $C^2$ compact manifold. I'm having a really hard time understanding why the following computation is valid:

$\int_{U} H_\delta(f) \Delta_U f=-\int_U H_\delta'(f) {\vert \nabla f
 \vert }^2 (1)$

where $\Delta_U$ denotes the Laplace Beltrami operator and $H_\delta$ stands for a smooth approximation of the Heaviside function such that $\lim_{\delta \to 0^+} H_{\delta}=H$ in the sense of distributions.
I know that in any compact manifold $M$ it holds (as a consequence of the divergence theorem):
$\int_{M} f\Delta_M f=-\int_M {\vert \nabla f \vert }^2 (2)$
Although it seems that $(1),(2)$ are strongly related, I can't conclude $(1)$ at the end! Probably I'm missing something about $H_\delta$
I'm really stuck here so I'd appreciate any help.
Thanks in advance!

A: You need to use (assume that $U$ has no boundary, of $f$ vanishes at the boundary)
$$\int_U \nabla g \cdot \nabla f d\mu = \int g \Delta f d\mu$$
with the chain rule  $\nabla (H_\delta (f)) = H_\delta '(f) \nabla f$.


Q: How to load a text file and store into data structure I have a 'text' file having content as follows:
012abc3cb7503bddef3ff59e0e52fd79.jpg 160.073318 18.588472 14.246923 8.054444 6.600504 6.261390 5.838249 4.447019 3.639888 3.357715 2.996645 2.910991 2.574769 2.527163 2.343448 2.264113 2.176161 2.088773 1.915582 1.902159 1.836033 1.725432 1.667595 1.633245 1.557424 1.542059 1.434280 1.430181 1.321047 1.302652 1.272890 1.261313 1.188892 1.138115 1.114376 1.070352 1.044311 1.025954 0.993622 0.988920 0.969866 0.933977 0.931669 0.913624 0.882856 0.876036 0.840088 0.822686 0.814072 0.787075 0.781157 0.778171 0.763771 0.748851 0.740975 0.708208 0.691589 0.688566 0.664124 0.659779 0.644820 0.623200 0.614799 0.607180 0.590615 0.578751 0.57...........

Each row represents an image (instance) with the first column being image name, remaining 240 columns being the feature-vector of the image.
How can I load this file in MATLAB and store the image names into 'names' variable and the 240 values into a 'histogram' variable?

A: You might be able to do it with textscan and repmat so you can avoid conversion from strings:
Nfeatures = 240;
fid = fopen('text.txt');
format = ['%s ' repmat('%f', [1 Nfeatures])];
imageFeatureCell = textscan(fid, format, 'CollectOutput', true);
fclose(fid);

A test on a file with 7 rows:
>> fileData
fileData =
    {7x1 cell}    [7x240 double]

Move into your desired variables:
names = fileData{1};      % names{1} contains first file name, etc.
histogram = fileData{2};  % histogram(1,:) contains first file's features

A: str = textread('tmp.txt','%s');
str = reshape(str,241,[]).';
names = str(:,1); %'// cell array of strings with image names
histogram = str2double(str(:,2:end)); %// each row refers to an image


Q: How to display relation table in php? How to display relation table in php using oracle 11g with index format
this is my code:
$stid = oci_parse($conn, 'SELECT * FROM HOTEL');
oci_execute($stid);

while (($row = oci_fetch_array($stid, OCI_BOTH)) != false) {
    $id_hotel = $row['ID_HOTEL'];
    $nama = $row['NAMA_HOTEL'];
    $kamar = $row->KAMAR_ID['NAMA_KAMAR'];
    $harga = $row['HARGA'];
    $gambar = $row['GAMBAR'];
    $lat = $row['LAT'];
    $lng = $row['LNG'];

    echo ("addMarker($lat, $lng, '
$nama - $kamar
 Rp.$harga
Lihat Hotel
');\n");
}

oci_free_statement($stid);
oci_close($conn);


Q: Trouble scraping email information from a website I wish to get persmission to use the images on www.confluence.org for an art project but i need to do that by going to each individual member and asking for thier permission. There is about 10,000 people on the site.
I want to use BeautifulSoup to scrape the site for all the emails, so i can send one mass email instead of 1 email 10,000 times.
The problem however is the email is not written into the the html using text, but what i assume is a php file....located inside an img src.

<img src="visitormailimg.php?id=851" border="0" alt>

and an example of how this appears on the site is
I initially thought of the above email as a simple image that I could run through tesseract to get  the text version of the email, but tesseract doesn't recognize it as an image object. I can click and download the php file as an image manually, but i cant figure out how to do something similar when scraping
Then i saved the webpage onto a folder on my desktop and opened the saved php file visitormailimg.php. Except when opened it i get "the file is not displayed in the editor because it is either binary or uses unsupported text encode" in vscode.
So i am at this stage unsure of how to proceed scraping ww.confluence.org website. Is it an image problem...is it a php problem? Any suggestions?


Q: SQL Server get a JSON of all distinct columns grouped by a different column I have a table that looks like this:

What I want to do is convert it to a JSON that has all distinct years as keys, and an array of Make as value for each key. So based on the image, it would be something like this:
{ "1906": ["Reo", "Studebaker"], "1907": ["Auburn", "Cadillac", "Duryea", "Ford"], ... }
Could someone please help me on how to write a query to achieve this? I've never worked with converting SQL -> JSON before, and all I know is to use FOR JSON to convert a query to JSON.

A: I managed to solve this for whoever needs something similar. However, I think this way is inefficient and I would love for someone to tell me a better method.
I first ran this SQL query:
WITH CTE_Make AS
(
  SELECT [Year], [Make]
  FROM VehicleInformation
  GROUP BY [Year], [Make]
)
SELECT
  ( SELECT
  [Year] AS Year,
  STRING_AGG([Make],',') AS MakeList
  FOR JSON PATH,
  WITHOUT_ARRAY_WRAPPER)
FROM CTE_Make
GROUP BY [Year]

This gave me the JSON in a different format from what I wanted. I stored this in a file "VehicleInformationInit.json", and loaded it in JS as variable vehicleInfoInitJsonFile and ran the following code in JavaScript:
var dict = {};
$.getJSON(vehicleInfoInitJsonFile, function
    (result) {
    result.forEach(x => {
        var makeList = x.MakeList.split(',');
        dict[x.Year] = makeList;
    })

    var newJSON = JSON.stringify(dict);
});

I simply copied the contents of newJSON by attaching a debugger into my required file. However, you can easily use fs and store it in a file if you want to.


Q: Java Array of InnerClass throwing java.lang.NoSuchFieldError I am trying to brushup java after a long time.
Any help is much appreciated.
For demonstration I have Animal Class that has an array of innerclass of Organs.
public class Animal
   {
    String nameOfAnimal;
    Organs [] vitalOrgans = new Organs[3];

    public Animal()
    {
    }

    public String getNameOfAnimal() {
        return nameOfAnimal;
    }

    public void setNameOfAnimal(String nameOfAnimal) {
        this.nameOfAnimal = nameOfAnimal;
    }

    @Override
    public String toString() {
        return "Animal{" + "nameOfAnimal=" + nameOfAnimal + "}";
    }
class Organs{

String nameOfOrgan;
public String getNameOfOrgan() {
    return nameOfOrgan;
}
public void setNameOfOrgan(String nameOfOrgan) {
    this.nameOfOrgan = nameOfOrgan;
}

@Override
public String toString() {
    return "Organs{" + "nameOfOrgan=" + nameOfOrgan + '}';
}

}
}
Now in driver file when I make call there is no syntactical error but I get "Exception in thread "main" java.lang.NoSuchFieldError: vitalOrgans"
    Animal mamal = new Animal();
    mamal.setNameOfAnimal("Chimp");
    mamal.vitalOrgans[0].setNameOfOrgan("Heart");
    System.out.println(mamal.vitalOrgans[0].getNameOfOrgan());

What would be the way to make this (or similar idea) to work.
Thanks.

A: Taking the relevant bit of code:
public class Animal
{
    //...
    Organs [] vitalOrgans = new Organs[3];
    //...
}

Since your declaration of vitalOrgans was never given an access modifier (i.e. one of private, public, protected) it took on default access, which means only other classes in the same package can see it.  Since your other block of code is not in the same package, it cannot see the field.
A minimally viable modification to just make it work would be to set the access to public:
public class Animal
{
    //...
    public Organs [] vitalOrgans = new Organs[3];
    //...
}

While this works, it's not necessarily the best solution, as if you ever change how vitalOrgans is represented, or need to perform any validation, those edits would have to be done throughout the application.  Thus, a better solution (and also, a major stylistic convention in Java for those exact reasons) is to make it (and all your fields, in fact) private and access via methods:
public class Animal {
    private String nameOfAnimal;
    private Organs[] vitalOrgans = new Organs[3];

    //...

    public Organs[] getVitalOrgans() {
        return vitalOrgans;
    }

    //Alternative accessor that fetches only one organ.
    public Organs getVitalOrgan(int index) {
        if(index >= 0 && index < vitalOrgans.length)
            return vitalOrgans[index];
        else
            return null;
    }

    public void setVitalOrgans(Organs[] vitalOrgans) {
        this.vitalOrgans = vitalOrgans
    }

    //...
}

Your caller could then access Organs via either form of the get method (note, you probably want Organs to be public):
Animal.Organs futureMammalHeart = mamal.getVitalOrgan(0); //Animal.Organs due to Organs being an inner class.
if(futureMammalHeart != null) //Demonstration of null check.  Safety first!
    futureMammalHeart.setNameOfOrgan("Heart");
Animal.Organs[] mammalianVitalOrgans = mamal.getVitalOrgans();
if(mammalianVitalOrgans != null) //Just in case...
    System.out.println(mamal.mammalianVitalOrgans[0].getNameOfOrgan());

Also, as Ari mentioned in his answer, don't forget to initialize the organs in your array, otherwise you will get a NullPointerException!

A: You would need to initialize the vitalOrgrans with new Organs(). Like:
public Animal() {
    for (int i = 0; i < vitalOrgans.length; i++) {
        vitalOrgans[i] = new Organs();
    }
}

Because when you say :
Organs[] vitalOrgans = new Organs[3];

You are creating an array of 3 null Organs. Hence the null pointer exception, when accessing "vitalOrgans[i].".


Q: What is the correct way to combine disjoint probability density value? I'm building a particle filter and have two measurements, say one from a camera (C) and one from a GPS (G). Each measurement has a PDF associated with it defined by a mean and sigma. It turns out that the sigma for C is very small while the one for G is rather large.
When I run a measurement update step of the particle filter, I evaluate PDF_G(measurement_g) and PDF_C(measurement_c) for each particle in order to determine which particle's pose most closely matches the measurements. Since sigma_C << sigma_G, the PDF_C(measurement_c) term always dominates the weighting since the result is always really large or small (as opposed to the much wider Gaussian that describes PDF_G). This is because I am multiplying the two PDF results together but this seems incorrect since the units do not match and I haven't done any normalization.
Is this the correct way to combine the PDF results from two independent measurements when trying to determine which hypothesis (particle) most closely matches the measurements? Thanks!

A: If the two functions are probability density functions, and the measurements are independent, then by definition:

*

*PDF_GC(measurement_g, measurement_c) = PDF_G(measurement_g)*PDF_C(measurement_c)
You state that you have not performed any normalisation, so it is plausible that your functions are actually not probability density functions.   Normalise!
$$f_G(g) = \dfrac{\exp(-(g-\mu_{\small G})^2/2\sigma^2_{\small G})}{\sigma_{\small G}\sqrt{2\pi}}$$
PDF_G(measure_g) = exp(-(measure_g - mean_g)^2/(2*sigma_g^2)) / (sigma_g*sqrt(2*pi))
The other issue is the assumption that the GPS and camera measurements are independent.   Depending on what are being measured this may not be the case.


Q: Mahout evaluation - unable to recommend in x cases I am trying to evaluate the recommender algorithms on my data set which probably is sparse, and I have only 341 items for around 20 000 users. I just want to evaluate all of the similarity algorithms. I tried almost all user-based recommendations, and for all of them I am getting this INFO from the evaluator, no matter which one, (AverageAbsoluteDifferenceRecommenderEvaluator or Root mean-square scoring Evaluator) which is Unable to recommend in xXXX cases.  However the final output still have some result. Here is the output of my evaluator:
3/06/17 14:11:35 INFO eval.AbstractDifferenceRecommenderEvaluator: Beginning evaluation using 0.7 of org.apache.mahout.cf.taste.impl.model.jdbc.PostgreSQLJDBCDataModel@44303e7b
13/06/17 14:15:17 INFO model.GenericDataModel: Processed 10000 users
13/06/17 14:15:17 INFO model.GenericDataModel: Processed 20000 users
13/06/17 14:15:17 INFO model.GenericDataModel: Processed 20530 users
13/06/17 14:15:17 INFO eval.AbstractDifferenceRecommenderEvaluator: Beginning evaluation of 11240 users
13/06/17 14:15:17 INFO eval.AbstractDifferenceRecommenderEvaluator: Starting timing of 11240 tasks in 4 threads
13/06/17 14:15:17 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 4ms
13/06/17 14:15:17 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 57MB / 101MB
13/06/17 14:15:17 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 3 cases
13/06/17 14:15:19 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 4ms
13/06/17 14:15:19 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 48MB / 99MB
13/06/17 14:15:19 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 882 cases
13/06/17 14:15:20 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:20 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 33MB / 109MB
13/06/17 14:15:20 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 1787 cases
13/06/17 14:15:22 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:22 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 41MB / 86MB
13/06/17 14:15:22 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 2687 cases
13/06/17 14:15:23 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:23 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 38MB / 98MB
13/06/17 14:15:23 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 3569 cases
13/06/17 14:15:24 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:24 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 28MB / 93MB
13/06/17 14:15:24 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 4465 cases
13/06/17 14:15:26 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:26 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 41MB / 88MB
13/06/17 14:15:26 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 5420 cases
13/06/17 14:15:27 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:27 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 45MB / 90MB
13/06/17 14:15:27 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 6317 cases
13/06/17 14:15:28 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:28 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 46MB / 103MB
13/06/17 14:15:28 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 7220 cases
13/06/17 14:15:30 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:30 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 72MB / 102MB
13/06/17 14:15:30 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 8145 cases
13/06/17 14:15:31 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:31 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 67MB / 99MB
13/06/17 14:15:31 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 9084 cases
13/06/17 14:15:33 INFO eval.AbstractDifferenceRecommenderEvaluator: Average time per recommendation: 5ms
13/06/17 14:15:33 INFO eval.AbstractDifferenceRecommenderEvaluator: Approximate memory used: 31MB / 83MB
13/06/17 14:15:33 INFO eval.AbstractDifferenceRecommenderEvaluator: Unable to recommend in 9982 cases
13/06/17 14:15:33 INFO eval.AbstractDifferenceRecommenderEvaluator: Evaluation result: 1.643042326271061

I don't understand the numbers, why they show so many times, and is this unable to recommend in xxx cases bigger then 20% of all my data? Does it mean that for one user it can't recommend in 3 cases, and for other in 9892?


Q: How to open Telegram desktop source in Qt? I'm trying to open the source of Telegram (desktop version) in Qt but I can't find any .pro file.


Q: How to pick a great working team? I've just finished my master and I'm starting to dig into the laboral world, i.e. learning how programming teams and technology companies work in the real world.
I'm starting to design the idea of my own service or product based on free software, and I will require a well coupled, enthusiast and fluid team to build and the idea. My problem is that I'm not sure which would be the best skills to ask for a programming team of 4-5 members.
I have many friends and acquaintances, with whom I've worked during my studies. Must of those ones I have in mind are very capable and smart people, with a good logic and programming base, although some of them have some characteristics that I believe that could influtiate negatively in the group: lack of communication, fear to debate ideas, hard to give when debating, lack of structured programming (testing, good commenting, previous design and analysis).
Some of them have this negative characteristics, but must of them have a lot of enthusiasm, nice working skills (from an individual point of view), and ability to see the whole picture.
The question is: how to pick the best team for a large scale project, with a lot of programming? Which of these negative skills do you think are just too influential? Which can be softened with good leadership? Wich good skills are to be expected? And any other opinion about social and programming skills of a programming team.

A:
Joel Spolsky said:
In principle, it’s simple. You’re
  looking for people who are

*

*Smart, and

*Get things done.

A: Team chemistry is something that is difficult to predict. How long a project will take to finish is difficult to predict. Really, life is difficult to predict. Your best bet is to choose the people you feel will work well together, get them started, and see what happens. Next, adjust your team as needed.It will be obvious what areas will need to be improved, and what is going smoothly, if you ask for feedback on these items from your team.
The scientific method is generally the best way to achieve results. Don't spend too much time hypothesizing, go ahead and get observing, so that you can take action.

A: Steve Yegge liked that principle and expanded on it a bit with Done and Gets Things Smart.
I've managed teams for 5 years now, after 15 years of development.  My own principle is much like Spoelsky's only not as elegantly worded.  Programmers are problem solvers who use software to solve the problems.  In that sense, a good programmer will use whatever tool is the best for the job, although that often means one of the handful they know best (good luck finding a .Net developer who believes Lisp is the best tool for a job).
While all of my interviews do have some development specific questions, they tend to be generic and not toolset based.  I would rather have people who understand OO (our current app suite is OO), and show an ability to understand, learn, and embrace.
All of that said, they do need to show they have the ability to write sound logic in some language.  I've come across way too many developers who can talk the talk but can't walk the walk.

A: A great team member have a number of characteristics, as in the list below. This is not specific to programming, but applies to all types of teams where collaboration is expected to happen:

*

*Acknowledges and works through conflict openly

*Considers and uses new ideas and suggestions from others

*Encourages feedback on own behavior

*Understands and is committed to team objectives.

*Shares openly and authentically with others regarding personal feelings, opinions,  thoughts, and perceptions about problems and conditions

*Involves others in the decision-making process

*Trusts, supports, and has genuine concern for other team members.

*"Owns" problems rather than blaming them on others

*When listening, attempts to hear and interpret communication from other's points of view

*Influences others by involving them in the issue(s)

*Encourages the development of other team members

*Respects and is tolerant of individual differences

*Does not engage in win/lose activities with other team members

*Has skills in understanding what's going on in the group

Use this list as a way to measure your potential team members.
This is more or less the perfect team member, someone I would sure like to work with. If you can find people like this and who also knows a thing or two about programming, then you have a winning team.
More info here.


Q: Alloc - add as accessoryView - release: does it leak? Does this leak memory? This code is executed in cellForRowAtIndexPath: outside the cell creation block (so each time the table cell is updated).
MyView *myView = [[MyView alloc] init];
// ... configuration code
cell.accessoryView = myView;
[myView release];

Or in other words, will the UITableViewCell release the object in its accessoryView when a new object gets assigned to it?
Thanks.

A: Yes, the cell will release the accessory view and you do not have a leak in the example.

A: The property accessoryView of a UITableViewCell is a retain type, in common with many view properties in the kit. Check the Apple documentation for UITableViewCell to convince yourself of this. Therefore there will be no leak in your example - the retain count has been correctly managed. You've also correctly released after setting the accessory view, on account of your alloc call.


Q: How to solve TypeError: The DTypes  and  do not have a common DType? I have a dataframe which I want to plot using stacked chart for all columns
    date              company1           company2           company3
0   2015-09-30  0.1729652326951854  5.10825384154414    5.28662587089132
1   2015-12-31  0.33177760613144625 5.341402694012068   7.757158664745589
2   2016-03-31  0.45978954321258786 0.601947573082123   14.280848001613228
3   2016-06-30  0.08512062667254938 0.26628902842588686 9.342680735839917
4   2016-09-30  0.07052086314882283 10.032170981625246  8.964205526466738
5   2016-12-31  0.06143896111634454 10.06041088786925   8.3778390910586
6   2017-03-31  0.03742645731812014 7.156923204928792   6.793302965780993
7   2017-06-30  0.1032395546373315  5.438273795868809   4.857798532828831

I did the following
df['date'] = pd.to_datetime(df.date)
fig, ax = plt.subplots(figsize=(9,6), dpi= 80)
ax = exchanges_disagg_data.plot.area(legend=None, figsize=(9,6), alpha=0.9)

and i get the following error message.
TypeError: The DTypes <class 'numpy.dtype[uint8]'> and <class 'numpy.dtype[datetime64]'> do not have a common DType. For example they cannot be stored in a single array unless the dtype is `object`.

Then i tried
df.date= df['date'].dt.strftime('%Y-%m-%d')

and i get the plot but instead of date time x ticks, i just get index numbers...
This is very frustrating, would anyone know how to solve this? Many thanks in advance.

A: Note: np.nan is float type and pd.NaT is of datetime null type. Problem with your code is that null values have been filled with np.nan
I got the same error while doing the following thing....
df['date'] = np.where((df['date2'].notnull()) & (df['date3'].notnull()),df['date2']-df['date3'],np.nan)

problem here is date difference of date2 and date3 is of datetime type but the type of "np.nan" is float/int. For saving it to df['date'], datatype should be same. In datetime type the null date is "pd.NaT". So when I replace the above code with below. It worked for me. You can try the same..
df['date'] = np.where((df['date2'].notnull()) & (df['date3'].notnull()),df['date2']-df['date3'],pd.NaT)

So you can replace the nulls present in your data with pd.NaT instead of np.nan
you can use below thing as well...
df['date'].replace(np.NaN, pd.NaT)

or
df['date'].fillna(pd.NaT)

Hope it is helpful for you :)


Q: Android CheckedTextView - Changing checked status on click I have a listview that needs to be multiple choice (i.e each list item has a checkbox which can be checked / unchecked)
The list view is in a tabhost and is the content for teh first tab.
My set up is like so:
My tab is set up with:
TabSpec tab = tabHost.newTabSpec("Services");

tabHost.addTab(tabHost.newTabSpec("tab_test1").setIndicator("Services").setContent(new Intent(this, ServiceList.class)));

When the tab is clicked new activity ServiceList is started
ServiceList is defined as such:
    public class ServiceList extends ListActivity{
        private EscarApplication application;
        ListView listView;
         @Override
           public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.service_list);
             ServiceList.this.application = (EscarApplication) this.getApplication();
             final ListView listView = getListView();
         }

         protected void onListItemClick(ListView l, View v, int position, long id) {
            String.valueOf(id);
            Long.toString(id);
            ((CheckedTextView) v).setChecked(true);
            super.onListItemClick(l, v, position, id);
        }

         @Override
         public void onStart() {
             super.onStart();
            //Generate and display the List of visits for this day by calling the AsyncTask
             GenerateServiceList services = new GenerateServiceList();
             int id = ServiceList.this.application.getVisitId();
             services.execute(id);
             listView  = getListView();
             listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
         }

        //The AsyncTask to generate a list
         private class GenerateServiceList extends AsyncTask<Integer, String, Cursor> {
              // can use UI thread here
              protected void onPreExecute() {
              }
              // automatically done on worker thread (separate from UI thread)
              protected Cursor doInBackground(Integer...params) {
                  int client_id = params[0];
                  ServiceList.this.application.getServicesHelper().open();
                  Cursor cur = ServiceList.this.application.getServicesHelper().getPotentialVisitServices(client_id);
                  return cur;

              }
              // can use UI thread here
              protected void onPostExecute(Cursor cur){
                  startManagingCursor(cur);
                  // the desired columns to be bound
                  String[] columns = new String[] {ServicesAdapter.KEY_SERVICE};
                  // the XML defined views which the data will be bound to
                  int[] to = new int[] {R.id.display_service};
                  SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(ServiceList.this, R.layout.service_list_element, cur, columns, to);
                  // set this adapter as your ListActivity's adapter
                  ServiceList.this.setListAdapter(mAdapter);
ServiceList.this.application.getServicesHelper().close();

              }
         }
    }

So, everything works ok until I click on my list item to change the checkbox state.
The part of teh code set to handle click events is causing me problems:
 protected void onListItemClick(ListView l, View v, int position, long id) {
                String.valueOf(id);
                Long.toString(id);
                ((CheckedTextView) v).setChecked(true);
                super.onListItemClick(l, v, position, id);
            }

My understanding is that the View v passed to the onListItemClick method reperesents my list element, so I am trying to cast v as a CheckedTextView and set teh checked value to true, however this just causes my app to crash. Am I missing something simple here, or is there an easier way to do this?
Thanks
Kevin

A: Have you debugged it to check if 'v' is null? If so, you need to use a layoutInflator to retrieve the view.
if(v == null)
{
    LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = vi.inflate(R.layout.service_list, null);
}


Q: Unable to get data from foreign table in mongodb nodejs using $lookup I have just started working on mongodb and I want to get data from foreign table(User) and table(Connection) by performing join but foreign table data is always an empty array
User Schema:
[
{key: 1, name: "a"},
{key: 2, name: "b"},
{key: 1, name: "c"},
{key: 2, name: "d"},
]

Connection schema:
 [
    {initiator_id: 1, target_id: 2}
    {initiator_id: 3, target_id: 4}
 ]

And this is my join code
const pipeline = [
    {
      $match: {
        initiator_id: { $eq: user_id },
      },
    },
    {
      $lookup: {
        from: "user",
        localField: "initiator_id",
        foreignField: "key",
        as: "user",
      },
    },
  ];

  mongoose.model("connection").aggregate(pipeline).then((res) => {
    console.log(res);
  });

And the console.log response is an array in which the user field is always an empty array
[
 {
 connection_id: 'some_id'
 initiator_id: 1
 target_id: 2,
 user: []//this is where I'm expecting data from User table but it is always empty
 }
]

initiator_id, target_id, and key .... all are type Number


Q: Message: cache_dir must be a directory Hello people I have some problems with Zend Framework. I first got the following message:
Message: Could not determine temp directory, please specify a cache_dir manually.
I searched google and found this post: Zend Framework : Could not determine temp directory, please specify a cache_dir manually
I read it and now when I fill in the form I get the following error:
 (Everywhere where I put .. in the error means the domain.)Message: cache_dir must be a directory
- #0 /home/daan/domains/../library/Zend/Cache/Backend/File.php(154): Zend_Cache::throwException('cache_dir must ...')
 - #1 /home/daan/domains/../library/Zend/Cache/Backend/File.php(121): Zend_Cache_Backend_File->setCacheDir('/domains/daan.h...')
 - #2 /home/daan/domains/../library/Zend/Cache.php(153): Zend_Cache_Backend_File->__construct(Array)
 - #3 /home/daan/domains/../library/Zend/Cache.php(94): Zend_Cache::_makeBackend('File', Array, false, false)
 - #4 /home/daan/domains/../library/Zend/Locale/Data.php(307): Zend_Cache::factory('Core', 'File', Array, Array)
 - #5 /home/daan/domains/../library/Zend/Locale/Format.php(796): Zend_Locale_Data::getList('nl_NL', 'day')
 - #6 /home/daan/domains/../library/Zend/Locale/Format.php(1106): Zend_Locale_Format::_parseDate('16-02-2013', Array)
 - #7 /home/daan/domains/../library/Zend/Date.php(4763): Zend_Locale_Format::getDate('16-02-2013', Array)
 - #8 /home/daan/domains/../library/Zend/Validate/Date.php(175): Zend_Date::isDate('16-02-2013', 'MM-DD-YYYY', NULL)
 - #9 /home/daan/domains/../library/Zend/Form/Element.php(1391): Zend_Validate_Date->isValid('16-02-2013', Array)
 - #10 /home/daan/domains/../library/Zend/Form.php(2135): Zend_Form_Element->isValid('16-02-2013', Array)
 - #11/home/daan/domains/../application/controllers/BugController.php(27): Zend_Form->isValid(Array)
 - #12 /home/daan/domains/../library/Zend/Controller/Action.php(513): BugController->submitAction()
 - #13 /home/daan/domains/../library/Zend/Controller/Dispatcher/Standard.php(289): Zend_Controller_Action->dispatch('submitAction')
 - #14 /home/daan/domains/../library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
 - #15 /home/daan/domains/../library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
 - #16 /home/daan/domains/../library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
 - #17 /home/daan/domains/../public_html/index.php(26): Zend_Application->run()
 - #18 {main}

Application.ini:
resources.cachemanager.configFiles.frontend.name = File
resources.cachemanager.configFiles.frontend.customFrontendNaming = false
resources.cachemanager.configFiles.frontend.options.lifetime = false
resources.cachemanager.configFiles.frontend.options.automatic_serialization = true
resources.cachemanager.configFiles.backend.name = File
resources.cachemanager.configFiles.backend.customBackendNaming = false
resources.cachemanager.configFiles.backend.options.cache_dir = APPLICATION_PATH      "/../tmp"
resources.cachemanager.configFiles.frontendBackendAutoload = false

Initcache:
 protected function _initCaching() {
$frontend = array(
'lifetime' => $time,
'automatic_serialization' => true
);
$backend = array(
'cache_dir' => sys_get_temp_dir(),
);
$cache = Zend_Cache::factory('core', 'File', $frontend, $backend);
Zend_Registry::set('cache', $cache);

}
Folder Structure:
.htpasswd
application
awstats
library
logs
public_ftp
public_html
tmp

A: cache_dir must be a directory :
This problem came generally when you move your code to another host or server . There are mainly two solution for this problem
1 -  Make sure your cache directory is writable or you can make writable to var folder of magento
but sometimes this situation does not work so here is the alternate solution. Go to this location lib/Zend/Cache/Backend/
and open file.php file you’ll see the code something like this
protected $_options = array(
        'cache_dir' => null,
        'file_locking' => true,
        'read_control' => true,
        'read_control_type' => 'crc32',
        'hashed_directory_level' => 0,
        'hashed_directory_umask' => 0700,
        'file_name_prefix' => 'zend_cache',
        'cache_file_umask' => 0600,
        'metadatas_array_max_size' => 100
    );

change this code as below
protected $_options = array(
        'cache_dir' => '/var/www/html/webkul/magento/tmp',
        'file_locking' => true,
        'read_control' => true,
        'read_control_type' => 'crc32',
        'hashed_directory_level' => 0,
        'hashed_directory_umask' => 0700,
        'file_name_prefix' => 'zend_cache',
        'cache_file_umask' => 0600,
        'metadatas_array_max_size' => 100
    );

assign path of cache_dir as per your configuration .

A: May be Zend is not able to find your cache directory. Try to se this in Bootstrap.php like this
protected function _initCache() {
    $frontend = array(
        'lifetime' => $time,
        'automatic_serialization' => true
    );
    $backend = array(
        'cache_dir' => sys_get_temp_dir(), /**automatically detects**/
    );
    $cache = Zend_Cache::factory('core', 'File', $frontend, $backend);
    Zend_Registry::set('cache', $cache);
}

A: Remove the _initCaching function from your bootstrap, you shouldn't have this and the application.ini entries as they are both trying to setup the same thing (but using different cache locations).
Your cache dir is set to APPLICATION_PATH "/../tmp" - i.e. a folder called 'tmp' at the root of your application (NOT in the application folder). Are you 100% sure that your tmp folder exists at this location? If so, you could try changing the application.ini configuration to use a full path instead:
resources.cachemanager.configFiles.backend.options.cache_dir = "/home/daan/domains/whatever/tmp"

just to see if that fixes the problem.
If you still can't get it working please post more information about the file structure of your application.

A: The answer of this question is that open File.php file and change the path of the tmp folder.
This issue mostly comes when you tranfer your site from one server to another. When you transfer the site then the path of the tmp folder doesn't changed to the the new one. So edit the file.php and change the path of the tmp folder.

A: magento root
Creating "tmp" file in the magento directory solved this error for me.
I was able to access admin easily

A: assign full path for your cache directory. For example,
'cache_dir' => '/var/www/html/var/cache1',

A: Change path in /install/config/, edit file vfs.php and put new path name.

A: One of the causes for this problem in CentOS/RedHat could be Selinux.
I got rid of this issue by just disabling Selinux
Edit the /etc/selinux/config file and set the SELINUX to disabled.


Q: Problema con header() en PHP Tengo esta advertencia:

Warning: Cannot modify header information - headers already sent

No sé qué pueda tener mal en header.
Este es mi código:

<!DOCTYPE html>
<!--
 *
 * @author Zarate
-->
<?php
include ('serv.php');

$fechaInicio=$_POST['fInicio'];
$fechaFin=$_POST['fFin'];

if (isset($_POST['excel'])) {

    //archivo
    header('Content-Type:text/csv; charset=latin1');
//    header('Content-Type:text/csv; charset=latin1');
    header('Content-Disposition: attachment; filename="Solicitud_De_Cuentas.csv"');

    //archivo saliente
    $salida=fopen('php://output', 'w');

    fputcsv($salida, array('Nombre', 'Apellidos', 'Nombre Completo', 'Alias E-mail', 'Titulo', 'Puesto', 'Delegacion', 'Departamento', 'Direccion', 'Ciudad', 'Estado', 'Telefono', 'Extencion', 'Matricula', 'CURP', 'Num. Seg Social', 'Servidor de correo actual', 'Forma de Acceso', 'Sist. Operativo de la PC', 'Nombre de la PC', 'pwd'));

    $csv=$conect->query("SELECT * FROM registros where Fecha BETWEEN '$fechaInicio' and '$fechaFin'");
    while ($filaR=$csv->fetch_assoc())
            fputcsv($salida, array($filaR['Nombre'],
                                    $filaR['Apellidos'],
                                    $filaR['Nombre Completo'],
                                    $filaR['Alias E-mail'],
                                    $filaR['Titulo'],
                                    $filaR['Puesto'],
                                    $filaR['Delegacion'],
                                    $filaR['Departamento'],
                                    $filaR['Direccion'],
                                    $filaR['Ciudad'],
                                    $filaR['Estado'],
                                    $filaR['Telefono'],
                                    $filaR['Extension'],
                                    $filaR['Matricula'],
                                    $filaR['CURP'],
                                    $filaR['Num. Seg Social'],
                                    $filaR['Servidor de correo actual'],
                                    $filaR['Forma de Acceso'],
                                    $filaR['Sist. Operativo de la PC'],
                                    $filaR['Nombre de la PC'],
                                    $filaR['pwd']));
}
?>

A: Las funciones PHP que envían o modifican las cabeceras HTTP se deben ejecutar antes de que se haya empezado a enviar la página solicitada al usuario. Si no, se producirá el siguiente error:
Warning: Cannot modify header information - headers already sent
(output started at file:line)

Las funciones PHP que modifican las cabeceras HTTP son las siguientes:
header() / header_remove()
session_start() / session_regenerate_id()
setcookie() / setrawcookie()

Y las formas de empezar a enviar contenidos al usuario antes de que se ejecuten esas funciones pueden ser a su vez intencionadas o no intencionadas:
Intencionadas:

*

*Mostrar información con print o echo

*Volcar el contenido de variables con var_dump()

*Utilizar alguna de estas funciones: printf(), trigger_error(), vprintf(), ob_flush(), readfile() o passthru().

*Añadir código HTML antes de la etiqueta <?php de apertura

No intencionadas:

*

*Añadir algún espacio en blanco antes de <?php o después de ?>

*El BOM (Byte Order Mark) de UTF-8

*Mensajes de error o notices producidos con anterioridad

A: El mensaje de

Warning: Cannot modify header information - headers already sent

Es enviado por que estás enviando información extra o cambiando la información que se envía en los headers de la respuesta HTTP cuando ya enviaste información previa de contenido. En el caso muy específico de tu código es por que estás enviando tags de xml en las primeras 5 líneas de tu código
<!DOCTYPE html>
<!--
 *
 * @author Zarate
-->

Y después estás queriendo cambiar la información de los headers para indicar que vas a enviar un archivo csv descargable con estas otras líneas de código.
header('Content-Type:text/csv; charset=latin1');
header('Content-Disposition: attachment; filename="Solicitud_De_Cuentas.csv"');

Elimina las primeras 5 cinco lineas de tu código para que ya no aparezca el mensaje de aviso.


Q: Why did I get an e-mail with a nonsensical header? I recently got an e-mail with the title

=?utf-8?B? 8J+QtiBZb3UncmUgYSBzdHJvbmcgY2FuZGlkYXRlIGZvciBvdXIgZnV0dXJlLCBQZXRlciDwn4e6 8J+HuA==?=

Thinking it might be malware, I ran a check with Malwarebytes, and it came up clean. Is there any legitimate reason for the title to be a nonsensical string of characters?

A: What you have is some header text encoded with a failed attempt at RFC 2047.
RFC 2047 is the standard governing embedding non-ASCII characters in email headers,
and it says that headers which do not comply exactly with the RFC 2047 standard should be displayed as-is, rather than decoding being attempted. So your email software is seeing the bad header and displaying it “correctly” (as required by the standard).
No mainstream software flouts RFC 2047 so badly as that, so it's probably coming from some dodgy bulk mailing software. The software is making "encoded words" too long (line length limit 76), which is forbidden (RFC 2047 says “MUST NOT”).
Despite being over-long it can be decoded manually; it looks like some sort of recruiter spam:
 You're a strong candidate for our future, Peter

A: It is a base64 string, a way of encoding text or data so it can be sent via 7-bit ASCII text supported by emails.
It would appear that your email client does not support base64 in the subject line.
Poking the text

8J+QtiBZb3UncmUgYSBzdHJvbmcgY2FuZGlkYXRlIGZvciBvdXIgZnV0dXJlLCBQZXRlciDwn4e6 8J+HuA==?=

Through base64decode shows the string below. This is the body of the string minus the utf-8 header.

 You're a strong candidate for our future, Peter