Quantcast
Channel: User Nicholas Knight - Stack Overflow
Browsing index pages (40 articles)
↧

Answer by Nicholas Knight for Encoding nested python object in JSON

So, the immediate problem is that you're passing the json module a JSON value, which will get encoded as just another string in the JSON value.The broader problem is that you're greatly...

View Article


Answer by Nicholas Knight for Can read(2) return zero when not at EOF?

After some research, there actually are some circumstances under which it will return 0 that you might not think of as being "EOF".For the gritty details, see the POSIX definition for read():...

View Article


Answer by Nicholas Knight for Create a list from a long int

It's not exactly clear what you're asking for, but if what you want is to iterate over the digits, just convert it to a string:x = str(n)You can iterate over a string as if it were a list.If you really...

View Article

Answer by Nicholas Knight for How to validate an Email address in Django?

Ick, no, please, don't try to validate email addresses yourself. It's one of those things people never get right.Your safest option, since you're already using Django, is to just take advantage of its...

View Article

Answer by Nicholas Knight for Printf security golang

tl;dr: Don't print untrusted data, escape it first. If in doubt or a hurry, use %q instead of %s.Go's string formatting methods are, indeed, memory-safe, and the specific class of vulnerabilities...

View Article


Answer by Nicholas Knight for Why use argparse rather than optparse?

As of python 2.7, optparse is deprecated, and will hopefully go away in the future.argparse is better for all the reasons listed on its original page...

View Article

Can I recursively create a path in Zookeeper?

I'm pulling ZooKeeper into a project for some concurrency management, and the first thing I tried was something that, to me, was quite obvious (using the zkpython binding):zh =...

View Article

Answer by Nicholas Knight for Should I use \d or [0-9] to match digits in a...

For maximum safety, I'd suggest using [0-9] any time you don't specifically intend to match all unicode-defined digits.Per perldoc perluniintro, Perl does not support using digits other than [0-9] as...

View Article


What does "evaluated only once" mean for chained comparisons in Python?

A friend brought this to my attention, and after I pointed out an oddity, we're both confused.Python's docs, say, and have said since at least 2.5.1 (haven't checked further back:Comparisons can be...

View Article


Answer by Nicholas Knight for Why doesn't the Go statement execute in parallel?

You probably need to review the Concurrency section of the Go FAQ, specifically these two questions, and work out which (if not both) apply to your case:Why doesn't my multi-goroutine program use...

View Article

Answer by Nicholas Knight for posix threads (pthreads) standard

Yes, that's a very old document. What you probably want is the full POSIX 2008 spec.

View Article

Answer by Nicholas Knight for Default GCC flags

The only two options there that make any sense to override are -D_FORTIFY_SOURCE and -fstack-protector, so just include -U_FORTIFY_SOURCE and -fnostack-protector, and they're effectively "gone".You...

View Article

Why does argparse give me a list-in-a-list?

I just noticed a behavior in argparse that puzzled me (guess I'd never used it for a dumb list of files before):import argparseparser = argparse.ArgumentParser()parser.add_argument('multi',...

View Article


Answer by Nicholas Knight for How to check exit if used tee?

For bash, there's a convenient special array: PIPESTATUS. The return code for myapp would be in ${PIPESTATUS[0]} and so on.zsh has a roughly identical method.There's also a rather more annoying, hacky...

View Article

Answer by Nicholas Knight for Can I keep threads alive and give them other...

The usual, simple form is an ordinary (work) queue. In principle, you maintain a queue structure, perhaps as a linked list, protected by a mutex. Typically, condition variables are used by the...

View Article


Answer by Nicholas Knight for Getting an embedded Python runtime to use the...

Well, the C API docs kind of imply it should just work (I read it as vaguely hinting the interpreter calls getenv itself), but seem to lack sufficient context to be certain, and I've never had occasion...

View Article

Answer by Nicholas Knight for How does C code call assembly code (e.g....

Many (most?) C compilers do happen to support inline assembly, though it's not part of the standard. That said, there's no strict need for a compiler to support any such thing.First, recognize that...

View Article


Answer by Nicholas Knight for When printf is an address of a variable, why...

So much insanity present here...%p is generally the correct format specifier to use if you just want to print out a representation of the pointer. Never, ever use %d.The length of an int and the length...

View Article

Answer by Nicholas Knight for Can you link a C++ library from a C application?

The easiest, least-hassle method to do this, assuming your C code is reasonably sane, is to simply build your C application with g++.Remember, good C code almost always builds in a C++ compiler. Then...

View Article

Answer by Nicholas Knight for By default, does gcc link to static or dynamic...

It is technically system dependent, but on most systems you're likely to develop for, the answer is "dynamic".A few systems (mostly very old, embedded, or otherwise specialized) do not support dynamic...

View Article
Browsing index pages (40 articles)


Latest Images