Python command line oneliners
vurt.ru
vurt.ru
Unfortunately, Python isn't really that good for writing one-liners, especially those that process input. At one point I was sufficiently unhappy about this, that I tried doing something about it:
https://github.com/gvalkov/python-onelinerI write a lot of these to remind myself of tool usage.
Even toy webservers blow the Python versions away. If I need a quick one-off server to share files over the LAN, webfs [1] is first on the draw. 90% of my uses don't even need fiddling with the command options. Though webfs is fairly limited, SSL is the most complicated thing it can do.
For slightly more advanced one-off webservers, thttpd [2] is wonderful. It's got many of the features of heavy duty webservers (plus great throttling controls) but every option is tune-able from the command line.
And as an aside, my own jshon [3] is usually nicer and faster than mjson.tool, at least until you hit a fairly high level of complexity.
[1] http://linux.bytesex.org/misc/webfs.html
[2] http://www.acme.com/software/thttpd/
edit: Thanks dschep.
What are you supposed to do with an http server after getting one quickly? Stare at the open port? The only thing quick about SimpleHTTPServer is the startup time. Don't actually try using the server.
The specific instance that put me off of the python servers was when a friend downloaded a CableGate tarball and someone else wanted to look at it. No one had a flash drive on them, but the fellow did have python installed. One SimpleHTTPServer later and the tarball was being transferred at 100KB/sec, slower than the original download. The cables were all html anyway so let's try uncompressing the tarball and serving those. Now the server would time out instead.
What do people actually use SimpleHTTPServer for?
It means I can develop offline.
I've used it as a half-baked and very short-lived file-sharing mechanism before, similar to what you describe above. I haven't noticed the DSL-like transfer rates because my broadband ISP gives me dialup-like upload speeds.
Yes, it's terrible. But not useless.
Smaller files than you need to move around when using a 1 off http server.
It's not that useless that you're portraying it as. But I do however agree that it's below toy level. It's not for production or long-time use.
Note, you missed the "l" on the end of link [1]
I have stopped using tools like that and even XAMPP. There's always something to mess you up. These days I just boot an instance of Ubuntu 12.04 Server on a virtual machine and life is beautiful. The next move is to setup a spare PC with, add an internal DNS server and route all *.local domains to said local Linux server.
php -S localhost:8080
10 chars typing effort spared, and it also supports ...PHP :Phttps://gist.github.com/dgulino/4750088 (mine)
http://code.activestate.com/recipes/437932-pyline-a-grep-lik...
cat messy.json | python -mjson.tool
It's served me well so far.
$ grep -r "if __name__ == '__main__'" /path/to/lib
Should be: $ grep -r "if __name__ == ['\"]__main__['\"]" /path/to/lib $ grep -r "if __name__ == .__main__." /path/to/lib
or even:
$ grep -Er 'if\W__name__\W==\W.__main__.' grep -n __main__ *.py|grep __name__
which turns up few false positives.