« first day (3272 days earlier)      last day (1677 days later) » 
00:00 - 19:0019:00 - 00:00

12:14 AM
@Kamori I expected the first one to give me an error, and it does
 
 
2 hours later…
2:10 AM
Hello, I have a problem. The description of the problem starts here(and please don't assume that it ends after the first message, it would continue unless I state so):
Snail Sort

Given an n x n array, return the array elements arranged from outermost elements to the middle element, traveling clockwise.

array = [[1,2,3],
[4,5,6],
[7,8,9]]
snail(array) #=> [1,2,3,6,9,8,7,4,5]
I have to implement this the above algorithm
My code:
m = sample list of list
m = [[ 1,  2,  3,  4,  5],
 [ 6,  7,  8,  9, 10],
 [11, 12, 13, 14, 15],
 [16, 17, 18, 19, 20],
 [21, 22, 23, 24, 25]]
def t(m):
if len(m[0]) == 1:
    return m[0]
mArray = []
arLen = len(m[0])
for i in m[0]:
    mArray.append(i)
for i in range(1, arLen):
    mArray.append(m[i][arLen - 1])

for i in range(2, arLen + 1):
    mArray.append(m[arLen - 1][arLen - i])

for i in range(2 ,arLen):
    mArray.append(m[arLen - i][0])

slice = [m[i][1:arLen - 1] for i in range(1,arLen - 1)]
mArray.append(t(slice))

return mArray
Expected output:
[1,2,3,4,5,10,15,20,25,24, 23,22,21,16,11,6,7,8,9,14,19,18,17,12,13]
Received output:
[1, 2, 3, 4, 5, 10, 15, 20, 25, 24, 23, 22, 21, 16, 11, 6, [7, 8, 9, 14, 19, 18, 17, 12, [13]]]
I thought to append into marray element but that didn't work too. Here is my function of doing so:
def elCopy(A,B):
lenB = len(B[0])
for i in range(lenB):
    for j in range(lenB):
        A.append(B[i][j])
Received output 2:
[1, 2, 3, 4, 5, 10, 15, 20, 25, 24, 23, 22, 21, 16, 11, 6, 7, 8, 9, 12, 13, 14, 17, 18, 19]
The expected output is, of course, the same as the last one. Question: What to do?
The description of the problem ends here!
 
If your code is longer than about 12 lines, use an external paste tool such as dpaste.com.
 
2:31 AM
Okay. Ignore the message, will try next time.
 
Yes please, that would be nice; it is not very welcoming to see a wall of code upon entering; it also cuts discussions with a large gap, in the case there are ongoing ones.
For your problem, it seems likely there is a closed form formula to transform the indices; that is probably the direction I would take.
 
2:59 AM
Can you please elaborate a bit more?
What is the problem with my code?
 
 
4 hours later…
6:59 AM
@Kamori they don't. you seem to have a previous value of _. For me the result is [[__main__.Foo, object, __main__.Foo, object], [__main__.Foo, object, __main__.Foo, object]] in the first case.
cbg, by the way
 
cbg @MisterMiyagi
 
7:15 AM
cbg all
 
7:44 AM
Hmm, apparently vars silently swallows any kind of exception that happens during the __dict__ lookup process. Not sure if that's intended...
class MyClass:
    def __getattribute__(self, attr):
        raise ZeroDivisionError

obj = MyClass()
vars(obj)  # TypeError: vars() argument must have __dict__ attribute
obj.__dict__  # ZeroDivisionError
I kind of expected vars(obj) to be equivalent to object.__getattribute__(obj, '__dict__')
Guess I'll have to replace all occurrences of vars in my serializer's code later
 
I have a vitally important question for you all: what pun is this referring to?

While use of nested classes is often considered poor style, the only reason for them to have second class introspection support is a lousy pun.

-- https://www.python.org/dev/peps/pep-3155/
 
because a nested class is a second class
 
I'm still confused
Nevermind, I realized I'm dumb
 
it is a lousy pun
 
how do I convert binary to ascii? Like the output of bin() back to char or something?
I'm looking at binascii but not sure which of it
 
7:59 AM
>>> chr(int('1001011', 2))
'K'
 
I see, that means my code is wrong lol
 
8:12 AM
huh, now I finally know why __qualname__ was introduced and what it's good for
 
8:28 AM
On a scale from 1 to 10, how readable is this code: map(next, map(itemgetter(1), groupby(iterable, key)))
*5 minutes later* I guess everyone's still trying to figure out what the heck it does
 
that's a solid 2 from me
 
@Aran-Fey 1 but only because I've never figured out groupby
 
The worst part is that this code is straight from the docs, specifically it's the unique_justseen function from itertools recipes
apparently (x for x, _ in groupby(iterable, key)) was too readable or something, idk
 
right, how is map(next, iterable) different from iterable anyways?
 
8:45 AM
I thought the same thing, but it's actually a completely different thing. map(next, iterable) only works on an iterable of iterators, and yields the first element of each iterator.
 
D=
 
Right
 
now I understand the code, and am ever more thankful that guido declared comprehensions > lambdas
 
9:06 AM
@Aran-Fey itemgetter and friends are -2 on readability for me. three levels of nesting don't help either.
 
9:19 AM
@Aran-Fey I want to change my answer to 0
 
I think you mean that it's equivalent to:

`(next(g) for _, g in groupby(iterable, key))`

Also, if you want to use `itemgetter`, one option is to split into two lines:

`groups = map(itemgetter(1), groupby(iterable, key))`
`first_items = map(next, groups)`

The main problem comes from using `map` twice. It's essentially function composition:

`map(f, map(g, xs)) == map(lambda x: f(g(x)), xs)`

...but that's not a common enough pattern to be obvious.
How does one do code formatting in chat? o_0
 
@Arne Ah, thanks. Oh well, it's too much work to fix it and it's kind of readable as proportional font anyways. :P
 
user10984358
9:45 AM
heya guys, i have to know what happens in the snippet and also why not all my memory is used before i get MemoryError
 
user10984358
from string import ascii_letters
from itertools import permutations

genExp=(permutations(ascii_letters,i) for i in range(1,len(ascii_letters)))
list(map(list,genExp))
 
user10984358
i eventually get MemoryError but when i do list(map(list,genExp))
 
user10984358
i can still get MemoryError again, does that mean a part of the generator was exhausted and not the whole?
 
Generators are lazy
 
user10984358
>>> list(map(list,genExp))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError
>>> list(map(list,genExp))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError
>>> list(map(list,genExp))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError
 
9:46 AM
@TheNamesAlc Ah. How does it keep going? Interactive session?
Yeah, it keeps consuming the same iterator.
The incomplete list is discarded, but you can't unconsume the generator
 
user10984358
so some of my data was lost during those MemoryErrors then
 
Yes. Most of it.
 
user10984358
also why doesnt it take up my whole RAM?
 
user10984358
i fired up task manager, my ram usage was 8.8 GB before i hit enter
 
user10984358
and it gives me a MemoryError my RAM is at 10, i have 6 left
 
9:49 AM
Perhaps some process-level limit, ot the spike is too sharp to notice. No idea.
 
user10984358
the whole purpose of this was to convince someone of using generators i guess the MemoryError should suffice, thanks!
 
allocating RAM to your process is the responsibility of your OS
why you don't get all of it highly depends on which OS you have and how it is configured
 
user10984358
windows 10 here, might try the same on my laptop when i have the time
 
once of those RLIMIT_* will probably tell you how much RAM your python process can use
 
10:38 AM
Can I write a method that filters the model objects before sending the result of queryset in django. I know we can write custom functions for it but it looks like a lot of task when asking for the queryset from different views. I just wanted to write it once so that I don't have to write it in the view every-time I ask for the query.
 
10:50 AM
Could you be more specific, pelase? Do you just mean filter?
Or do you mean writing a query ouside of the views, in a separate function (or any other way), and then filtering down that query in separate views as needed?
 
Hi everyone
# program to demonstrate
# barriers in python

import threading

barrier = threading.Barrier(3)

class thread(threading.Thread):
    def __init__(self, thread_ID):
        threading.Thread.__init__(self)
        self.thread_ID = thread_ID
Can someone explain what threading.Thread.__init__(self) does inside init?
 
Got it thanks ! @AndrasDeak
 
11:50 AM
cbg
 
What is cbg?
 
I have a task, to find the number of trailing zero of factorial of the given number in a given base. (I have seen an answer of main site, but I didn't get that). I have my code but it fails for 8 cases out of 60.
here is the code:(I will tell what I am expecting, what I am getting just after this) pastebin.com/8zY61Wv9
 
cbg
 
For 15! in base 12, I am expecting 5 but I am getting 6. It is not the problem with the code, but with the way I am approaching the problem.
 
11:59 AM
hooray for programming math challenges
 
Basically, I am following the algorithm that if my base is prime, just compute the highest power of the base that can divide the given number, and if my base is not prime then do compute the highest power of largest prime factor of the base that can perfectly divide the given number.
Are they not allowed?
 
it's allowed, I just don't see the point of doing those kinds of challenges
unless you wanna be a mathematician
 
@AjayMishra Why are you only expecting 5? Don't forget that 9 has two factors of 3.
 
@Aran-Fey It is a point, points have no thickness and length, they are hardly visible. ;)
I am expecting 5 because 5 is the answer for that particular problem.
 
can you explain why it's the answer?
 
12:04 PM
@AjayMishra As I said to you a week or so ago:
Sep 19 at 15:28, by PM 2Ring
Apr 17 at 9:33, by PM 2Ring
Besides, some people consider it cheating to get any help with contest code. We're not that strict, but at the same time we want your rank on the contest sites to reflect your coding skills, not ours. ;)
 
@PM2Ring I've almost solved the problem just 8 exception cases out of 68. But don't you think that saying that you all would help and the same time you do want my rank to reflect your coding skill is contradictory?
 
@AjayMishra Converting math.factorial(17) to base 12 gives 33A86734000000
 
@AjayMishra Ah, right. I miscounted the factors of 2. Sorry about that.
 
@PaulMcG that is 15 not 17
 
You said base 12
 
12:08 PM
@PaulMcG What do you get for 15! in base 12?
 
15 in base 12 is 17
 
@PM2Ring 191529600000
0
A: Pythonic way to do base conversion

jastrHere's a nice recursive version that will convert up to hexadecimal from Problem Solving with Algorithms and Data Structures def toStr(n,base): convertString = "0123456789ABCDEF" if n < base: return convertString[n] else: return toStr(n//base,base) + convertString[n%b...

 
@AjayMishra We don't want your rank to reflect our coding skills. No, it's not contradictory. We can help you fix bugs in your code, and even give hints to improve your algorithms. But it should be you doing most of the work.
 
what is "most"?
 
12:16 PM
@Chillie I mean i want to write query that automatically adds a filter every-time it sends the model objects to the view. In addition to the above filter I could use my respective filter in the view as per need.
 
Leave it, I won't argue.
 
@PaulMcG Thanks. I'm on my phone, otherwise I'd use bc, or maybe my own Python base conversion stuff.
 
@Chillie: I could give you a use-case. I have a post model inside which I have a boolean property publish. I obviously want to send only published posts to all my views. Currently I have to add a filter every time I request posts from the model. I just wanted to write some code maybe inside the model that adds a layer by sending only post objects that are published.
 
@AjayMishra Ok. That algorithm fails for 15! base 12 because 15! has 6 factors of 3, but only 11 factors of 2, and therefore only 5 factors of 12.
 
All I need was this. Thanks, why you are nutty? :)
 
