Instantly share code, notes, and snippets.

• Sort options
Last active May 25, 2017
Another tiny python game
View connect4.py
 licence, itertools, board, vectors, get, put, coloured, board_string, winner = 'MIT', __import__('itertools'), [[] for _ in xrange(7)], [(0, 1), (1, 0), (1, 1), (1, -1)], lambda i, j: board[i][j] if 0 <= i < 7 and len(board[i]) > j >= 0 else ' ', lambda i, p: board[i].append(p) or True if 0 <= i < 7 and len(board[i]) < 6 else False, (lambda string, colour: {'red': '\033[1;31m{}\033[1;m', 'yellow': '\033[1;33m{}\033[1;m', 'blue': '\033[1;34m{}\033[1;m'}.get(colour, '{}').format(string)) if not __import__('os').getenv('NOCOLOR') else lambda string, colour: string, lambda: '\n'.join(coloured(' | ', 'blue') + coloured(' | ', 'blue').join(get(column, row) for column in range(7)) + coloured(' | ', 'blue') for row in range(5, -1, -1)) + '\n' + coloured(' | ', 'blue') + coloured(' | ', 'blue').join(coloured('{}', 'blue').format(i + 1) for i in range(7)) + coloured(' | ', 'blue'), lambda: any(all(get(i, j) != ' ' and get(i, j) == get(i + vi * step, j + vj * step) for step in range(4)) for vi, vj in vectors for j in ra
Created Feb 7, 2016
View ugly_hangman.py
 c,g,s,m,l,p=''.join(x for x in __import__('random').choice(list(open('/usr/share/dict/words'))).upper() if x.isalpha()),set(),'|===\n| |\n|{3} {0} {5}\n| {2}{1}{4}\n| {6} {7}\n| {8} {9}'.format,list(r'QT-\-//\||'),10,' ' while not all(q in g for q in c) and l:_,l=[g.add(x) for x in raw_input('%s %s left\n%s\n%s:'%(p.join(sorted(g)),l,s(*(m[:-l]+[p]*l)),p.join(q if q in g else '_' for q in c))).upper() if x.isalpha()],max(10-len(g-set(c)),0) print 'You',['win!','lose!\n'+s(*m)][not l],'\nWord was',c
Last active Apr 20, 2017
Hangman implemented in 3 lines of Python! For an explanation of how this works, see http://danverbraganza.com/writings/hangman-in-3-lines-of-python
View hangman.py
 license, chosen_word, guesses, scaffold, man, guesses_left = 'https://opensource.org/licenses/MIT', ''.join(filter(str.isalpha, __import__('random').choice(open('/usr/share/dict/words').readlines()).upper())), set(), '|======\n| |\n| {3} {0} {5}\n| {2}{1}{4}\n| {6} {7}\n| {8} {9}\n|', list('OT-\\-//\\||'), 10 while not all(letter in guesses for letter in chosen_word) and guesses_left: _, guesses_left = map(guesses.add, filter(str.isalpha, raw_input('%s(%s guesses left)\n%s\n%s:' % (','.join(sorted(guesses)), guesses_left, scaffold.format(*(man[:10-guesses_left] + [' '] * guesses_left)), ' '.join(letter if letter in guesses else '_' for letter in chosen_word))).upper())), max((10 - len(guesses - set(chosen_word))), 0) print 'You', ['lose!\n' + scaffold.format(*man), 'win!'][bool(guesses_left)], '\nWord was', chosen_word
Created Nov 2, 2014
View .bashrc
 # I have tried to fork-bomb myself in the past. ulimit -u 1000 export ANDROID_HOME=/usr/local/android/sdk export PATH=\$PATH:/usr/local/go/bin:\$ANDROID_HOME/tools:\$ANDROID_HOME/platform-tools alias set_gopath='export GOPATH=\$(pwd)' export EDITOR=emacs export GOPATH=~/projects/go
Created Nov 2, 2014
My personal rc.lua file.
View rc.lua
 -- Standard awesome library require("awful") require("awful.autofocus") require("awful.rules") -- Theme handling library require("beautiful") -- Notification library require("naughty") -- Load Debian menu entries
Last active Oct 4, 2015
My personal .emacs file for convenience.
View .emacs
 (when (load "flymake" t) (defun flymake-pyflakes-init () (let* ((temp-file (flymake-init-create-temp-buffer-copy 'flymake-create-temp-inplace)) (local-file (file-relative-name temp-file (file-name-directory buffer-file-name)))) (list "pyflakes" (list local-file)))) (add-to-list 'flymake-allowed-file-name-masks
Created Mar 10, 2012
Dynamic programming solution for finding the longest sequence of length 2^n in a m x o matrix (Winner
View connect4.py
 '''Expressing "Find the winner in connect 4" as a dynamic programming problem. ''' import json lines = [] while True: try: lines.append(raw_input()) except EOFError:
Last active Oct 1, 2015
Standard starting for a file.
View setup.py
 from setuptools import setup, find_packages setup( name = 'Undefined', version = '0.0.0', author = 'Danver Braganza', author_email = 'danverbraganza@gmail.com', description = ('A description of my project goes here.'), license = 'WTFPL', # keywords = 'space separated',
Created Jan 26, 2012
My standard tox.ini file that allows you to run coverage, lettuce, nosetests and lint, and to pick out a given feature or a module for nosetest (So that you don't have to run the whole suite)
View tox.ini