This file contains hidden or 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 get_transitions(n): | |
| """Return a dictionary of array spots to neighbors for an nxn grid""" | |
| def neighbors(row, col): | |
| return {at(to_row, to_col) | |
| for to_row in around(row) | |
| for to_col in around(col) | |
| if (to_row, to_col) != (row, col)} | |
| def at(row, col): | |
| return row * n + col | |
| def around(i): |
This file contains hidden or 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
| import inspect | |
| from functools import partial | |
| def curryable(func): | |
| spec = inspect.getargspec(func) | |
| nargs = len(spec.args) | |
| if spec.varargs: | |
| raise ValueError('Hard to make a multiarity function curryable') | |
| if spec.defaults: | |
| raise ValueError('Hard to make a function with default arguments curryable') |
This file contains hidden or 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
| import socket | |
| # see wsgiref.simple_server for a real implementation of a WSGI server | |
| def serve(app): | |
| listener = socket.socket() | |
| listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
| listener.bind(('', 8080)) | |
| listener.listen(5) | |
| while True: | |
| s, addr = listener.accept() |
This file contains hidden or 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
| new-session | |
| set-option -g default-command "reattach-to-user-namespace -l bash" | |
| unbind C-b | |
| # I'm tempted to use C-a, but I want 'beginning of line' | |
| set -g prefix C-q | |
| set -g history-limit 1000000 |
This file contains hidden or 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
| function! g:Refresh_hy_python_preview() | |
| redir => message | |
| redir END | |
| let pyfile = substitute(bufname("%"), ".hy", "", "") . ".generated.py" | |
| let errfile = substitute(bufname("%"), ".hy", "", "") . ".error" | |
| exec "silent !~/hy/bin/hy2py % > " . pyfile . " 2> " . errfile . " || cat " . errfile . " > " . pyfile | |
| call MyPreviewVSplit(pyfile) | |
| set nomodified | |
| "exec "silent !rm " . pyfile . " " . errfile | |
| redraw! |
This file contains hidden or 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
| console.log("collide.js loaded"); | |
| function Ray(dx, dy, dz, x, y, z){ | |
| if (x === undefined){x = 0}; | |
| if (y === undefined){y = 0}; | |
| if (z === undefined){z = 0}; | |
| this.dx = dx; | |
| this.dy = dy; | |
| this.dz = dz; | |
| this.x = x; |
This file contains hidden or 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 foo(): return 1 | |
| >>> foo | |
| <function foo at 0x10c5af488> | |
| >>> foo.__call__ | |
| <method-wrapper '__call__' of function object at 0x10c5af488> | |
| >>> foo.__call__.__call__ | |
| <method-wrapper '__call__' of method-wrapper object at 0x10c562c50> | |
| >>> foo.__call__.__call__.__call__ | |
| <method-wrapper '__call__' of method-wrapper object at 0x10c64c8d0> | |
| >>> foo.__call__.__call__.__call__() |
This file contains hidden or 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
| import socket | |
| # see wsgiref.simple_server for a real implementation of a WSGI server | |
| def serve(app): | |
| listener = socket.socket() | |
| listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
| listener.bind(('', 8080)) | |
| listener.listen(5) | |
| while True: | |
| s, addr = listener.accept() |
This file contains hidden or 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
| class Board(object): | |
| """ | |
| >>> Board().rows | |
| ((' ', ' ', ' '), (' ', ' ', ' '), (' ', ' ', ' ')) | |
| >>> print Board() | |
| | | | |
| ----- | |
| | | | |
| ----- |
This file contains hidden or 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
| from Music import * | |
| s = Song(Note('f#5', 1.0/4), Note('f#5', 1.0/4), Note('g5', 1.0/4), Note('a6', 1.0/4)) | |
| s.play() | |
| # plays the first four notes of "Ode to joy" |