This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for attr in dir(obj): | |
code = 'obj.' + attr | |
print attr, eval(code) | |
for attr in [x for x in dir(obj) if not callable(getattr(obj, x))]: | |
code = 'obj.' + attr | |
print attr, eval(code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias git=hub | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* | |
if [ -f $(brew --prefix)/etc/bash_completion ]; then | |
. $(brew --prefix)/etc/bash_completion | |
fi | |
GIT_PS1_SHOWDIRTYSTATE=true | |
GIT_PS1_SHOWSTASHSTATE=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To dissect the behavior of this server and client, I need two things: more realistic network latency than is produced by making connections directly to localhost, and some way to see a microsecond-bymicrosecond report on what the client and server are doing. | |
These two goals may initially seem impossible to reconcile. If I run the client and server on the same machine, the network latency will not be realistic. But if I run them on separate servers, then any timestamps that I print will not necessarily agree because of slight differences between the machines’ clocks. | |
My solution is to run the client and server on a single machine (my Ubuntu laptop, in case you are curious) but to send the connection through a round-trip to another machine (my Ubuntu desktop) by way of an SSH tunnel. See Chapter 16 and the SSH documentation itself for more information about tunnels. The idea is that SSH will open local port 1061 here on my laptop and start accepting connections from clients. Each connection will then be for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Traceback (most recent call last): | |
File "minimal_pdb_traceback.py", line 7, in <module> | |
y = "line of code not triggering an error" | |
AssertionError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socktactoe [master *+]\ ⚲git status | |
# On branch master | |
# Changes to be committed: | |
# (use "git reset HEAD <file>..." to unstage) | |
# | |
# modified: multi_tictactoe.py | |
# modified: socktactoe_server.py | |
# | |
# Changes not staged for commit: | |
# (use "git add <file>..." to update what will be committed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def naive_add(lis): | |
total = 0 | |
for elem in lis: | |
total += elem | |
return total | |
def recursive_add(lis): | |
if len(lis) == 1: | |
return lis[0] | |
elif len(lis) == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file must be used with "source bin/activate" *from bash* | |
# you cannot run it directly | |
deactivate () { | |
unset pydoc | |
# reset old environment variables | |
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then | |
PATH="$_OLD_VIRTUAL_PATH" | |
export PATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def two_sort(ex): | |
ex_copy = ex[:] | |
ex.sort(key=lambda tup: tup[1]) | |
ex.reverse() | |
print "Ex: ", ex | |
ex_copy.sort(key=lambda tup: tup[1], reverse=True) | |
print "Copy:", ex_copy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def gen(): | |
... yield 1 | |
... yield 2 | |
... yield 3 | |
... | |
>>> for i in gen(): | |
... print i | |
... | |
1 | |
2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = """Gur Mra bs Clguba, ol Gvz Crgref | |
Ornhgvshy vf orggre guna htyl. | |
Rkcyvpvg vf orggre guna vzcyvpvg. | |
Fvzcyr vf orggre guna pbzcyrk. | |
Pbzcyrk vf orggre guna pbzcyvpngrq. | |
Syng vf orggre guna arfgrq. | |
Fcnefr vf orggre guna qrafr. | |
Ernqnovyvgl pbhagf. | |
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf. |