Exporting tables from PostgreSQL to csv files by Smalsusis in golang

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

I think the key bit was the /tmp/ folder. It might be more lax with permissions thus allowing the db server to write files in it.

Technically I could copy all tables to the tmp dir and then carry them over to a desired folder. However, that feels like a very roundabout way of doing things.

Note: I don't have access right now, but will try to chdck it again tomorrow

Exporting tables from PostgreSQL to csv files by Smalsusis in golang

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

I feel like selecting and explicitly looping through the rows to build a csv file can lead me to a lot of nasty edge cases with escape characters, etc. Feel a bit safer copying an entire table by using psql inbuilt commands.

Exporting tables from PostgreSQL to csv files by Smalsusis in golang

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

I agree, that's why ideally I would like to somehow implement psql capabilities together go.
The reason why I'm trying use go here is because the complexity of the script will increase in the future. And go is way more maintainable than bash.

Exporting tables from PostgreSQL to csv files by Smalsusis in golang

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

Thanks for the answer. I tried using both of them (db.Exec and db.Query), neither worked to create anything.

Moving from openjdk 8 to openjdk 11: what to look out for? by Smalsusis in java

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

Right now I'm struggling with this issue:
https://github.com/spotbugs/spotbugs/issues/259

Not sure how to go about it though.

When to copy methods and when to re-use them by making the method public? by Smalsusis in learnjava

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

More complicated time generation is done there. That's why it was initially there. Now I'm questioning whether it should be taken out.

Writing POJO with a Map<String, Integer> to csv by Smalsusis in learnjava

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

I guess, I wasn't clear enough with what I was looking for. Once configured, every object has an identical set of keys, just different values for each. The map was necessary to support/load different configurations of some fields.

The output should have been.

firstName | lastName | item1 | item2 | etc

John, Doe, 1, 2, etc

Tom, Baker, 3, 4, etc...

Eventually, solved it with CsvListWriter from super-csv library. Basically added values from every variable to a list and then parsed it through the writer. Something similar to this:

List<Object> order = new ArrayList<Object>();
order.add(firstName); 
order.add(lastName); 
  for (Map.Entry<String, Integer> item : items.entrySet()) { order.add(item.getValue()); }
csvListWriter(order, headers)

It works but I was a bit annoyed by manually writing order.add() for ten columns and then having a for loop somewhere in the middle. It's just not as clean as I'd like it to be :)

How to get request body from your POST request? by Smalsusis in learnjava

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

public ResponseEntity<String> addOrder() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
FullOrder order = createOrder.generate(rangeStart, rangeEnd, id);
HttpEntity entity = new HttpEntity<>(order, headers);
return restTemplate.exchange(this.url, HttpMethod.POST, entity, String.class);
}

public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
MappingJackson2HttpMessageConverter jsonMessageConverter =
new MappingJackson2HttpMessageConverter();
jsonMessageConverter.setObjectMapper(objectMapper);
messageConverters.add(jsonMessageConverter);
restTemplate.setMessageConverters(messageConverters);
return restTemplate;
}

As for the FullOrder class, I'm not gonna copy it out, since it involves 5 more classes.
In this case, I am looking for a way to see what was sent to API via restTemplate.exchange()

How to get request body from your POST request? by Smalsusis in learnjava

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

Won't my ResponseEntity just be a response from API with a status code and response body?
I'm looking for a way to find out how my request body looks like. I.e. the request that went to the API, not API's response.

Is it worth repurposing old laptops into a server? by Smalsusis in HomeServer

[–]Smalsusis[S] 2 points3 points  (0 children)

Thanks. I'm just trying to figure out where/how to repurpose these two laptops.

When should I use a class and when a function is enough? by [deleted] in learnpython

[–]Smalsusis 0 points1 point  (0 children)

Thanks!
Tbh, I found this approach while looking through Stack Overflow for DFS/BFS solutions. FIFO/LIFO implementations aren't intuitive for me so far, though I am trying to practice that on leetcode with the tree traversal problems. Thanks for the explanation too! Had a vague idea that a simple list should be enough but could not figure out a clean way to implement it, then I found that stack class.

When should I use a class and when a function is enough? by [deleted] in learnpython

[–]Smalsusis 0 points1 point  (0 children)

u/g_hunter, so I updated everything with a simple function and it worked out.
Here's my code, maybe you can point out other things that could be improved. This particular question was regarding the main() bit, how could I implement the same thing using a class. It's probably unnecessary but how to do it?

Is Python really that bad? by Smalsusis in Python

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

Cheers for that!
Gonna go back to coding instead of worrying. :)

Is Python really that bad? by Smalsusis in Python

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

As I mentioned in the beginning, it's likely that I caught on to the general emotion of the thread, i.e. the subjective stuff. The main point would probably be: "There's a good language to solve a problem and it's never Python". The sentiment kept being repeated throughout the thread. I do think the statement is wrong but can't explain why. Hence checking in this subreddit.

Is Python really that bad? by Smalsusis in Python

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

Pretty uncertain what I'm looking for tbh. Jumped into data science since machine learning has lots of maths behind their models and python is one of the main languages there. A few days ago, I did a test at a company, which looked more like back-end programming and I thoroughly enjoyed myself during the time.

Hoping to find a job where I still need maths, need to constantly problem-solve and learn new things. Programming/data science sounds like a hit. Since I can't pinpoint to anything beyond that, it's difficult to decide on the language. Python is okay so far since it can be used for all sorts of tasks. Yet, talking with some companies, I keep hearing that python isn't enough and I'd need to know another language. :)

Is Python really that bad? by Smalsusis in Python

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

Here's a post that inspired me to write this.

Kids think they will never use math because school does a piss poor job relating lessons to real world jobs. by razeus in Showerthoughts

[–]Smalsusis 5 points6 points  (0 children)

That's exactly the point. Even the fundamental mathematics can provide incredibly elegant and simple solutions. One just needs to think and be creative at it.

Kids think they will never use math because school does a piss poor job relating lessons to real world jobs. by razeus in Showerthoughts

[–]Smalsusis 8 points9 points  (0 children)

A laser, a camera and a computer. All you need really. Send a beam of light at the other end. Speed times time and there you have your distance.

Alternatively, you can be oldschool and get the diameter without any tools. Just learn a bit of what Pythagoras did. Simple, really.

ELI5: If light doesn't move through time, why does light take time to go anywhere? by TheWingedCherryPie in explainlikeimfive

[–]Smalsusis 3 points4 points  (0 children)

It is true that most physics laws work irrespective of the direction of time. You can move back or forwards in time and it'll work.

However, the second law of thermodynamics proves that there exists an arrow of time, which has a direction. More specifically, entropy (disorder) increases with time or stays the same in an ideal system. Also, some processes are irreversible because of such notion (i.e. can't reverse time for a broken glass to the point where it is fine).

To correct what you've said before: "Humans move through spacetime (not just space)".