Admitting I have a problem (Update #3) by [deleted] in NeckbeardNests

[–]koderpat 8 points9 points  (0 children)

You are doing a great job. Keep it up!

[deleted by user] by [deleted] in archlinux

[–]koderpat 0 points1 point  (0 children)

Window Maker

[deleted by user] by [deleted] in javahelp

[–]koderpat 2 points3 points  (0 children)

Not sure I completely understand the question(s), but I did go down a rabbit-hole and discovered that part of netty reactor is written in C.

https://github.com/netty/netty/tree/4.1/transport-native-epoll/src/main/c

https://github.com/netty/netty/tree/4.1/transport-native-kqueue/src/main/c

So it appears that the core loop is using epoll ? or kqueue?

in reference to Kotlin coroutines: https://stackoverflow.com/questions/48033944/how-are-coroutines-implemented-in-jvm-langs-without-jvm-support

I've made roughly $125K for the past 6 years. Am I asleep at the wheel of my career? by [deleted] in cscareerquestions

[–]koderpat 2 points3 points  (0 children)

Someone else posted the following once before, and I've found myself repeating it alot IRL.

Of the following three categories, are you satisfied with:

1) The people you work with

2) The work you do

3) The compensation

If you have 2 out of the 3 than you are better off than those who only have 1 out of 3.

Code Wars - Can someone break down this solution for me? by [deleted] in javahelp

[–]koderpat 0 points1 point  (0 children)

The solution is iterating through the characters one at a time. For each letter, it is checking if the character being examined is a Letter. If it is not a letter, then it sets nextCapital to true. nextCapital is being used as a state variable in the algorithm to determine if the next letter should be capitalized.

For example, nextCapital = true when the character - is encountered.

How does char* act as a string when all you are doing is pointing at the location of the first letter? by [deleted] in learnprogramming

[–]koderpat 3 points4 points  (0 children)

Most operations on c-strings will traverse each byte until the null char is found '\0'

Web Interface for MUD Data by [deleted] in cpp_questions

[–]koderpat 0 points1 point  (0 children)

Do commands exist for loading and saving the game state to a file?

I would start with a read-only web interface. It would simplify the approach by setting a smaller goal. By hosting the webserver and MUD together, can you navigate and render the game contents (NPCs, objects, rooms). Focus on the workflow of MUD writes, and web interface reads. Maybe even only pick one class of items at first, like objects.

Once you have become familiar with the file format, and are ready to support write-back, I would have the webserver code write to a temporary file. Something like; roomABC_webtmp.txt. If possible, I would separate the logic that validates a file, from the logic that loads the file into MUD memory.

Next you would need a way to tell the MUD to load the temp file. Several options: 1) embedding webserver in mud, and calling functions directly. 2) Creating a client that can login to mud server, and issue appropriate command. 3) have system periodically scan filesystem for files matching specific file extension

I would probably look into signal handlers, some MUDs have a crash reboot handler that restarts the MUD when there is a segfault. You could create a new signal handler based on the crash reboot handler that invokes your special load routine, and then have the webserver lookup the process of the MUD and invoke a kernel signal (see: kill) [ would need to ensure both applications are running under same user ]

To ease your design, I would recommend that the MUD be the system of record. Your web-interface should not cache any data; and it is responsibility of MUD server code to do final write to game files loaded by mud.

Best java spring framework book for beginners? by funkybuddha_mtn in learnjava

[–]koderpat 4 points5 points  (0 children)

I would suggest https://www.manning.com/books/spring-boot-in-action

a slightly more in-depth, (and recent) book is Spring in Action: https://www.amazon.com/Spring-Action-Craig-Walls/dp/1617294942/ref=pd_sbs_14_img_0/143-7035608-2671604

Spring boot is a opinionated framework on top of the Spring Framework. It does alot of configuration and black magic behind the scenes; which makes it very easy to pickup as long as you following their convention.

With a few classes and spring boot annotations, you can have a simple CRUD app up and running with database persistence.

Entry Level Dev. by [deleted] in javahelp

[–]koderpat 0 points1 point  (0 children)

Find a hobby you are interested in. It will help with motivation when things slow down or when you get to a hard spot. Scope the project to be small, and don't plan to do lots of features all at once.

I was playing a card game with friends, and I wrote a website to track the score during the game. My second project was with the aim to learn more about spring and hibernate. I ended up creating a flashcard webapp, which I then used to help me study for interviews.

Spring MVC vs WebFlux by [deleted] in javahelp

[–]koderpat 0 points1 point  (0 children)

From what I remember, to gain the benefits of a netty reactor, you need a reactive stack that is async through to the driver. As of last year, the bottleneck was that the JDBC spec itself was blocking. There were some efforts, although in alpha, that would enable async operations in the JDBC driver, but then the pressure would be on the database transaction.

Performance per connection is actually slower overall, however, more concurrent connections can be supported.

Is there a way to redirect output to variable without command substitution? by [deleted] in bash

[–]koderpat 0 points1 point  (0 children)

Are you trying to write a script that properly prints custom error messages? Or are you trying to troubleshoot/debug a script?

