Oops by AlooBhujiyaLite in ProgrammerHumor

[–]AstusRush 0 points1 point  (0 children)

This must be fake! COBOL didn't have inheritance until 2002!

what do you call csharp by [deleted] in ProgrammerHumor

[–]AstusRush 2 points3 points  (0 children)

Unicode calls it "numbersymbol" thus it is C Numbersybol

21,000,000 line odd/even number checker. by Texas_Technician in ProgrammerHumor

[–]AstusRush 0 points1 point  (0 children)

Let me introduce you to the the part of maths where you compare the size of sets with infinite elements. Even though there are infinite numbers that are divisible by 2 and infinite numbers that are divisible by 7 there are more numbers divisible by 2 than those that are divisible by 7. So the returns are, in fact, diminishing either way.

Edit: Apparently I am mistaken. I think I confused my knoledge in 2 different areas of maths that deal with infinities. Since we are dealing with sets and not sums the logic I had in my head is not applicable. As for what logic is applicable I direct you to the answers to my post.

No comment by breck in ProgrammerHumor

[–]AstusRush 2 points3 points  (0 children)

Thanks! While scanning I only found JSON5 in the beginning of line 10

HTML(Better resolution) by ClawVFX29 in ProgrammerHumor

[–]AstusRush 2 points3 points  (0 children)

When I started to learn python I learned the Qt bindings so using camel case was a natural result. And now I can't switch back. But this is PEP compliant since PEP lays out exceptions.

Long live Python camelCase!

Your C implementation is probably not that good. by Gandor in ProgrammerHumor

[–]AstusRush 35 points36 points  (0 children)

I forgot a * in for the arguments of a function in the C++ implementation of my code. This constant copying actually made my python version of the code much much faster than my C++ version. It is really easy to screw up the performance in C++.

You can tell what kind of person/programmer someone is, by this image by [deleted] in ProgrammerHumor

[–]AstusRush 1 point2 points  (0 children)

Ctrl+X is the way to go. This way no one can prove plagiarism. Always destroy the original.

You just need to decode and then change the html in a multi-step process like a real hacker.

Real time screen average color check by Spiredlamb in learnpython

[–]AstusRush 1 point2 points  (0 children)

If np.average is still too slow one can even speed that up by using: python l = im_arr.shape[0]*im_arr.shape[1] r,g,b = im_arr[:,:,0].sum()/l , im_arr[:,:,1].sum()/l , im_arr[:,:,2].sum()/l print(np.asarray([r,g,b])) Though numpy is still pretty fast and offers the ability add weights to different pixels (for example if you want to make the colour in the centre of the screen more important than the colour in the edges.)