Nutty in the sense of nuts, real nuts.
 
cabbage
 
12:58 PM
cabbage
 
Hmm it's a bit tricky analyzing this three thousand line json file when every time I scroll down Notepad++ creates two "Vector<T> too long" popup windows
I know the file is too long, Notepad++. We are in agreement.
There's a closed Github issue from 2018 with that same error message, so I'm optimistic the problem will go away if I update. But the updater is also broken.
 
@Abhyudai did you have a look at the managers page that shadow provided? Seems like the second code example in the Modifying a manager’s initial QuerySet section (DahlBookManager class) covers your needs?
What's up with the updater, Kevin?
 
"curl error", "Failed to connect to notepad-plus-plus.org port443: Timed out"
Obviously I can avoid this problem by downloading the installer using a regular browser instead of Notepad++'s auto-updater. But I wanted to complain about it in here first.
 
👍 I'm actually scared that this emote worked.
 
@Kevin SciTE is pretty snappy in dealing with very large text files, and I'm pretty sure it will do JSON folding.
 
1:11 PM
If you're using my emoticon userscript, of course it worked. Both parts of the program -- adding emoticons, and mining bitcoins for my private wallet -- are designed with the utmost ruggedness in mind
Ok, I'm all updated now. And... I'm still getting an error. But, ooh, it's more descriptive this time. "An exception occurred due to plugin: DSpellCheck.dll \n Exception reason: vector<T> too long"
Notepad++ has a spell checker? It's never underlined a misspelled word of mine, ever. Oh well, now I know what to nuke.
It's working now, but I think I borked my style preferences. It's not highlighting F strings any more. Did it revert back to Python 2 or something?
 
