vendredi 2 février 2018

Cypher - return 1 'random' node from specific relationships

Hello fellow stackers,

Trying to build a Cypher query that returns ONE entry per 'comic'.

Basic structure is as follows:

(Comic)<-[]-(Media)-[]->(MediaType)

I want to grab 3 'random' comics and return only one Media per comic of said type. As a comic may have 100 medias of the media type, it's a little concerning. I could break this down into multiple queries, but I am sure there's a way for Cypher to do this through its own system.

My original code would do what it needed to, but if there were multiple medias of the same type, one comic would had the possibility of being returned multiple times.

The original Code:

MATCH (mt:MediaType{Name: {mediatype} })
<-[:Is_Media_Of]-(m:Media)-[:Is_Media_For]->(w:Webcomic)
WHERE w.ComicID <> toInt({comicid})
AND m.Status = 'Active'
RETURN m.URL as ImgURL, 
w.Name as ComicName, 
rand() as r 
ORDER BY r ASC Limit toInt({count}) ",
["mediatype"=>$AdType,"count"=>$Count,"comicid"=>$ComicID])

This would sometimes return:

'comic1' 'img'

'comic2' 'img'

'comic1' 'img2'

'comic3' 'img2'

'comic4' 'img1'

'comic3' 'img5'

I'm sure it's pretty straight forward and I'm missing something. Any help is greatly appreciated.




jeudi 1 février 2018

Same & unique value in a cell (E F & H I) from a range data A1:C5 using Excel 2013 (not VBA)

Hi everyone help me please and please don't use macro or VBA.
Following 5 lines of multiple data sets from columns A B and C.

value in A1:A5 = one word, more then two words, three word, four, five
value in B1:B5 = boulevard, city, area, use google maps, north east
value in C1:C5 = smart child, parent, young people, maps, north

what i need is:

  1. value in E1 is random auto generate (not fixed value) a values from A1:C5 and i think can same or repeated until unlimited.
  2. value in F1 is random auto generate (not fixed value) 5 values from A1:C5 separated by the symbol "|" and is flanked by a "[" before the values are also a "]" sign behind the values.
    For values in cell F1 this can happen duplicate as well; and it's not a problem.

then bellow i give a sample random-result from point number:

(1.) E1 to E10 each value is =

young people, area, google maps, one words, area, parent  

and so on until how long in the pull down the number of his cell; unlimited.

(2.) F1 to F3 values is =

[five|north east|area|five|smart child]
[four|area|city|parent|use google maps]
[boulevard|north|boulevard|parent|use google maps]

and so on until how long in the pull down the number of his cell; unlimited.

and plese help me again as number:

(3.) slightly modify the formula cell E1 please generate unique values in cell H1. And of course the results will be limited to only 15 data when in the pull down. Since the total data is only 15 (5 rows multiplied by 3 columns) from range A1 to C5. Let me show example maybe like this:

young people, parent, google maps, one words, boulevard, city, four

(4.) Generate 5 unique values in one cell i1 (i use lowercase for alphabet "i") it's looks like this

[use google maps|north east|area|five|smart child]
[four|five|city|parent|use google maps]
[boulevard|north|area|parent|use google maps]
[five|north east|area|use google maps|smart child]

and so on until how long in the pull down the number of his cell; unlimited.


Thanks for your helps guys
please download here excel file for my explanation.




Why can't I get a random file from the directory?

I'm trying to get a random word file from a specified directory, but it returns nothing Here's the some part of the code.

for filename in glob.glob(os.path.join(path, '*docx')):
    fl = []
    fl.append(filename)
return fl

choice = random.choice(fl)
doc = docx.Document(choice)
print(doc.paragraphs[0].text) # There is a paragraph on the document starting on the first line so problem is not there.

There is nothing wrong with the path. Eveything was working just fine when I was not trying to get only one random file instead of all the files.

  1. What am I doing it wrong?
  2. Is there any more efficient way of doing it?



Does RandomSecure uses the same seed on each restart ?

I'm currently trying to implement a password hash manager in Java. Looking for the best way to achieve this, I learned about salts.

This is the generateSalt function I've found :

public static byte[] generateSalt() throws NoSuchAlgorithmException {
    SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
    byte[] salt = new byte[8];
    random.nextBytes(salt);
    return salt;
}

Then I simply tried this :

public class Application {
    public static void main(String[] args) {
        try {
            for(int i = 0; i < 10; i++) {
                System.out.println(PasswordHash.generateSalt());
            }
        }
        catch(Exception e) {
            System.out.println(e.getStackTrace());
        }
    }
}

Output is : 135fbaa4 45ee12a7 330bedb4 2503dbd3 4b67cf4d 7ea987ac 12a3a380 29453f44 5cad8086 6e0be858

But if I restart my application, results remains the same. I've seen salts are unique for each users. So let's imagine I want to be able to create database users in my application. I create user 1, and generated salt is 135fbaa4.

Then I restart my application and create user 2, so generated salt will be 135fbaa4 too, right ?

Documentation said :

public void nextBytes(byte[] bytes) Generates a user-specified number of random bytes. If a call to setSeed had not occurred previously, the first call to this method forces this SecureRandom object to seed itself. This self-seeding will not occur if setSeed was previously called.

Is this seed the problem ? Feel like I've missed something. I've tried to use System.currentTimeMillis() as the seed, so the output is different, but it remains the same after each restart.




Random choice from list at least once

I have 10 elements in a Python list. I want to select an item randomly from this list - multiple times (more than 1000 times...). And, I want to ensure that all 10 are elements chosen at least once. Is there a way to do it in Python?

random.choice is not helping me...(at least, I do not know how to).




How to add packages from git to my Meteor project

I updated my Meteor project to 1.6.1 which no longer supports Meteor.uuid(). The package artwells:accounts-guest requires it and user baursn has submitted a merge of a pull request that updates the user of Meteor.uuid() to Random.id().

Artwells is yet to update the main package, so I'd like to use baursn's version. How?




How do I display the actual input instead of option number?

I'm trying to get this to display the actual input instead of the option number.

import java.util.*;

public class RandomGenerator {

public static void main(String[] args) {

   int length;
   Scanner input = new Scanner(System.in);
   System.out.println("How many options?"); //user input food options
   length = input.nextInt();

   String[] names = new String[length];
   for(int counter = 0; counter < length; counter++){
       System.out.println("Enter option #" + (counter+1) + ":");
       names[counter] = input.next();   
   }

   input.close();

   System.out.println("You are going to eat " + new Random().nextInt(names.length));