import antigravity

import antigravity

Nice python command-line one-liners. Great even for people who don't *do* python.

D57aec10399cbb252bd890c2bb3fe1c9?s=128

Brad Montgomery

November 07, 2013
Tweet

Transcript

  1. import antigravity - brad montgomery Thursday, November 7, 13

  2. Thursday, November 7, 13

  3. orly? Thursday, November 7, 13

  4. python -c Thursday, November 7, 13

  5. $ python -c “expression” Thursday, November 7, 13

  6. # Print a random number # from 0, 10 (inclusive)

    import random print(random.randint(1, 10)) Thursday, November 7, 13
  7. $ python -c “import random; print(random.randint(1, 10))” Thursday, November 7,

    13
  8. # String of random characters import random,string print ''.join([ random.choice(string.ascii_letters)

    for i in range(20) ]) Thursday, November 7, 13
  9. $ python -c “import random,string; print ''.join([random.choice(string.ascii_letters) for i in

    range(20)])” Thursday, November 7, 13
  10. # CSV File to JSON:: import csv, json print json.dumps(

    list(csv.reader(open('file.csv'))) ) Thursday, November 7, 13
  11. $ python -c “import csv, json; print json.dumps(list(csv.reader(open('file.csv'))))” Thursday, November

    7, 13
  12. $ python -c “print(unichr(0x26C4))” Thursday, November 7, 13

  13. $ echo 234 | python -c “import sys;print(unichr(int(sys.stdin.read())))” Thursday, November

    7, 13
  14. # UTC to CST conversion! for h in range(0,24): print("{0}

    utc -- {1} cst".format( h, (h+6)%24) ) Thursday, November 7, 13
  15. $ python -c “for h in range(0,24): print("{0} utc --

    {1} cst".format(h, (h +6)%24))” Thursday, November 7, 13
  16. 0 utc -- 6 cst 1 utc -- 7 cst

    2 utc -- 8 cst 3 utc -- 9 cst 4 utc -- 10 cst 5 utc -- 11 cst 6 utc -- 12 cst 7 utc -- 13 cst 8 utc -- 14 cst 9 utc -- 15 cst 10 utc -- 16 cst 11 utc -- 17 cst 12 utc -- 18 cst 13 utc -- 19 cst 14 utc -- 20 cst 15 utc -- 21 cst 16 utc -- 22 cst 17 utc -- 23 cst 18 utc -- 0 cst 19 utc -- 1 cst 20 utc -- 2 cst 21 utc -- 3 cst 22 utc -- 4 cst 23 utc -- 5 cst Thursday, November 7, 13
  17. alias lolutc=“python -c ‘for h in range(0,24): print("{0} utc --

    {1} cst".format(h, (h+6)%24))’” Thursday, November 7, 13
  18. python -m Thursday, November 7, 13

  19. $ python -m SomeModuleName Thursday, November 7, 13

  20. $ python -m SimpleHTTPServer Thursday, November 7, 13

  21. $ python -m SimpleHTTPServer Instant Static Webserver! Thursday, November 7,

    13
  22. alias serve='python -m SimpleHTTPServer' Thursday, November 7, 13

  23. Thursday, November 7, 13

  24. $ python -m smtpd -n -c DebuggingServer localhost:1025 Thursday, November

    7, 13
  25. $ python -m smtpd -n -c DebuggingServer localhost:1025 Instant Email

    Server! Thursday, November 7, 13
  26. alias email='python -m smtpd -n -c DebuggingServer localhost:1025' Thursday, November

    7, 13
  27. $ python -m json.tool file.json Thursday, November 7, 13

  28. $ python -m json.tool file.json Instant JSON VALIDATOR! Thursday, November

    7, 13
  29. $ python -m htmllib file.html Thursday, November 7, 13

  30. $ python -m htmllib file.html HTML TO PLAIN-TEXT! Thursday, November

    7, 13
  31. $ python -m calendar Thursday, November 7, 13

  32. $ python -m calendar CALENDAR! Thursday, November 7, 13

  33. $ python -m this Thursday, November 7, 13

  34. $ python -m this ZEN OF PYTHON! Thursday, November 7,

    13
  35. $ python -m antigravity Thursday, November 7, 13

  36. $ python -m antigravity just try it! Thursday, November 7,

    13
  37. Thank you! Thursday, November 7, 13