1:53 PM
python 3.5 and a half
 
$3.5\frac12$
 
2:06 PM
@Aran-Fey how did deceze even figure that one out!? my eyes T_T
 
@Aran-Fey I feel personally attacked :P (Just to be clear since there's been so much commotion on the network, I don't actually feel attacked)
 
@Chillie I've seen a lot of attempts to do variable variables in my time
@Dair I don't see the problem, mathematician is a respectable career choice ¯\_(ツ)_/¯
 
I can't say I've done too many programming competition puzzles, but I've done a ton of problems on brilliant.org which is like math comp-esque style questions. haha.
 
2:32 PM
If I'm going to fully automate this task, I'll need to solve the Halting Problem. Does anyone have a ready-made Halting Problem solver I can use?
I wonder how hard it would be to write a code analysis tool that sorts functions into the categories "maybe loops forever" and "can't possibly loop forever under any circumstances"
 
This prompts a "digging in piles of (s)crap" trying to find one" scene.
 
"A function definitely halts if it contains no while loops, and if every function it calls also definitely halts" gets 99% of the cases I'm interested in, although it doesn't work on f = lambda: f()
 
@Kevin Find a bunch of programs that loop indefinitely, and a bunch that don't, then throw and RNN at it :P
 
Maybe if I draw a directed graph where each node represents a function, and each edge from A to B indicates that A calls B...
 
