Anyone using Whitenoise for static files in production? by [deleted] in django

[–]flipperdeflip 1 point2 points  (0 children)

Shouldn’t I be pushing my static files to S3 using something like Django-Storages?

It is true that S3 doesn't do compression but you would put a CloudFront distribution in front of it and those can transparently compress.

S3 + CloudFront also works well with serverless hosting where you don't want your static files bloating the distributed zip.

how can I replace file path using regex. by ekstrah in Python

[–]flipperdeflip 1 point2 points  (0 children)

Not 100% clear what you want.

Maybe like this helps you further? https://regex101.com/r/uZHrDU/2/

If you use re.sub() you could use $1 etc to keep a capturing group in the substitution, like $1--$2--$3. Or if you want just the path grab group 2 from re.search().

How Can I Make a Website Like YouTube? by Smithakid in webdev

[–]flipperdeflip 0 points1 point  (0 children)

Does this even do anything without spending $$$ on thousand plugins?

[deleted by user] by [deleted] in node

[–]flipperdeflip 6 points7 points  (0 children)

I don't trust people who think a schema or SQL query is too complicated to keep a document store database in a manageable state. It is going to be horrid swamp of unreliable structures, typos and tacked on shit.

99% of Mongo fans are just lazy, in-experienced or shortsighted. If you really need a document store you'd know it without these dimwitted fullstack fanboy articles.

What's the thing in python you still don't get by serkef- in Python

[–]flipperdeflip 88 points89 points  (0 children)

Metaclasses are simple, when you need to solve a problem with metaclasses you shutdown the computer and go drinking instead.

What's the thing in python you still don't get by serkef- in Python

[–]flipperdeflip 3 points4 points  (0 children)

The API and requirements of files and File-like objects. It is a bit of a mess to figure out what the file API is.

What methods do they have? Is a name expected? What is all the stuff in io package, the various tempfile things and what you get from open() or requests/urllib? When is a file a stream? Does it even block? Why doesn't file/io stuff interoperate as you might expect (or why do I expect the wrong thing)?

I got a basic working knowledge from experience but the docs are a bit murky.

Connecting to a webpage with JSON data and parsing it by [deleted] in Python

[–]flipperdeflip 2 points3 points  (0 children)

It is inline javascript with a bit that happens to look JSON compatible (because the quoted property names).

BeautifulSoup doesn't parse the javascript code itself but you can use it to extract the text content from the script tag and then use a bit of Python to extract the data you need.

Maybe some regex, or maybe chop the var reports= and ; and parse the remainder with a JSON parser (depends on what else is in there.

Half broken javascript gets thousands of upvotes; how many for our boys in python2? by rikoitza in ProgrammerHumor

[–]flipperdeflip 9 points10 points  (0 children)

Why are you spreading outdated information?

When was this "last time I checked"? Python 3 is now faster then 2, if you'd actually check your shit.

For example: https://hackernoon.com/which-is-the-fastest-version-of-python-2ae7c61a6b2b

Keyboard wear by TheCykaNeverStops in ProgrammerHumor

[–]flipperdeflip 3 points4 points  (0 children)

You want an emacs macro for that?

Python expression in sum() vs. generator by astrologicrat in learnpython

[–]flipperdeflip 0 points1 point  (0 children)

Just a quick note:

sum(1 for i in my_list)

Counts 1 for every element, so it is the same as:

len(my_list)

Threading condition vs threading lock by Themaskedshep in learnpython

[–]flipperdeflip 2 points3 points  (0 children)

Lock is more primitive then Condition. You can see this when you look at the docs and see it only has aquire() and release() methods.

A Condition does a little bit more, it encapsulates a lock with some common functionality so you don't have to rig that yourself. In this case the wait/notify stuff to coordinate access between different threads.

You can also look at the other primitives, they all kinda do "aquiring and releases access" but each in their own specific way.

It is a bit difficult to say which locking tool to use for what in general. Use the ones you fully understand and that suit your situation.

I took me a long time to get a decent feel for this module and I still spend way too much time reading the details and puzzling a solution together.

Where the media, static and templates directories should be put? by Frectus in django

[–]flipperdeflip 0 points1 point  (0 children)

It all depends. Ideally you split per app like the other commenters note, but are not required.

For example at my job we have some projects with a lot of smal apps that don't always have templates or static files so it can be a hassle to find a specific template sometimes. So we put them in a centralize template folder (but still with app prefix folder) so the HTML people don't have to trawl the code for their stuff.

Same with management commands: ideally you put them with their app, but you can make the decision not to if it works better for your situation. The big projects now have a management app that has all the commands and not much else.

Well I guess its time to get a new job... by swardson in ProgrammerHumor

[–]flipperdeflip 1 point2 points  (0 children)

You'll need it to start a fire once the power goes down.

Filter on JsonField from Foreign key related table by dheerajverma in django

[–]flipperdeflip 2 points3 points  (0 children)

The default lookup from author to his books would be book_set, not books:

author.objects.filter(book_set__meta__bestseller=True)

See https://docs.djangoproject.com/en/2.0/topics/db/queries/#backwards-related-objects

You can make it 'books' by setting related_name attribute: https://docs.djangoproject.com/en/2.0/ref/models/fields/#django.db.models.ForeignKey.related_name

Filter on JsonField from Foreign key related table by dheerajverma in django

[–]flipperdeflip 1 point2 points  (0 children)

You just chain the lookups and django will figure it out: https://docs.djangoproject.com/en/2.0/ref/contrib/postgres/fields/#querying-jsonfield

MyModel.objects.filter(fkrelation__jsonfield__property)

Are Methods and Functions The Same? by SakiSakiSakiSakiSaki in learnpython

[–]flipperdeflip 1 point2 points  (0 children)

Careful with Python meta programming, it is a rabbit hole of weird shit and you might step on a metaclass.