275 karma · joined Jun 14, 2020 (6y ago) · 170 submissions
comment 3mo ago · link · parent
> SQLWindows had an outline-based code structure — not braces, not BEGIN/END, but an indented tree that was simultaneously the code and the IDE’s display. You wrote code by expanding and collapsing outline nodes. Classes were outline headings. Methods were sub-headings. Code lines were leaf nodes. The entire program was a hierarchical outline that the IDE rendered as a collapsible tree.
comment 4mo ago · link · parent
I am asking because I have never needed preserving the `$?` outside of an `if`, nor have I ever seen this in somebody else's scripts, and I'm curious.
comment 4mo ago · link · parent
There was one case where all transactions were implemented using nested `SAVEPOINT bla` so `BEGIN IMMEDIATE` could not be used without more hassle, so this ended all “I know I'm going to write” transactions to instantly update a single-row table so that their lock would not begin as DEFERRED and eventually switch to `IMMEDIATE`; this way almost all `SQLITE_BUSY` side-steppings disappeared. (timeout was set to 30 seconds but all read/write transactions were instrumented to have less than 5 seconds duration).
comment 4mo ago · link · parent
So this was a write to a column that did not have INTEGER affinity. If it was intended to be used as a boolean, then it should have INTEGER affinity. I know because I've tried hard to enter integer- and float-like strings as strings in INTEGER affinity columns, and I haven't managed to; I could only insert them as BLOBs, or prefix the string with say '\' and check/remove at the application level. (That was for an ontology-like database, where table EAttribute.eatvalue could have any type.)
comment 6mo ago · link · parent
> I agree, Python allows anyone to write bad code, but makes up for it by running the code slow enough that it can't do real damage.
In the same sentence you agree with the implied beauty of the syntax of Python and then go on sarcastically about the performance of CPython. Assumably you deliberately mixed language and implementation because you needed a soapbox, so hey, here's my comment to which you can reply and continue your rhetoric.
comment 7mo ago · link · parent
Now I can have side-by-side two editors plus a Structure or Project pane at the left in PyCharm while having 120 chars visible in both editors.
comment 8mo ago · link · parent
import re, operator
def count_words(filename):
with open(filename, 'rb') as fp:
data= memoryview(fp.read())
word_counts= {}
for match in re.finditer(br'\S+', data):
word= data[match.start(): match.end()]
try:
word_counts[word]+= 1
except KeyError:
word_counts[word]= 1
word_counts= sorted(word_counts.items(), key=operator.itemgetter(1), reverse=True)
for word, count in word_counts:
print(word.tobytes().decode(), count)
We could also use `mmap.mmap`.comment 8mo ago · link · parent
IFS=' ''
'
Hint: the spaces between the first two apostrophes are actually one <Tab>.This does not affect the already written script (you don't need to press Tab instead of space to separate commands and arguments in the script itself), but by making <Tab> and <LF> be the “internal field separators” will allow globbing with less quoting worries while still allowing for `files=$(ls)` constructs.
Example:
IFS=' ''
'
echo hello >/tmp/"some_unique_prefix in tmp"
cat /tmp/some_unique_prefix*
fn="My CV.txt"
echo "I'm alive" >/tmp/$fn
cat /tmp/$fn
Of course this will still fail if there happens to be a filename with <Tab> in it.24.
Python VM in Assembly (contributor is Claude)(github.com ↗)
5 points · by tzot · 9mo ago · 4 comments
comment 10mo ago · link · parent
1. replacing parentheses —given that the em-dash in pairs for me mark more-relevant-to-the-main content than a parenthesized expression would— so I use the same spacing as `()`
2. replacing colon or just finishing the sentence with a subsentence— so the spacing goes like for a colon.
Probably unfounded grammatically and against any style guides, but this spacing makes sense to me.
comment 10mo ago · link · parent
comment 1y ago · link · parent
We did the same on the ZX Spectrum in Greece for our programs: replace the lowercase latin letters with the keyboard-matching greek letters.
I still remember the vulgar ΣΨΡΟΛΛ? when the screen filled up and the machine asked your permission to scroll!