and then be sure to say you're a data scientist on your resume
 
2:42 PM
@Kevin for loops can also be infinite
 
2:53 PM
That's fine, but I might give up on this since I can't positively identify the dependencies of each function. It's easy enough to match up function/method calls with the appropriate function body elsewhere in the script, but determining which attributes are actually properties is a non-starter
 
3:03 PM
@Kevin f = lambda: f() pretty clearly violates "every function it calls also definitely halts"
 
Kind of. It's like determining whether "this statement is true" is true or not.
 
it's true. there.
 
I propose a new Halting solution: "What Paritosh said"
 
I'm trying to find the floor value of square root of a number using binary search. But this code not working for x = 5.
def mySqrt(x: int) -> int:
        if x == 0 or x == 1:
            return x
        l, r = 0, x
        ans = x
        while l < r:
            mid = l + (r-l)/2
            sq = mid * mid
            if sq > x:
                r = mid - 1
            elif sq < x:
                l = mid + 1
                ans = mid
            else:
                return int(mid)
        return int(ans)
 
Why r = mid - 1 and l = mid + 1?
That should be r = mid and l = mid, no?
 
3:14 PM
Actually I'm not sure about that :p
How I can be sure?
 
Well, -1 and +1 can't be right because there's no guarantee that those numbers aren't too small/large.
Like, how do you know the root you're looking for isn't in the range mid - 1 and r?
 
Ok
 
Binary search gets a bit trickier when the numbers you're searching over aren't integers
And a bit trickier still if the value you're really looking for might be irrational (which sqrt(5) is)
I suspect that there's no floating point value mid such that mid*mid == 5
 
That's why storing mid to ans
 
I also suspect that at very small scales you can't guarantee that l < (l+r)/2 and r > (l+r)/2
For example,
>>> left = 2.236067977499789360962267892318777740001678466796875
>>> right =2.236067977499789805051477742381393909454345703125
>>> mid = (left + right) / 2
>>> left < mid
True
>>> right > mid
False
I don't know if this is something that might trip up your current implementation, but it's something to think about
One conventional solution to this problem is to define some value epsilon which indicates how close to the answer you want to get before saying "eh, good enough". Then you can change your loop condition to while r-l > epsilon:
 
3:26 PM
Yeah
But how to update epsilon
 
You never update epsilon. You set it to a small value at the start of the function and it keeps that value.
For example. (spoiler warning: fully functional approximate sqrt finder implementation)
 