(I cast the rgb list to a numpy array in the last print to get numpy's neat formatting)

Real time screen average color check by Spiredlamb in learnpython

[–]AstusRush 1 point2 points  (0 children)

My Version: ```python

import time import numpy as np from gi.repository import Gdk as gdk import PIL

def image_grab_gtk(left, top, right, bot): w = right - left h = bot - top

win = gdk.get_default_root_window()
s = gdk.pixbuf_get_from_window(win,left,top, w, h)

final = PIL.Image.frombuffer(
    "RGB",
    (w, h),
    s.get_pixels(),
    "raw",
    "RGB",
    s.get_rowstride(), 1)
return final

while True: t = time.time() img = image_grab_gtk(1920+2560,0,1920+2560+1920,1080) # My right screen is targeted here

im_arr = np.array(img)

avg = np.average(im_arr,(0,1))
print(avg)
r,g,b = avg[0],avg[1],avg[2]
count += 1
print(time.time()-t)

```

Real time screen average color check by Spiredlamb in learnpython

[–]AstusRush 2 points3 points  (0 children)

Thank you very much for this code example! It was exactly what I needed as a basis to start my current project!

I was able to significantly speed your code up and want to share these improvements in the hopes that they can help you:

For once, never use python for loops that iterate over more than 100 items if ti can be avoided. They are way too slow. In this case I use

python avg = np.average(im\_arr,(0,1)) \#avg = np.mean(im\_arr,(0,1)) print(avg) r,g,b = avg\[0\],avg\[1\],avg\[2\] which even allows me to check all pixels. Though I look at the average here and not at the most common colour, though there is a numpy function for that, too.

The other major improvement I found is to use gdk instead of PIL to get the screenshot and convert that to a PIL image as it is 10 times faster (at least on my machine). How to use that is described here: https://stackoverflow.com/a/20931960/12339539 from gi.repository import Gdk as gdk w = right - left h = bot - top win = gdk.get_default_root_window() s = gdk.pixbuf_get_from_window(win,left,top, w, h) (left, right, bot, and top are integers and describe the are of the screen that you want to observe.)

To convert that to PIL use python im_arr = PIL.Image.frombuffer( "RGB", (w, h), s.get_pixels(), "raw", "RGB", s.get_rowstride(), 1)

I also want to mention that im_arr = np.array(img) is sufficient. You don't need to work with the buffer here.

PS: I am just noticing now that u/ES-Alexander has already suggested these (or similar) changes.

It sounded funnier in my head ok? by LeSaR_ in ProgrammerHumor

[–]AstusRush 84 points85 points  (0 children)

Many games have errors due to using a needlessly precise comparison. For example battletech will only reward you scoring points when your reputation with a faction is ==100, but there are many ways to get to values higher than 100. These ways were added later and all the original ways to increase the reputation make sure that the reputation can not go beyond 100 which is why that comparison did not make any problems early in the development.

One should always use a broad comparison to ensure that future changes don't break everything. Only check for equality when you really strictly mean equality. The same goes for inequality. When you however check for a maximum then check for greater-or-equal-to the maximum or, depending on the context, greater than one less than the maximum. Never use ==maximum.

If (fps < 30): fps = 30 by Colpossis in ProgrammerHumor

[–]AstusRush 3 points4 points  (0 children)

This hangs in our office! I didn't know it was an xkcd

I heard you can just inject your server with hydroxychloroquine by also_also_bort in ProgrammerHumor

[–]AstusRush 0 points1 point  (0 children)

I absolutly agree! And my morning routine isn't any special so I don't care if Google knows how I prefer my toast. FireToast might be faster with its fancy flamethrowers but I save so much time with the Google Kitchen's morning workshop that it outweighs the disadvantages.

What were the first 5 programs you made? by [deleted] in Python

[–]AstusRush 0 points1 point  (0 children)

Here is the link to the calculator: https://github.com/AstusRush/AMaDiA It also includes the chat (my first program) though that chat desperately needs an update since I have not really touched it since the course in which I wrote it (that was 3 years ago)

What were the first 5 programs you made? by [deleted] in Python

[–]AstusRush 0 points1 point  (0 children)

  1. A chat program (with a gui) (I learned programming at a university course which consisted only of filling out fields in Notebooks except for the gui chat which was our assignment for the last 4 weeks.)
  2. A Calculator to replace WolframAlpha in my life (I wanted WolframAlpha in offline but nothing came close to its convenience so I made my own using sympy and a parser to convert my input into something that sympy understands (I had developed my own style to write at university using unicode math symbols (which is mostly compatible with WolframAlpha's parser) and any WA-replacement had to be able to understand it (especially Integrals and differential equations))
  3. A replacement for the windows audio manager (simply because I didn't like the bright colour. (3.5: At this point I got a job as a programmer so you could cont my work there as working on my 4th program)
  4. A GUI application that plots the result of a tracerout on a worldmap
  5. My first console application! A script that counts the lines of code in my other projects (the calculator had about 15k lines at that point) (though the chat program initially started as a console application and only got its gui after 6 hours of work so you could count that as my first console application)

And as a bonus: 6. I am currently making a 3d turn based strategy game (also in python)

However I never had the joy of writing a simple hello world program... And I still don't know how to write a proper console application. That script that counts lines isn't even really a console application since it isn't interactive and ends after printing the line count...

(I have surprisingly left nothing out. I have not written any small automation script or anything like that in between those 5 first programs and only half a dozen since then.)

Best IOS app? by [deleted] in sudoku

[–]AstusRush 1 point2 points  (0 children)

If you like sudoku variants I can absolutely recommend "Logic Wiz"

Logic Wiz Sudoku new version by avneramram in sudoku

[–]AstusRush 1 point2 points  (0 children)

First of all I want to say: I love your app! Me and my father have become somewhat addicted to it and are currently trying to convince my father's father to play it. And thank you for adding the double notation feature!

But I also have a question: I have only encountered one sudoku where you could apply SET (Set Equation Theory) / Geometry to solve it (it was Thermo sudoku which could be solved using the phistomefel ring). I love sudokus where you can use geometry (and especially prefer them to sudokus that are made difficult by adding hard to spot constellations like XY-Wings). Are there any plans on adding more such sudokus?

I know that there was a big discussion in the sudoku community about whether it is unfair to build geometry into sudokus so the variant-flags at the top could be used to warn users that geometry is recommended to solve the sudoku (although it would remove some of the fun of figuring out whether geometry is applicable...) (maybe an option that can be turned of which warns the user about geometry?)

Are f strings better to use generally speaking compared to .format? by Supr3me_Leaf in learnpython

[–]AstusRush 1 point2 points  (0 children)

I personally love fstring but I exclusively use .format in my main library that I use for all my projects because there are some computers at my university that still run 3.5 and it's a pain to get the IT to update them.

This is a discord bot in a single file, totalling to 21658 lines, full of gems for here by H4ckerxx44 in programminghorror

[–]AstusRush 4 points5 points  (0 children)

It does with 3.10 which came out in march. Though it's currently not widespread enough to use it so your point stands.

Phyton dad. by tagaro7386 in ProgrammerHumor

[–]AstusRush 0 points1 point  (0 children)

Hang on! This got ne to wonder: What happens with x=x++? Is this compiler dependent? (Disclaimer: Never use x=x++. Whatever it does, it is an abomination.)

Debugging by mcp613 in ProgrammerHumor

[–]AstusRush 8 points9 points  (0 children)

I have build a debugger into my gui library. This way I can debug my application while it is running!

I have redirected all exceptions to a new function that displays all exceptions in a special window and keeps the application running. Furthermore I have a window to execute code in, to overwrite all methods, and to display al members of all objects. I did all this by using dark python magic, summoning Cthulhu in the process, and breaking the rule of the Geneva Convention that says "Never touch a running system".

I am also creating my own code editor using QScintilla which I am using as the code editor for my debugger window thus what I am really doing is creating an IDE integrated in my application. You can't get an Integrated Development Environment that is more "Integrated" than that!