Skip to main content
Marius's user avatar
Marius's user avatar
Marius's user avatar
Marius
  • Member for 12 years, 7 months
  • Last seen more than 1 year ago
awarded
comment
Open file in a relative location in Python
It's __file__ not '__file__'.
comment
SPA: using websockets only. Why not?
IMO the only reason to not use Websockets is that there is more inertial tooling and middleware around HTTP request/response, like caches, proxies, etc. But HTTP request/response sucks badly at live updating. The more live you want to make your app the more HTTP request/response, and frameworks built around that (Rails, Django, etc.), feel like medieval technology.
awarded
comment
How to listen state changes in react.js?
The question is not about React 'listening' and re-rendering the dom. The question is about how a user can listen for a change in state (for example if the state count changes from 20 to 21) and run some code when it changes. useEffect does this in React hooks. Not sure what the mechanism was before React hooks, or if there was one.
comment
deepcopy() is extremely slow
Thanks. marshal is the fastest of all the mentioned alternatives in this thread, slightly faster than cPickle as well.
comment
Replace values in list using Python
You can modify the list in place and use a comprehension at the same time: items[:] = [b if x == a else x for x in items].
comment
Firefox duplicating large websocket messages when server takes time to receive the messages
I ran into the same issue and it looks like a FF82 bug. I also ran into another large-message issue where when "per message deflate" compression is turned on in the server, FF82 sends broken/nonsensical payloads. For the record I used WireShark and verified that it's FF sending the duplicate/busted payloads. The Developer Tools websocket message inspector says one thing, and FF82 does another, it seems.
awarded
awarded
comment
Transactions with Python sqlite3
I will add that you can set the transaction level too. For example c.execute("begin exclusive transaction").
awarded
awarded
comment
Variable value getting changed after a function call in python
In Python, object variables are pointers to objects. So when you return temp_map you're just returning the same object that was passed in. If you want that function to return a modified copy, you need to explicitly create a copy like another poster suggested.
comment
Merging and sorting lists: Complexity
However the complexity of list.append() and list.pop() is a factor. If this is just "theoretical code" that assumes pop and append are constant, that's ok. In python, append and pop are "amortized constant".
comment
Merging and sorting lists: Complexity
Your algorithm is O(m+n). The exact boound is 2*(m+n) because you iterate each element in m+n and then the reverse() at the end is another m+n.
comment
awarded
Loading…
comment
Storing 1 million phone numbers
How much further can you get if you use a bit array to store numbers, as suggested in another answer? For 10-digit phone numbers you'd need a 10-billion bit bit-array. Then you can compress patterns e.g. all possible phone numbers are encoded as "1"x10^10 (all 10 billion bits are 1). All alternating numbers starting at 0 would be "01"x(10^10)/2 (repeat the string "01" 5 billion times). The approach would fail if you get a random distribution of around half billion numbers, where the encoding size can exceed 10 billion bits.