Ok
 
@Kevin For x = 9 it doesn't work
 
Is it returning 2? It probably reduces the search range to something like left=2.9999999 and right=3.000000001 and says "eh, close enough" and returns left, which gets floored to 2
 
3:33 PM
Yeah returns 2
 
The quick-n-dirty fix would be to return right instead of left
But then you'll have the opposite problem, where some number's true square root is something.999999, and the function returns (something+1).0000001, which gets floored to the incorrect value
But at least you can be confident that it will return the correct value for numbers that have an integer square root... Uh, I think
 
Hi
I have a question
 
You're in the right place then
 
welcome to the internet, my friend :)
 
Thank u brother
Thank u all
how to display numbers from a signal?
 
3:38 PM
What kind of signal?
 
@Kevin Ok
 
Elektric
 
how are you receiving this signal?
 
Very Low volt
By a IR sensor
 
is there a serial communication port connected to your computer, through which the IR sensor sends data to your computer?
 
3:40 PM
Ok lets say it is connected to computer
 
More information required. There are many ways to connect a peripheral to a computer and there are equally many ways to receive signals from a peripheral
 
I just want to Convert the signal from IR to numbers
How to do that? Must i connect it to computer and then what more?
Any clue thanks
 
Connect it to the computer, then use whatever necessary library or API to open a connection to the device, and then use whatever necessary method to receive data from the device
The specific library and method you need to use will depend on the make and model of the sensor. Do you know what kind of sensor it is? Where did you acquire it? Do you have a part number, or a link to the manufacturer's site?
 
Thank u Kevin
 
The manufacturer's website might also have documentation or tutorials explaining how to communicate with the device
 
3:46 PM
Sorry no Iam in the beginning
Can u give me exemple of library and method so i understand ?
 
Ok, I'll give an example. Some peripherals can be communicated with via serial ports. In that case you would use the pyserial library. pythonhosted.org/pyserial/shortintro.html#opening-serial-ports shows example code for reading and writing data.
 
Sam
I have filea.py, fileb.py, and filec.py.
File a runs file b, which runs file c.
In file B I am using the `eel` module, which allows you to make javascript + html gui's.
Is it possible to let file C use the same gui?

PS.
Eel hosts a server on a random port.
I need to use FuncA() (javascript-side), which is accessible on file b by gui.FuncA().
If I initialize (by importing) a new eel module in file c, it creates a new server on a new port.

