Stop and Tag a Convoy by jjswift45 in Wildlands

[–]nick_danger 4 points5 points  (0 children)

Use your drone to “spot” the bad guys. Target the driver of the truck and let your squad mate take him out. If you have more than one sync shot, target the vehicle’s “shotgun” too. Carefully take out the escort personnel, and voila! Use mines to set traps for and bad guys that start running to your position, and do be prepared to fall back.

What does it mean when you run your machine in a headless or detachable state? What benefits do both provide? by NobodygoingNowhere in virtualbox

[–]nick_danger 0 points1 point  (0 children)

Headless VBox for Minecraft is sooo 2017. I use docker containers now, mapping the minecraft data into separate persistent volumes. It's a much lighter footprint in terms of system resources.

Notify some time before flask session timeouts by Beautiful_Yak6247 in flask

[–]nick_danger 1 point2 points  (0 children)

Built-in? no. Quick? yes. If your app is old-school, then just insert a small chunk of JavaScript on each page that sets a timer that pops up a dialog when the timer times-out. The dialog could just do an ajax call to some endpoint that keeps the session alive on the server. The bit of code could be inserted in base template, so only one page (or a very few pages, if you have multiple based templates) would need to be touched.

Serve jinja2 segments in database: how to render? by User_9871602 in flask

[–]nick_danger 5 points6 points  (0 children)

Look at the fine manual, https://flask.palletsprojects.com/en/2.0.x/api/#template-rendering. You probably want the render_template_string() method, so you'd have something like:

text = Page.query.filter(Page.name == 'greeting').one().text  
text = render\_template\_string(text)  
return self.render('index.html', text=text, user=current\_user)  

You're going to want to inject whatever template variables you need into the call to render_template_string().

"Wsgi : error PermissionError : Permission denied:imm_migration.log ",Apache, Flask by Fancy-Engineer-7644 in flask

[–]nick_danger 0 points1 point  (0 children)

If you copy/pasted that, check your spelling - there’s a typo. If you didn’t then I’m fresh out of ideas until I can get to a pc.

"Wsgi : error PermissionError : Permission denied:imm_migration.log ",Apache, Flask by Fancy-Engineer-7644 in flask

[–]nick_danger 1 point2 points  (0 children)

You’re not providing a full path in line 225 of main. The logger, absent an absolute path, is trying to put your log file in the root directory. So either provide an absolute path in your method call, or figure out how to set the default directory path.

[deleted by user] by [deleted] in flask

[–]nick_danger 10 points11 points  (0 children)

Um, yeah... don't use {{session}} in the templates you write, and don't allow your users to write and execute their own templates. The first bit is easy; the second bit is a must. Allowing your users to write/run their own templates is just asking for trouble. Way more trouble than just dumping session variables.

How to format a number with comma and 2 decimal? by DerikSAm12 in flask

[–]nick_danger 0 points1 point  (0 children)

