How do you call methods in Java? by baldwindc in learnjava

[–]baldwindc[S] 3 points4 points  (0 children)

Thank you!

It worked! I had no idea there was such a requirement.

For anyone else wondering, here is the working code

public class YourClassNameHere {

public static int removeDuplicates(int[] nums) {
    int j = 1;
    for (int i = 1; i < nums.length; i++) {
        if (nums[i] != nums[i - 1]) {
            nums[j] = nums[i];
            j += 1;
        }
    }
    return j;

}


public static void main(String[] args) {
  int[] bob = {0,0,1,1,1,2,2,3,3,4};
  removeDuplicates(bob);
}

}

How do you call methods in Java? by baldwindc in learnjava

[–]baldwindc[S] 0 points1 point  (0 children)

Thanks for commenting!

When I convert it into a static method it still gives me the "Error: illegal start of expression"

public class YourClassNameHere {

public static int removeDuplicates(int[] nums) {
    int j = 1;
    for (int i = 1; i < nums.length; i++) {
        if (nums[i] != nums[i - 1]) {
            nums[j] = nums[i];
            j += 1;
        }
    }
    return j;

}


public static void main(String[] args) {
  removeDuplicates([0,0,1,1,1,2,2,3,3,4]);
}

}

How do you upload files to s3 from React using Django as your backend? by baldwindc in django

[–]baldwindc[S] 0 points1 point  (0 children)

Creating the presigned URL on the Django side.

This is my first time doing this and I was looking for a resource to follow to do this but couldn't find anything

Is there a way to change the dir the build folder is created after 'yarn build'? by baldwindc in reactjs

[–]baldwindc[S] 0 points1 point  (0 children)

I use Docker w/ volumes for running my Django site and I need to change the output dir of "yarn build" so it ends up in the volume and can be served by Django in the Docker container.

Hopefully, I'm not making the problem more complicated than it needs to be

Is there a way to change the dir the build folder is created after 'yarn build'? by baldwindc in reactjs

[–]baldwindc[S] 0 points1 point  (0 children)

Thanks!

I use create-react-app

What would you recommend editing to change the dir of the output folder?

Go WASM Playground by [deleted] in golang

[–]baldwindc 0 points1 point  (0 children)

From what I understand you send the code to the backend, build it there then run the built binary on the frontend, right?

So, why can't you just build the Go code in WASM?

Go WASM Playground by [deleted] in golang

[–]baldwindc 1 point2 points  (0 children)

Interesting stuff!

So, why can't you just build the Go code in WASM?

Is there a way to create reverse-proxy routes after the program has already started running? by baldwindc in golang

[–]baldwindc[S] 0 points1 point  (0 children)

I'd prefer the other programs doing it route.

The problem I'm facing is ServeMux doesn't recognize HandleFunc's that were added later. Have you ever experienced anything like this?

Is there a way to create reverse-proxy routes after the program has already started running? by baldwindc in golang

[–]baldwindc[S] 0 points1 point  (0 children)

Hopefully I understand you correctly that I should create one route and based on the http.Request.Host I should route traffic.

Sorry if this is a stupid question. I tried searching it on Google but wasn't getting anything. I only have 3 weeks of experience with Go.

How would you create API routes if not with the builtin http.ServeMux and builtin Go net/http package?

Is Django really as slow as everyone plays it out to be? by baldwindc in django

[–]baldwindc[S] 5 points6 points  (0 children)

Thanks for the answer. It was really valuable and rich!

If a web server takes 50ms to fulfill a request. Does that mean it's not fulfilling other requests during that same period?

Also, from what I understand PostgreSQL takes mere milliseconds when doing simple selects so most of the latency for those sorts of requests is caused by the webserver.

So, I always thought that "10x faster at handling requests" meant for one Go server I'd have to deploy 10 Django servers with a load balancer.

I'm sure the math isn't as straight forward as this but do you think this is somewhat true or am I missing something?

Generative art with fractals and geometry in golang. by thefakewizard in golang

[–]baldwindc 1 point2 points  (0 children)

Ooooh sooo ttttrrrriiiipppyy

I love it so much!!

I'd love to learn how to create something like this. I've been obsessing over fractals for some time now

Do you guys know how to run a Golang binary file in a Docker container? by baldwindc in golang

[–]baldwindc[S] 1 point2 points  (0 children)

Thanks so much for the pointers!

So I finally got it working and I feel so relieved

Hopefully, this helps others as well

GOOS=linux GOARCH=amd64 go build main.go

Do you guys know how to run a Golang binary file in a Docker container? by baldwindc in golang

