Skip to content

Instantly share code, notes, and snippets.

View akaptur's full-sized avatar

Allison Kaptur akaptur

View GitHub Profile
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)
@akaptur
akaptur / Traceback
Created November 15, 2012 17:33
simple pdb traceback
Traceback (most recent call last):
File "minimal_pdb_traceback.py", line 7, in <module>
y = "line of code not triggering an error"
AssertionError
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
@akaptur
akaptur / gist:3836483
Created October 4, 2012 21:10
.bashrc settings
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
@akaptur
akaptur / gist:3408317
Created August 20, 2012 22:01
A way to get the attributes of an object without using getattr
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)
@akaptur
akaptur / gist:3316675
Created August 10, 2012 18:46
String formatting with % in python
>>>a = '%s'
>>>a %= 1 # equivalently, a = a % 1
>>>a == '1'
True
# A more clear version
>>> f = '%s' % 1
>>> f
'1'
@akaptur
akaptur / gist:3287028
Created August 7, 2012 16:28
Quicksort with heisenbug
#include <stdio.h>
#include <stdlib.h>
void quicksort(int *array, int length);
void swap(int *a, int *b);
void print(int *array, int length);
int main()
@akaptur
akaptur / gist:3279183
Created August 6, 2012 22:46
quicksort in C
#include <stdio.h>
#include <stdlib.h>
void quicksort(int *array, int length);
void swap(int *a, int *b);
void print(int *array, int length);
int main()
@akaptur
akaptur / gist:3277921
Created August 6, 2012 19:47
simple C loop
for (int i=0; i<15; i++)
{
int c = rand();
printf("%d\n", c);
}
@akaptur
akaptur / gist:3251981
Created August 3, 2012 22:05
fun with pointers
# include <stdlib.h>
# include <stdio.h>
int main()
{
int myarray[10] = {100,4,'c','d','e','f','g','h','i','j'};
int *a_goddamn_pointer;
int x, y, z, w;
a_goddamn_pointer = &myarray;