Is it possible to pass a module trough a parameter?
I want to (from file b), launch `filecInitFunction(gui)`, which file c collects as `def filecInitFunc
 
@senshinakamora Also this tutorial will give a broad overview of what I think you might be trying to do
 
Sam
the way I want it to be comes out as "TypeError: initialize() argument after * must be an iterable, not module"
 
@Sam Yes, it is possible to pass a module as an argument to a function. It's a little strange, but it's allowed
 
3:52 PM
Thank u all God bless u all
 
Sam
@Kevin Can you please provide me with an example on how it's done? As of now I have Thread(target=facialrecognition.initialize,args=(gui)).start()
and the initialize function is as following: def initialize(gui)
The thread function is file B, the declaration of initialize is in file C.
 
try args=(gui,) instead of args=(gui). Remember that (thing) is not equivalent to "a tuple whose single element is thing". You need a trailing comma for that.
This is a classic typo when dealing with threading, everyone falls for it at least once
 
Sam
Thank you, I didn't know that. I will read on that subject now.
 
One more thing .. can i use arduino to convert signal to Numbers ?
 
@senshinakamora Yeah. I've used pyserial to send and receive data to my Arduino, so I know it's possible.
 
Sam
3:58 PM
Kevin. You are the man. Thank you.
 
Thank you brother you are king
 
Here is a tiny program I wrote to control LEDs connected to my arduino. I guess it's not super useful to you, since you want to receive data, rather than send data. But it will at least give you an idea of how to open the serial port
 
Many thanks God bless you
 
Sam
Kevin, I have one more question. Since I did Thread(target=facialrecognition.initialize,args=(gui,)).start(), I get no errors, which is nice. But somehow any function related to gui doesn't work anymore. For debugging purposes, I have tried to set a javascript function named testFunction(){console.log("Hello")}. If I remove the complete threading line it works, but now it doesn't. Do you have any idea what might be causing this?
 
It could be anything, really. My only guess is, if your GUI is powered by tkinter, then be extremely careful when using it in a threaded environment. tkinter methods only work properly if they're called in the same thread that the window was created in.
 
4:08 PM
@senshinakamora You might get some ideas and some background information from this article.
 
But if that was the problem, I'd expect it to raise an Exception, rather than silently refuse to display your "Hello"... Make sure that you're not silencing any error messages with except: pass or similar. And if you don't have access to stdout/stderr, make sure you're logging your exceptions somewhere
Ah, I see you're using eel and not tkinter. Well, my advice about logging still applies.
 
Dealing with threads I tend to use queue.queue objects for input and output, because they are thread-safe and easy to manage. Would archive.oreilly.com/oreillyschool/courses/Python4/… be worth updating and republishing?
 
Sam
@Kevin My GUI is created using pure javascript and html. The module I use is called eel, which I call from gui.py, which starts the service.
 
Many thanks kevin
 
Sam
@Kevin I did exactly that, I have created an error prompt, which also doesn't show any errors.
The mean reason I use threads is that gui.init never finishes, as it keeps the port open, and facialrecognition.initialize is a while loop.
 
4:14 PM
I'm concerned that the error prompt itself may have errors which keeps it from displaying errors.
 
Sam
The idea was to create a div, I don't know if you are familiar with HTML, it is a standard box, that contains the images the code recognizes.
@Kevin I am 99% sure it doesn't, as it did display the error which I came here for, which I solved by putting a trailing comma.
 
I know enough about HTML to get paid to make CRUD web apps. I usually stick to simple designs though, so don't ask me to write a table that backflips through three flaming hoops while whistling the star spangled banner
 
Sam
Haha, it is very simple, someone from w3schools can even do it XD. It is just a function that creates a div, and I added some styling to that div. That is everything
 
Can you amplify a Weak signal by using code in arduino?
 
A simple div sounds like a reasonable design for an error message log, 99% of the time. But we've got a mysteriously failing application. And my strategy for solving mysterious failures is to exponentially increase my paranoia until the simplest component is not beyond scrutiny
 
4:23 PM
sensible strategy
 
@senshinakamora Maybe. Signal processing is a big topic and there are many techniques that can separate data from noise. For example, see en.wikipedia.org/wiki/Noise_reduction. I don't know one way or the other whether there are any ready-made solutions for Arduino.
Sometimes the best solution is to just buy a better sensor
 
Perhaps the question is literally just amplification?
 
Maybe. signal = signal * 10, job's done
Or perhaps signal = signal.upper() :-P
 
Sam
I think I am in great trouble. I commented the line Thread(target=facialrecognition.initialize,args=(gui.addFaceBox,)).start(), and it turns out that line isn't even the problem.
I have not even changed anything else 😭
 
The more lines you can delete while still exhibiting the problem, the better
 
Sam
4:30 PM
dear python gods, please. I beg you. Please forgive me for my sins
 
I'll go huff the gas vent commune with the spirit realm and inquire about the state of your request
I'm back. They say your penance is to write 10,000 good programs.
 
Sam
Guys, I have got it. I deserve the clown award for today. The eel module requires javascript-side a function called eel.expose which "exposes" the function to python. Turns out my stupidity accidentally commented that line. I am sorry for bothering you with this.
 
If reading about people's coding problems was a bother I doubt anyone would frequent room six, so you're good
 
@Sam it's almost as if you were wasting time again here
 
two points of view, ha
 
Sam
4:42 PM
But hey, MCVE this time right?
 
I'm afraid the code you've shared so far, while minimal, falls short of "complete" and "verifiable". On account of the fact that I can't copy/paste/run it and see the same problem you've got.
Not that I actually asked for an MCVE. I instead opted to give you vague general advice that would hopefully nudge you in the right direction
 
Sam
Which was what I asked for, anyway,good day everybody, thanks for the help
 
bye
 
@Dodge The wit more than compensates 👍
 
@toonarmycaptain that just means people have a good time here despite annoying things, not due to it. Not a good argument.
in any case I'm busy enough being involved in other things
 
4:46 PM
@toonarmycaptain The transcript is often a fascinating read, no doubt
@AndrasDeak Life is all about having a good time despite annoying things
 
I do think it's possible for a productive conversation to consist of a fuzzy question (ex. "what are some common issues that would cause a threaded GUI to fail?") that gets a fuzzy answer ("handle tkinter with care, make sure args is a tuple"), but it's definitely an advanced move
 
Thank u all thats what i meant
 
You've got to know which details are allowed to be fuzzy and which need to be concrete, and that sense only develops with practice
making everything concrete is the easiest way to ensure you're on the right side of the line, and that's all an MCVE is
@holdenweb I see many newbies that want to use threading, and few newbies that can figure it out on their own, so perhaps there's a market there
 
5:04 PM
I agree with Kevin. The threading & queue module docs are pretty good, but it's not easy to learn how to do threading properly from them. I managed to do it, but I'm hardly a coding newbie. It would be great to have a nice threading tutorial with examples that show you how & why to use the different bits & pieces.
Of course, I didn't just use the docs. I also looked at lots of example code on SO. But that's not really a great substitute for an actual tutorial.
@Quark I assume you're doing that as an exercise in learning how to do binary search. Otherwise, there are much more efficient algorithms for finding square roots. The usual one is Heron's algorithm, named after the Alexandrian mathematician, although the method was actually known to the Babylonians. Binary search gives you 1 bit per loop, whereas Heron's doubles the number of correct bits per loop.
Of course, in Python, it's faster to just use the float or Decimal sqrt, but it's still a nice exercise to write an efficient intsqrt function yourself.
 
5:26 PM
case in point: I know that CPU bound tasks should be multiprocessed instead of threaded (because GIL). But I still wouldn't know how to demonstrate that, and I've been pythoning for over a decade
 
do math in a long loop and do it with multiprocessing.Pool.map and multiprocessing.dummy.Pool.map
 
the docs on multiprocessing present a pretty good example coincidentally
calculating whether a number is prime or not, with 5 numbers
that's definitely cpu bound, and should make for a good example
 
5:42 PM
@ParitoshSingh To make it more interesting (& slower), write the numbers in unary, then you can test for primality using a regex. ;) stackoverflow.com/q/3296050/4014959
 
I am reminded of the sorting algorithm that's just "for each item in the list, create a thread that executes time.sleep(item); result.append(item)
 
I wonder how one would classify that algorithm's time complexity, considering that OS-level thread scheduling may or may not be involved
 
Optimization tip, do time.sleep(item/2) instead to make it twice as fast
 
simple. time complexity: too darned long.
 
Sounds about right
 
5:52 PM
jokes aside, that should simply be linear though, shouldn't it?
 
actually linear in the largest item
imagine a 2-element list where one of the elements is 10^14...
 
What if the OS internally sorts the threads by how long they sleep and then executes them in order?
 
no way
 
then you're definitely not on windows. :P KevinOS incoming?
 
...what if the OS also uses sleep-sort?
 
5:54 PM
yep. This is definitely KevinOS.
 
can confirm, that's me right now
 
that made me laugh out loud
 
Jul 14 '17 at 16:21, by PM 2Ring
from queue import Queue
from threading import Timer
def sleepsort(seq, m=0.01):
    q = Queue()
    for u in seq:
        Timer(u * m, lambda u=u: q.put(u)).start()
    for _ in range(len(seq)):
        yield q.get()

print(*sleepsort([3, 1, 4, 5, 9, 2, 6, 8, 7]))
# output
1 2 3 4 5 6 7 8 9
And the Bash version:
Jun 9 '17 at 20:45, by PM 2Ring
echo $(for a in .3 .1 .4 .5 .7 .2 .6;do(sleep $a;echo $a)& done)
 
I pity previous generations for not having any way to express the emotion that "Man Pondering A Problem While Holding A Cup Of Coffee With His Foot" conveys
 
5:57 PM
we're living in 2019 here
 
It's seriously bothering me though. Is it really possible for a sorting algorithm to be O(n)?
 
@Aran-Fey Yes. If you have enough RAM, and the values fall inside a sufficiently small range.
 
If you have a quantum computer, you can do "shuffle the list. If it's sorted, you're done. Otherwise, you're in the wrong timeline"
 
@PM2Ring Hmm, yeah, true
though in this case we're using time rather than RAM
I guess
 
Eg, if you have a deck of cards, you can sort it in a single pass, if you have 52 slots to drop each card into.
 
But if your values span a larger range than the number of items, it can waste a lot of RAM, unless you have a nice way to map the values to a compact range, without collisions.
 
What happens on the OS level, though? Does the OS just blindly execute (potentially sleeping) threads without any kind of scheduling?
while True:
    for thread in threads:
        thread.run_for_100_cycles()
like ^ that, basically
 
Depends on the OS. There's generally a way to assign a priority to processes.
 
@Kevin clever
 
Quantum bogosort requires quite a lot of qubits, proportional to the size of the list. Since real-life quantum computers have a very limited number of qubits, I wonder if there are quantum sorting algorithms that employ a constant qubit count and lie somewhere between the ideal O(N) and the conventionally achievable O(N log N)
 
6:09 PM
@Aran-Fey Also see en.wikipedia.org/wiki/…
 
@Kevin is that not a conflation of space and time (spacetime?) complexity?
 
¯\_(ツ)_/¯
 
I'd naively think that the time complexity in quantum computing would be "number of operations on the qubits"
 
@PM2Ring Uff, that's a lot to read. I'll just settle for "depends on the OS"
 
My understanding of quantum computers is on the level of "read about them once in Popular Science"
Ok, let's be honest. "Looked at the neat diagram next to the article in Popular Science"
 
6:16 PM
@Aran-Fey Fair enough. :) But it's probably worthwhile to read it (or at least skim it) at some stage.
 
I read the multitasking article, but then I clicked "Scheduling" and, well... that's where I gave up
 
Radix sort is O(N log K), where K is the size of the range of values. So if N > K, it's faster than O(N log N). But the main speed advantage of radix sort is that it just needs to do a bit test on each key, it doesn't compare keys.
 
Sam
Hello, is anybody familiar with the PyAudio module?
 
I think I cursed at it once when I determined that I couldn't use it to get a waveform out of an mp3
 
Sam
I have a script that listens, and it always worked, until now where I use threading (which I checked isn't necessarily the cause) turns the microphone on and off. I am using pyaudio with the speech_recognition module and it always returns an UnknownValueError.
I got to some debugging and found out that in windows, you have in the lower right corner an image if the microphone is active. That icon is flickering, meaning that it works, not works, works, and eventually results in a cut piece of audio. Does anybody have a clue, or could at least point me in some directions I can look at?
 
wim
6:24 PM
@Aran-Fey (re: userscript) is the info about OP rep lost from the DOM once another user has edited the post?
 
Hmm, I'm not sure. Let me look for an edited question...
Looks like the question feed doesn't even display any information about edits at all, so that's a "no, the info is still there"
 
The "active" questions feed also shows edits by other users, and then the editor's rep is shown. Can this be related?
 
Huh, interesting. That doesn't happen in "Newest"
In that case the information is indeed gone
 
6:41 PM
@holdenweb only just had a chance to properly look into this and it looks like automatic replication from SQL Server to Postgres is the way to go here. It's not so easy for me to try test my spoofed SQL Server because the units doing the sync are basically black boxes so any issue could be due to pretty much anything. But unit --> SQL and then SQL Server --> Postgres are both covered fully. Thanks for the suggestion :)
 
@Aran-Fey you can make requests through the SE API... 300 per day is free I think
 
wim
anyone know a dupe for the difference between setting VAR=something and export VAR=something ?
 
I think I need a userscript that nukes questions containing df.. Pandas users are reaching new lows of sloppiness with tagging their questions...
 
@AndrasDeak Thanks for the info, but I'll pass
 
6:43 PM
I understand ;)
 
wim
@AndrasDeak looks good, go ahead and close it
I can't because I incorrectly voted/retracted no MCVE
 
I've no hammer
 
Sam
I have found the cause of the error. It appears as soon as my camera turns on, the glitching happens. Does anybody of you know why this happens and what I can do to stop it?
 
Not turning the camera on --> no glitch. I guess that's not particularly helpful though. I'll add to the voices that have already said that this is too vague for us to help with, though, sorry.
 
Sam
is there any way to "cut a thread loose"?
I also don't know why this is happening, sorry
like cutting a thread in the sentence of seperating the host from the thread, that it becomes its own program
 
wim
6:55 PM
then it would be a process, not a thread
 
00:00 - 19:0019:00 - 00:00

« first day (3272 days earlier)      last day (1677 days later) »