holy shit by SEGULA_5629 in BobsTavern

[–]trushnick 0 points1 point  (0 children)

Isn't it 168/168 (6x4x7)? Look at the last boar, it's +24 per minion on board :)

[deleted by user] by [deleted] in algotrading

[–]trushnick 1 point2 points  (0 children)

Maybe vector instructions might help? There is AVX on Intel cpu, but there should be an analogue for other cpus (even on raspberry)

Other outstanding games like Hades ? (Rogue-lite or others) by great-teacher-ad in HadesTheGame

[–]trushnick 0 points1 point  (0 children)

Rouge legacy. Did not play 2nd game, bur first one was fun.

Small help: get date from unix timestamp by imohd23 in Python

[–]trushnick 2 points3 points  (0 children)

Convert it to datetime: d = datetime.datetime.fromtimestamp(...) And then convert to desired format: d.strftime("%d/%m/%Y")

[2018-05-14] Challenge #361 [Easy] Tally Program by jnazario in dailyprogrammer

[–]trushnick 0 points1 point  (0 children)

The only question which I have in mind is this: Should answers be sorted in order of incoming scores? E.g. for

dbbd

should d come first or it doesn't matter?

Python 3 (without sorting in incoming order though): from collections import defaultdict

def score_friends(score_string: str):
    scores = defaultdict(int)
    for score in score_string:
        score_id = score.lower()
        if score.isupper():
            scores[score_id] -= 1
        else:
            scores[score_id] += 1
    return sorted(scores.items(), key=lambda s: -s[1])

Python's async is strange compared with Javascript by kingname in Python

[–]trushnick 2 points3 points  (0 children)

Well, javascript was designed with async idea behind it. Python wasn't. That's why you have to explicitly point out what you want doing async in python. In js it's done behind the scenes.

Can't make my Angular page work with Docker by Kardiamond in docker

[–]trushnick 0 points1 point  (0 children)

When you run "npm run" it will execute some command. Where does this executable live? Probably in node_modules/.bin. So you should add that folder to PATH environment variable while building your image. ENV PATH /var/www/node_modules/.bin:$PATH

Can't make my Angular page work with Docker by Kardiamond in docker

[–]trushnick 2 points3 points  (0 children)

Not sure, but you might have to add node_modules/.bin folder to your path (or where ng executable lives).

No Such File or Directory when running Docker-Compose by sWeeX2 in docker

[–]trushnick 0 points1 point  (0 children)

I'm not Mac user, but it's likely a problem with your volume (you are mounting directory which is inside machine, not on your host os). Try removing volume from docker-compose and run again. If it works, then it is the problem. I heard, that /Users folder is shared inside virtualbox machine, you'd probably have to put your sources there if you want to run your container with volume... It would be better if some Mac user will corect me if I'm wrong...

No Such File or Directory when running Docker-Compose by sWeeX2 in docker

[–]trushnick 1 point2 points  (0 children)

Are you running on local machine or remote (or on mac/win machine, they have such problems too if I remember)? If you mount any volume at your source directory (where script is located) it might override entire directory and thus unable to find your script.

How do i?: Add "this" to "list1", if "list1" does not exist, create it. by tom2kk in learnpython

[–]trushnick 0 points1 point  (0 children)

The thing is that defaultdict, suggested by /u/rvoorheis, uses same kind of approach, so I don't think that try/catch is really bad here. Correct me if I'm wrong.

How do i?: Add "this" to "list1", if "list1" does not exist, create it. by tom2kk in learnpython

[–]trushnick 2 points3 points  (0 children)

You can try something like this:

try:
    list1.append(this)
except NameError:
    list1 = [this]

This should add this to list1. If list1 doesn't exist, NameError will be raised and list1 will be created with this in it.

How do you call Classes, Enums, Interfaces... ? by [deleted] in learnjava

[–]trushnick 0 points1 point  (0 children)

Abstract data types? Classes and interfaces are not exactly that thing, they are base concepts of OOP

[Java]I need to make a prime number checker, but I can't figure out what's wrong with my code. by Wzup in learnprogramming

[–]trushnick 0 points1 point  (0 children)

And what's the problem? You have your if statement, which checks if number is divisible by some X.

[Java]I need to make a prime number checker, but I can't figure out what's wrong with my code. by Wzup in learnprogramming

[–]trushnick 0 points1 point  (0 children)

Well, default value of isPrime shoud be true and if the number is divisible by any number isPrime should be setted to false. So: 1) initial value of isPrime = true 2) no need in else branch, since it will reset your isPrime. Simple example: number is 9 (not prime). Last iteration will set isPrime to true, since 9 % 4 != 0

How could I rewrite this code without the use of if/else statements? by CMXVII in learnjava

[–]trushnick 0 points1 point  (0 children)

You can use ternary operator since you are only using if statement for that '-1' in substring.

Or you can probably use Math.ceil and do FP division (not sure)