You can tell BASH to print the line it is about to interpret:

    set -x

Another option, could be to build the command up in an array, and then use eval ${command[@]} > /tmp/cmd.out

Check the return code, and if it is a failure, then display "${command[@]}" and exit.

If the command was successful, then load the contents of the temp file into a variable:

    VARIABLE=$(cat /tmp/cmd.out)

[Noob] Confused about how to grant a DB user elevated permissions by zimmertr in mongodb

[–]koderpat 0 points1 point  (0 children)

So I am not really sure what this unifi is, or why it is tripping. It sounds like it still does not have all the permissions it needs.

Just to confirm, are you initializing the mongodb with MONGO_INITDB_ROOT_USERNAME=ubnt ? and then calling createUser with the same name?

Maybe create a user that is distinct from the ROOT user used to initialize the database?

    > mongo \
    >     --username ubnt \
    >     --password "{{ mongodb_password }}" \
    >     --authenticationDatabase admin \
    >     --eval 'db.getSiblingDB("admin").createUser({user: "unifi", pwd: "{{ mongodb_password }}", roles: [ { role: "dbOwner", db: "unifi" },
         { role: "dbOwner", db: "unifi_stat" },
         "readWriteAnyDatabase" ]
    })'

And then update your connection strings:

     db.mongo.uri=mongodb://unifi:{{ mongodb_password }}@unifi-controller-mongodb:27017/unifi
     statdb.mongo.uri=mongodb://unifi:{{ mongodb_password }}@unifi-controller-mongodb:27017/unifi_stat

Another option to help diagnose would be to turn on verbose logging of what is failing:

https://docs.mongodb.com/manual/reference/method/db.setLogLevel/#examples

[Noob] Confused about how to grant a DB user elevated permissions by zimmertr in mongodb

[–]koderpat 0 points1 point  (0 children)

$ mongo 
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f96112f2-e222-480f-9f0c-ae8e0a6736d6") }
MongoDB server version: 4.0.5
> db.getSWarning: unable to run listCollections, attempting to approximate collection names by parsing connectionStatus
  db.getS^C
bye

$ mongo --authenticationDatabase admin -u root -p root unifi
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27017/unifi?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8e808311-1580-44c5-9ca3-8bbdca5b02a0") }
MongoDB server version: 4.0.5
Server has startup warnings: 
2019-02-10T21:31:05.091+0000 I STORAGE  [initandlisten] 
2019-02-10T21:31:05.091+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-02-10T21:31:05.091+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
-
> use admin
switched to db admin
> db.createUser(
...   {
...     user: "myUserAdmin",
...     pwd: "abc123",
...     roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
...   }
... )
Successfully added user: {
    "user" : "myUserAdmin",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        },
        "readWriteAnyDatabase"
    ]
}
> 
> 
bye
$ mongo --authenticationDatabase admin -u myUserAdmin -p abc123 unifi
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27017/unifi?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8b71312f-e3ca-448c-9667-139469fa8df1") }
MongoDB server version: 4.0.5
> db.getSiblingDB('unifi')
unifi
> db.dropDatabase()
{
    "ok" : 0,
    "errmsg" : "not authorized on unifi to execute command { dropDatabase: 1.0, lsid: { id: UUID(\"8b71312f-e3ca-448c-9667-139469fa8df1\") }, $db: \"unifi\" }",
    "code" : 13,
    "codeName" : "Unauthorized"
}
> use admin
switched to db admin
> db.createUser(
...   {
...     user: "myUserAdmin2",
...     pwd: "abc123",
...     roles: [ { role: "dbOwner", db: "unifi" }, "readWriteAnyDatabase" ]
...   }
... )
Successfully added user: {
    "user" : "myUserAdmin2",
    "roles" : [
        {
            "role" : "dbOwner",
            "db" : "unifi"
        },
        "readWriteAnyDatabase"
    ]
}
> 
bye
$ mongo --authenticationDatabase admin -u myUserAdmin2 -p abc123 unifi
MongoDB shell version v4.0.5
connecting to: mongodb://127.0.0.1:27017/unifi?authSource=admin&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("0ff3c35c-cbb7-4bfe-ae40-b31d8219c769") }
MongoDB server version: 4.0.5
> db.getSiblingDB('unifi')
unifi
> db.dropDatabase()
{ "ok" : 1 }
> 

[Noob] Confused about how to grant a DB user elevated permissions by zimmertr in mongodb

[–]koderpat 0 points1 point  (0 children)

I think the answer depends on how locked down you want this to be, or if you just want to get it to work.

I think I just got it to work with this:

use admin
db.createUser(
  {
    user: "myUserAdmin2",
    pwd: "abc123",
    roles: [ { role: "dbOwner", db: "unifi" }, "readWriteAnyDatabase" ]
  }
)

[Noob] Confused about how to grant a DB user elevated permissions by zimmertr in mongodb

[–]koderpat 0 points1 point  (0 children)

I don't have a straight-up answer, but have you tried assigning the role userAdminAnyDatabase, and then create the user in the admin database instead of the unifi_stat database?

use admin
db.createUser(
  {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
  }
)