someone can help me convert this code to python please
for (int i = 0; i < myArray.Length; i++){ if(myArray[i] < 1 || myArray[i]>5 ){ valido = false; break; }
How do i convert this code to python ?
Dim mayorSec As Integer = 1 Dim mayorSecAux As Integer = 1 Dim numeroMayorSec As Integer = 0 Dim numeroAux As Integer = 0 Dim i As Integer = 0 Do While (i < myArray.Length) If (myArray(i) = numeroAux) Then mayorSecAux = (mayorSecAux + 1) Else mayorSecAux = 0 End If
If (mayorSecAux > mayorSec) Then mayorSec = mayorSecAux numeroMayorSec = myArray(i) End If
@EduardoHerrera Please use a code sharing service like dpaste or ppaste to share the code and also try to explain a bit what this code is doing as we may not be that good with Cpp (or C)
Hmm. I do not understand C# there but based on what you wrote as a requirement, do you just need the frequency output of each number in an array, right?
A quote from your second paste: """Write a program in CTM that prints the highest number of the array""", do you only need the maximum number or a histogram of all occurrences of numbers?
I would also like to know, but pitifully the page I use test or the test does not demonstrate the expected result, I wrote it in visual basic.net and it worked perfect, now I am asked in python. I assumed it's just converting the vb.net to python.
@EduardoHerrera In your second problem, you have an array and you need to print the highest number in that array (not the number with highest number of occurrences), right??
@EduardoHerrera you're confusing me again. Do you mean the number which has highest number of occurrences, or the number which is greater than other values?
cbg, is there a ELI5 for thread(multithread) vs multiprocessing? some site that shows when to use what?
I want to write a script (no gui, so no blocking) that downloads images from a list of urls, I want to get the maximum network usage here, so thread or multiprocessing?
I think threading is the solution here but then I see mentions about GIL which I think is above my level as of now
Just do not forget to maintain the same session while scraping :) that's will count as thread safe. where in the backend you maintain the same TCP connection which will prevent multiple TCP flags to establish & close while you are out of same session. that's will count as DDOS attack :P flood etc
@αԋɱҽԃαмєяιcαη well I am needing to store full names within this app in a field however not quite sure what size is a reasonable limit for this type of field
@roganjosh with qlalchemy it isnt a requirement when setting the models ? obviously am using flask-migrate so shouldnt be to difficult to change if needed just curious for production what would a decent limit be
came with comment field although may leave that to 255 and force them to make smaller comments ;/
No, SQLA should take an empty String() data type. I'll have to double check but I think that's an optional optimisation, at least in the case of Postgres. For SQLite I think it, as usual, will ignore the character limit. It's equally possible that some RBDMS will pick an arbitrary size
There can't be a decent generic limit - how would you cope if your db stored SO answers and then Aaron came along? :P
Then again, if you're storing a hash or a UUID or a name, you can make some either exact predictions or reasonable assumptions
Hmm well is it takes an empty db.String datatype then may leave that for comments, hwoever names surely 255 should work well considering english and spanish names I cant think there will be many with more than 255 characters
fast question does slug url with id is accepted by google ? i mean when i add website and pages to google search console for example example.com/url-1 ?
here is a screen shot, i am trying to access pipliens.app from core.app
the error is : Traceback (most recent call last): File "core/app.py", line 6, in <module> from pipliens.app import Pipeline ModuleNotFoundError: No module named 'pipliens'
PyCharm should already have set up the import search path to include all these folders. But the proper approach is to create a single, self-contained package.
Question to anybody familiat with flask-login and flak-session. I am currently trying to get users to login to the site and once they do have their permissions level set based on position which is saved to the same table as the user.
When using flask-login I can get them in easily, however can I access say user['position'] with flask login in order to set the permissions based on whether it is a manager, employee or admin? or is it better to save the position into a flask session-variable to access as needed?
Does someone know a package that scans a file for its mime type? The package shouldn't just scan the header of the file, it should scan the whole file thoroughly to ensure it hasn't been manipulated.
Yeah, no, there's no way something like that exists. Nobody in their right mind would create a program that can decode all image, video and audio formats, (un)compressed archives, office document files, and all the other file types that exist
Use one tool to detect the mime type, and then another tool to verify that the file is valid
In the interest of accuracy I booted up my other laptop and timed it. I admit that 90 second was an exaggeration; it only took 88.30 seconds. I apologize for the deception
Of course, my laptop is at its slowest right after a fresh bootup, so that measurement is hardly representative of my usual experience. I'll time it again during lunch, as it should have cleared out all the crufty startup processes by then.
Hmm, okay, how do I say this... Does this laptop have a rotary knob on the front? Is it the kind of laptop where you put in a slice of bread and a few minutes later you open the lid and it has turned into toast?
@Kwsswart It's not a good setup to have the customer access stored in the same table as the customer data
Ideally you would want a many-to-many between the User table and the Permissions table
It can be quite convoluted to implement a decent and extensible access system. There is Flask-principal but I've never used it. Later on I can share an example from my dashboard if you want to try rolling your own
How not good of a setup are we talking here? "functional but very hard to customize/extend"? "glaring security hole"?
Certainly I'd implement fine-grained permissions for medium-to-large applications, but maybe for a little internal app, having just employee/manager/admin might suffice for v1.0
It's just not considered good database design anyway, if you're trying to follow correct database normalization. Even with a small app I may want to subdivide some permissions between two existing levels and give different people combinations of those new permissions; your app already becomes a mess and I wouldn't say it was an unreasonable thing you'd need to do
Does someone know how to change the header of an jpeg file? I want to change an image header to be considered as something else (like a .wav file or so)
You only have to figure out the approach once and then you just drop the ~100 lines of code into the project's auth.models.py and you instantly have a fully extensible system
Certainly, subdividing permissions is a reasonable requirement. But if your client doesn't give you that requirement, well...
I suspect we're both converging upon the same conclusion of "developers must use their best judgment to strike a good compromise between extensibility and YAGNI. History indicates that very very often, you are eventually going to need fine grained permissions, even if v1.0 doesn't require it"
many-to-many that ends up being one-to-one is virtually no overhead provided that you set up an index on the association table, so it's a do-once-and-forget-about-it even if you never end up using it
But yeah, storing it in a single table isn't "broken" off-the-bat :)
Hmm, I think I just "picture of a bird"ed myself on a personal project I've been kicking around. I want to be able to crawl through an artist's twitter feed, stripping out any retweets and posts that have no images...
(easy API call, give me a couple hours)
... And also filter out any boring pictures of their housepets and animal crossing villages
@Kevin it could just say "yes" all the time (with a random number generator to appraise the art) and may be contended as the one of the toughest art critics of all time
But seriously, a NN might be pretty good at distinguishing art from video game screenshots and photographs of cats. The majority of the artists I follow either work entirely in black and white, or draw their subjects over a featureless solid color background.
I worry that if I google the artist, it will return both images of their art, and pictures of their cat. So I'll still have to do the manual work of categorizing them.
Ok, I've tried google images on the first artist in my queue, who happens to share a name with a city in India. I get pictures of his artwork and pictures of the city in a 20-80 split.
Admittedly, most artists do not share a name with a city, so this is something of an outlier
Morbi, a municipality in Morbi district in the Indian state of Gujarat, and also the artist/writer of once-popular now-defunct webcomic Poppy O Possum
Actually in his specific case, scrolling through his timeline is aggravating not because of pictures of his cats, but because he retweets his old artwork about four times as often as he posts new artwork. So I don't necessarily need the cat detector for this one, just the retweet remover.
@roganjosh I am curious I am working on a item for the company I am at as a personal project and was thinking of using the flask-login current_user.position variable which will be set at registration to either manager, admin or teacher. And through this was thinking forcing redirects if their try access parts of the web app where you need to be a manager to use i.e. staff registration, student registration, class creation etc
@roganjosh Would be very curious to see I was thinking of using a similar system to the one used in the flask mega tutorial you guys recommended i look through a while back. As its simple to implement, however would like to see the way you suggest at some point.
Here's one possible reason you might want permissions that are more fine-grained than manager/admin/teacher: perhaps the manager of the Arts department should not have permission to create classes for the Science department.
Perhaps the manager of the Physical Education department is a good guy, but tends to destroy any computer system he touches, so he has no permissions, and his class creation duties etc are delegated to the Computer Science teacher.
@Kevin I get what you mean. Although it is an english adacemy so slightly less complex but the reasoning still stands, how would be best to set the permissions
A separate table keyed by user is a good start, certainly
I'd be inclined to have more than one field, though. Perhaps separate fields for "can register staff" and "can register students" and "can create classes"
Or something even more elaborate if you want to support "can create Arts classes, but not Science classes"
@Kevin Cbg! In a past life, I worked in a project where permissions were structured like paths, so that Classes/create/* could create all classes, while Classes/create/Science could only create Science classes. It has been a while, and I think in retrospect I would probably put the create/read/update/etc. operations at the tail end of the path. But that was a pretty fully featured app, with many sub-domains and corresponding permissions.
I, too, am curious about what roganjosh's many-to-many design looks like. The simple design I have in mind uses a one-to-one table, and the complex design I have in mind is one or more one-to-many tables
The benefit this has over hardcoding admin/manager/teacher into your model logic is that you can create new roles and modify the permissions of existing roles without having to change any of your code
Ugh, coming back to a project after a few weeks/months after you decided you are too lazy to write unittests, because "it works" and now hating yourself.
Also looking at code and being confused, because it can't even work at all like this. But being 100% that I manually tested this and it worked :D Oh Dante
@Kevin Oh yes, that is very likely it. User <-> Role is many-to-many, and then the permissions are attached to Users and Roles alike (so that a user in Role "normie" can still be given special permission to "Blurb/Gornitz/frobnicate").
@AndrasDeak hahaha, yes :D Well I could delete code, which is always my favorite part of coding :)
But it definetly doesn't help that the modules who have to interface with each other share 3 out of 4 letters and that they are just accronyms and totally meaningless. In the see of characters on the screen it's so easy to get them mixed up and I just did
on the bright side. That python package version numbers have to increase I always found annoying. Now I'm so happy to just see oh it's the newest version and not having to double check the sources :P
Style poll: d is a dict populated by json from a service I don't control. Should I do user_address = d["userAddress"], or userAddress = d["userAddress"]? PEP 8 says "be consistent with surrounding code", after all...
@Kevin Well its a bit simpler of theres 3 main aspects in the company those that access and update class progress, those that search for details in the system, add classes, students and teachers and those that add students and use it simply to get details of students and classes
Hence why i was thinking using those 3 names to signify permissions
@Hakaishin Would love to find a good resource eto learn unit testing
For example, there were "unique" pages on my website such as a single page for stock levels. That's locked down based on a general permission. However, each department also had its own page which was a standard page just showing data specific to a department. In which case, I had another permission level, so it ended up being 3 tables
@Kevin Create a dataclass with var names in snake case, and then do obj = MyClass(**json.loads(config_json_with_ugly_java_like_names)). Then you can do obj.user_address.
@Kwsswart this is a dpaste of the auth file for the dashboard. I did actually refactor it a bit to clean things up but I can't put my finger on that version right now
I think you'd need some code in post_init to do the actual name assignments, since MyClass's init will expect snake_case names, which you aren't getting.
I thought this was a no-brainer tbh. Create a pythonic interface for the API, and keep the camelCase stuff in there along with all the other API-specific stuff. What design decisions are there even to make here?
@Aran-Fey I guess I'm just once-bitten-twice-shy because one of my work projects uses ALLCAPS for table and column names, and the ORM uses PascalCase or camelCase for attribute names depending on accessibility level, and the front end uses snake_case for form element names...
@Kwsswart No rush. One more piece to the puzzle, you can register a function in your app's __init__.py to allow for front-end validation too. Though if I was still working on that project I'd probably fix that function to not establish a new connection on every call. It went in years ago and I forgot to change it :P
@roganjosh - ok, so your many-to-many is User <-> Permission, where permissions are actual managed objects instead of just values like path strings. If you didn't make permissions actual objects, a User -> permission string table would probably suffice.
@Kevin For multiple duplicates, just keep adding more underscores to the front
@Kevin How would you end up with duplicate names? What kind of names are we even talking about? Instance attributes? Local variables? And how do you get duplicates?
@Aran-Fey For example, the ORM requires the User model to have the private attribute string _Address, and the public property string Address, which by default is a simple setter/getter on _Address
I know that recentish versions of C# let you magically declare private/public attribute/property pairs automatically, but I'm not sure the ORM allows that. It does some weird reflection stuff at runtime.
Student/update vs. Student/Humanities/update vs. Student/1729/update. The leading part is actually starting to look kind of REST-ish, and the tail end is the permitted operation.
I don't really get it. If the ORM requires a private attribute, then the _-prefix is fine. What would be different here if you were to compromise with variable names? Would you name the public one address and the private one Address?
In reality it's only a 5 min job to set up the base permission groups. Someone with Master access then can click a few buttons on the admin panel to configure new user with set departments and specific permissions. It perhaps is over-engineered but I start every project with this system anyway because I never want to preempt what I might need over project lifetime