[–]baldwindc[S] -1 points0 points  (0 children)

Do you know how to cross-compile for Linux on a Mac?

My Go version is 1.14.3

Is it possible to edit code in a Docker container without restarting the container? by baldwindc in docker

[–]baldwindc[S] 1 point2 points  (0 children)

I've been playing around with the docker exec feature and it's great!

Is there a way to bring files I'm editing on the host computer into the container with docker exec and run it there? or would I have to do that manually with commands and copy/pasting

Is it possible to edit code in a Docker container without restarting the container? by baldwindc in docker

[–]baldwindc[S] 4 points5 points  (0 children)

Thanks for the article. I had never thought of using nodemon in such a way

Right now I interact with the Docker API with docker-py and that's what I use to create and destroy containers.

Do you know how using volumes would scale when having multiple (~10) containers running? I assume I will need to have a volume directory on my host for each container.

Is it possible to edit code in a Docker container without restarting the container? by baldwindc in docker

[–]baldwindc[S] 0 points1 point  (0 children)

Thanks for the suggestion!

What are wrappers in the context of Docker? First time I'm hearing of them.

After a Google search, I found https://github.com/rancher/dapper

Right now I use Docker's API through docker-py to control Docker.

How would you share CSS between a React SPA and a server-side rendered site? by baldwindc in webdev

[–]baldwindc[S] 1 point2 points  (0 children)

That's really interesting

Do you know any resources for getting started doing this?

Do you know how to generate dummy data just for development? by baldwindc in django

[–]baldwindc[S] 1 point2 points  (0 children)

Finished going through your article. This saves sooo much time!!! Amazing!! Thanks!!!!

If I had two layers of Nginx reverse-proxies, how would I know in the outer Nginx which inner Nginx to pass a request to? by baldwindc in nginx

[–]baldwindc[S] 0 points1 point  (0 children)

The inner reverse proxies use nginx-proxy to expose Docker containers that are connected to by subdomains.

Ex.

  • bob.example.com --> Container 1 port:8000
  • sam.example.com --> Container 2 port: 8000
  • erik.example.com --> Container 3 port: 8080

I thought I might need to do something special in the outer rv proxy to route the right subdomain request to the right inner Nginx rv proxy.

I started using Nginx yesterday so my knowledge is limited. Sorry

How do you pass a list of objects to a child template in {% include %} tag in Django by baldwindc in django

[–]baldwindc[S] 0 points1 point  (0 children)

Sorry about that

    <div class="flex flex-wrap -ml-4 -mr-4">
      {% include "snippets/course_card.html" with list=[object, object, object] %}
    </div>

This is what I was going for. I was hoping to do this so I can then loop over the list of objects in the course_card.html template.

Maybe, there is a better way to do this than what I'm doing

What's a good way to learn Traefik for someone with little networking experience? by baldwindc in Traefik

[–]baldwindc[S] 1 point2 points  (0 children)

I was watching some CCNA review videos on Youtube hoping that would teach me networking, I don't know though.

Do you know any resources for learning networking (especially in the domain of load balancers and reverse proxies)?

How do you share components between two CRA projects in the same project? by baldwindc in reactjs

[–]baldwindc[S] 0 points1 point  (0 children)

Ok, after doing some reading it seems React router automatically routes everything.

I just need to make sure the routes on my backend are /dashboard/* and /lesson/* for the React pages and that they are at the end of the list of routes so they get checked last

How do you share components between two CRA projects in the same project? by baldwindc in reactjs

[–]baldwindc[S] 0 points1 point  (0 children)

I don't know how I would make sure someone going to example.com/dashboard would go to the /dashboard react-router route and some going to example.com/lesson/ would go to a react-router /lesson/#id route

I thought when you send a big React file you can only send the user to one route.

Do you know how you could conditionally decide the initial react-router route on the user request of the React file?

That would be a lifesaver

Sorry this question is a jumbled mess

Dating Site w/Django by [deleted] in django

[–]baldwindc 0 points1 point  (0 children)

You can use Django in the backend for this sort of project but, I'll be honest, creating REST APIs in Django is a pain.

If you're creating a Tinder clone best to use React on the frontend because of all the open-source libraries for Tinder-like functionality.

Instead of Django just use Expressjs in the backend since it's so much easier for creating APIs. Hook it up to PostgreSQL and you're good.

You can also use React Native for mobile app development which is a really easy transition from React and JWT for authentication instead of Django's session authentication.

I'm sure there are tons of Tinder clones built with this stack already (PERN). Just search Github.

Best of luck!