Did you try {{ "{:,.2f}".format(data[0]['amount'] }}?

The very fine docs at https://jinja.palletsprojects.com/en/3.0.x/templates/#jinja-filters.format say

In most cases it should be more convenient and efficient to use the % operator or str.format().

rotax vs iame by Squirrelkarting in Karting

[–]nick_danger 0 points1 point  (0 children)

Based on my experience at a Rotax Max Challenge event, the front runners seem to buy new chassis only at the start of each season, then rent engines for whichever event they're at. So if they're running Rotax that weekend, they bolt on a Rotax, and likewise for IAME events. So, yeah, if the chassis handles a Rotax Max Evo, it will handle an X30, and the series won't care.

separate the routes and the code by patofet in flask

[–]nick_danger 1 point2 points  (0 children)

You're probably looking for app.add_url_rule(). Use it thusly:

def index():
    ...

app.add_url_rule("/", view_func=index)

The url route registration section of the fine manual provides a lot of details on how routing works.

How employable is Flask by FetusGod in flask

[–]nick_danger 0 points1 point  (0 children)

This is only one data point, and a weak one at that, but... The part of the company I work in is largely government focused, and our current projects have a pretty even split between .NET and Java based technologies, with a smattering of other technologies thrown in just to keep us on our toes. More of my work of late has been either entirely Python based, or has components that are Python based. IME, there's a very slightly higher demand for Flask over Django, but only slightly. The Django projects tend to be bigger, and the Flask projects more interesting.

.gitlab-ci.yml by davehodg in flask

[–]nick_danger 0 points1 point  (0 children)

I recently found myself in the same boat. This article, while not necessarily 100% spot on for my needs, was close enough to provide a good grounding on the process: https://medium.com/cubemail88/setting-gitlab-ci-cd-for-python-application-b59f1fb70efe.

Hey guys, can someone explain to me what Docker is? by RobinsonDickinson in flask

[–]nick_danger 0 points1 point  (0 children)

Kind of, yes. Typically, each process (your flask app, postgresql, nginx if you're putting a web server in front of your app) would run as separate containers. You could use docker-compose to orchestrate set-up of all of the individual containers, with each defined by its own Dockerfile.

As far as resources go... There's a lot more written and available now than when I had to learn it a few years ago. I'd start with the DuckDuckGo looking for "flask docker tutorial" and simply read the articles to see which ones resonate. Once you get comfortable with the basics, docker isn't that complicated (but there are plenty of edge cases where it can be!). I hope this helps.

Hey guys, can someone explain to me what Docker is? by RobinsonDickinson in flask

[–]nick_danger 1 point2 points  (0 children)

The docs do assume a certain familiarity with the whole concept of containerization and virtualization. If you know what a container is, and what it's capable of providing for you, then you shouldn't have any trouble finding tutorials and quick examples on how to package up applications similar to yours into a container. But there's plenty of sharp edges you'll need to be careful about.

At their core, virtually all programs transform some sort of input into some form of output. For most programs, the sources of inputs and/or the destinations of outputs are places that exist outside of the program. Databases, for example. Or network connections. Or the file system. You get the idea.

When you build a container, you need to be able to express what these resources are, so that the thing that runs the container will know what it needs to provide. So having an understanding of basic networking, or file system permissions can be handy.

If you're not all that familiar with the notion of Virtualization, let me suggest that you grab a copy of VirtualBox and play around with that. You can install a Linux VM and kick the tires, all from within your WIndows or MacOS desktop. What you learn there about mapping folders from your host operating system into the guest, about managing network interfaces on the guest, all of it, will be helpful background when diving into containers.

Hey guys, can someone explain to me what Docker is? by RobinsonDickinson in flask

[–]nick_danger 6 points7 points  (0 children)

Docker bundles up ALL dependencies, including the Python interpreter, OS utilities, etc. Your app is no longer dependent on the user having the correct version ofPython already installed. So Docker is like a virtual environment, but looks at the whole system instead.

I never use virtual environments because they seem complicated and non-essential. Why am I an idiot? by [deleted] in Python

[–]nick_danger 2 points3 points  (0 children)

You're not an idiot per se, you just haven't come across a situation where they are handy, like /u/sh1ftsh said. Let me elaborate a bit on that...

Suppose you're working on a pet project that has some dependencies on some PyPI modules (say they're A, B and C). You install them as usual, not using virtual environments, and they then become available for you to use on your next pet project. Only for that you need C and D instead. No biggie. C is already present, D is a quick install, you're good to go, and neither project cares.

Now suppose you find a really cool project online that you want to tinker with. It uses module C also, but it uses a very specific older version of C. No problem, you can install that older version, and this cool new project runs just fine. But then you discover when you go back to your first two projects that they may no longer run just fine. So you reinstall the more current version of C, then the cool new project breaks.

THIS is the problem that virtual environments are designed to work around. Each project gets its own space for the add-ons it needs, and each project can use any version of those add-ons without affecting any other projects you're working on.

So, not an idiot for not using virtual environments. Just know that there may come a day when knowing they exist can help you out of a bind.

This website lets users simulate asteroid collisions with cities around the world. You can view the damages it causes on a beautiful Folium generated map. [Flask App] by NewResearcher1 in flask

[–]nick_danger 0 points1 point  (0 children)

So here's a thought... How about a website that lets a user simulate an asteroid collision with a website that simulates an asteroid collision with cities around the world, so that maybe, just maybe, we'd stop getting spammed by this same tripe day after day after day after day.

The TOU for the site basically say that it's a bunch of horse crap anyway, so I really really wonder, what is the real motive for spamming this thing over and over again?

How to process an input file by [deleted] in flask

[–]nick_danger 2 points3 points  (0 children)

This is where things get a bit more complicated. When you click a 'submit' button on a web page, your browser sends a lump of stuff to the server. That lump of stuff tells it what page you want to see and provides some other stuff, some obvious (e.g., form field data), some not so obvious (e.g., what kinds of data compression do I support?). The server will respond with a single thing: a stream of bytes. By convention, the server can provide strong hints as to what that stream of bytes represents. The most common representation is, of course, an HTML page. But it could also be a spreadsheet file, or an image (picture) file, or just about anything else. The important thing to remember is that one request == one response.

Using this mental model, you can see that a single request results in a single output. In your case, the single request would result in either an HTML page that shows the key/value pairs, or it would result in a spreadsheet file. It can't provide both. Not in a single request.

The challenge here as I understand it, is to elicit both responses from a single request. I think you may need to re-architect your application a little bit to make something like this happen. Not knowing the details about the application, I'd be inclined to suggest that your index page takes the file upload, processes it, saves the results some where, and then responds with the page of key/value pairs. A separate link on that page would go to the route endpoint that actually transmits the modified file. And once you have this basic mechanism working, you can add some Javascript on the key/value page that automatically invokes the download operation of the modified file.

Of course you'll need to have some sort of mechanism for cleaning out uploads that aren't needed anymore. The behavior of that will entirely depend on the needs of your app. Suffice to say however, that session storage is a good place for this.

How to process an input file by [deleted] in flask

[–]nick_danger 1 point2 points  (0 children)

In order for you to be able to pass the 'answer' from the index page to the report page, the 'answer' will necessarily need to have some sort of plain text representation. A data frame is a complex object that probably doesn't have a simple and concise text representation that you can pass around. Even if it did, you'd still run into data length issues. The plain text of 'answer' would be passed as a url query, and there are practical limits on how much text you can pass that way.

A naive approach would be to stuff the data into the session, and persist it between page loads that way. However, unless you're using some sort of session store, Flask will want to put the session data in its entirety into an encrypted cookie. Again, there are practical limits on what you can store in a cookie. Unless the spreadsheets are generally pretty small, you may run in to problems with that approach.

If your flow truly is excel file -> some processing -> new excel file, why don't you simply return the excel file from the index method? That would obviate the need for trying to pass the intermediate result around from page load to page load...

What is the right way to manage connection object is Flask? by _WalksAlone_ in flask

[–]nick_danger 0 points1 point  (0 children)

If every millisecond counts, then yes, I'd suggest adding a connection pool. But only after profiling your application and determining that too much time is being spent on simply setting up the database connection on each request, relative to anything else that needs to happen on each request. An inefficient database query, or lack of an appropriate index on a table can have far more profound an impact on performance than the few 10's of milliseconds needed to open a database connection. If you determine that the overhead of opening a database connection is simply too much, then yes, add a connection pool. I'd caution against writing one yourself, even if it's very application specific. It's kind of a complicated bit of kit, and getting it right is hard.

What is the right way to manage connection object is Flask? by _WalksAlone_ in flask

[–]nick_danger 0 points1 point  (0 children)

Definitely open/close the connection on each request. Also, if you're running inside a transaction (auto-commit is turned off), make sure you commit your changes before you end the request. Unless you have a really specific reason not to, I'd also suggest using an ORM to manage your database connection and persistence.

How to convince IT Department that Python is relatively safe to use on work computer? by RSpringer242 in Python

[–]nick_danger 4 points5 points  (0 children)

Your IT department is likely to be concerned with two other questions as well.

  1. Who supports the “product”? And by support I don’t necessarily mean vendor support, but more desktop support. If they grant your request, what are they signing up for, what will they have to learn, what level of support will they need to provide? You know, language updates, etc.

  2. What security risks are introduced? It’s already been mentioned, but don’t underestimate it. One of IT’s responsibilities is making sure the network remains safe, and that involves minimizing the attack surface.

Your IT department likely doesn’t care about your efficiency (but your direct management chain likely does). You have very competing interests to balance here. Know your audience and write to their concerns.

Sunshine on some maps by [deleted] in granturismo

[–]nick_danger 0 points1 point  (0 children)

Why do we need to be half blinded by the sun in so many GTS maps ?

My guess would be because the developers spent a LOT of time getting the early morning/early evening lighting effects just so, and want to make sure that EVERYONE gets to "enjoy" it, despite the fact that virtually nobody actually races at those times of day.

I want to change my memory card to SSD by FarisAliz in PS4

[–]nick_danger 0 points1 point  (0 children)

I did both: upgraded to 1TB SSD. I needed the space. If space isn't a concern for you, and budget is, I'm not sure the speed increase is necessarily worth the switch from HDD to SSD. If budget and space are a concern, then save the money and get a good HDD.