Skip to content

Instantly share code, notes, and snippets.

@jbwincek
jbwincek / befunge.tmLanguage
Created September 15, 2015 01:29
Sublime 3 Syntax highlighting for Befunge source code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>bf</string>
</array>
<key>name</key>
<string>Befunge</string>
from bs4 import BeautifulSoup
import requests
def main():
r = requests.get('http://www.soybomb.com/tricks/words/')
soup = BeautifulSoup(r.text, 'html.parser')
tags_with_words = soup.find_all('td')
for tag in tags_with_words:
if tag.string:
print(tag.string)
@jbwincek
jbwincek / bggl_board_generator.py
Last active November 24, 2015 02:48
A simple script that generates valid Boggle™ dice configurations.
import random
import textwrap
# Actual Boggle dice
dice = ['aspffk',
'tesois',
'ehgewn',
'atwtoo',
'uensie',
'itmuoc',
@jbwincek
jbwincek / coroutine_box_handler.py
Last active February 24, 2016 04:21
using a coroutine to save state for repeated box rendering
""" notes coroutine box handler: using a coroutine to save state for repeated box rendering
* Box renders input, rolls over to new lines when it hits the end.
* Box uses arrow keys to update size
* the box_updated flag exists so that when in the loop, the box only gets redrawn
when the size changes
* text flow inside the box updates after a new character is hit
* ``with curtsies.Input() as input:`` makes input be a generator, perhaps further
optimization could be done with calling next on it, instead of using it in a for loop
* the double break is to get out of the for loop, and then the ``while True:`` loop
* exceptions propagate out from the generator, hence the raise stop iteration error
""" Test the speed of various string concatenation methods """
import timeit
def not_join(size = (40,40)):
blank_dict = {}
output = ''
for y in range(size[1]):
if y>0:
output += '\n'
for x in range(size[0]):
@jbwincek
jbwincek / cellspace.py
Last active August 1, 2016 01:26
CellSpace is a thin wrapper around dictionaries that adds 2D slicing and bounds information to dicts of (x,y) coordinate pairs.
from collections import UserDict
from numbers import Integral
class CellSpace(UserDict):
""" CellSpace adds 2D slicing and bounds information to dicts of (x,y) coordinate pairs.
Notes: CellSpace does not support assigning by slice at this point.
Height and width are not absolute measures of how many cells CellSpace contains in
either direction. Instead they show the max labeled cell, this can be considered