Skip to content

Instantly share code, notes, and snippets.

@alexdelorenzo
alexdelorenzo / wrapper.py
Last active Sep 28, 2016
HtmlWrapper -> Fast drop in replacement for BeautifulSoup
View wrapper.py
from functools import lru_cache
from lxml.html import HtmlElement, fromstring
from lxml.etree import XPath
BS4_TYPES = "bs4.element.Tag", "bs4.BeautifulSoup"
class HtmlWrapper(object):
View wrapper.py
from functools import lru_cache
from lxml.html import HtmlElement, Element, fromstring
from lxml.etree import XPath
from bs4 import BeautifulSoup, Tag
class BeauToLxml(object):
"""
An adapter for a small subset of the BeautifulSoup4 API
View example.py
In [26]: import requests
In [27]: import bs4
In [29]: url = "http://www.yellowpages.com/raleigh-nc/wake-med-hospital"
In [30]: response = requests.get(url)
In [31]: bs_content = bs4.BeautifulSoup(response.content)
@alexdelorenzo
alexdelorenzo / gist:9459232
Last active Aug 29, 2015
semicolon's okcupid
View gist:9459232
"""Import the modules"""
In [1]: from OKQuestions import OKQuestions as OKQS
In [2]: from bs4 import BeautifulSoup as BS
In [3]: from OKSession import OKSession as OKS
In [4]: from OKProfile import OKProfile as OKP
@alexdelorenzo
alexdelorenzo / pygletway.py
Last active Dec 24, 2015
pyglet front end for game of life, runs in pypy
View pygletway.py
from gol import Universe as U
import pyglet
# too lazy to make into a class, just pulled all functions under pyglet_way()
def pyglet_way():
x, y = 150, 150
u = U(x, y)
View play.py
from gol import Universe as U
from random import randint as r
import pygame
from pygame.gfxdraw import pixel as p
from pygame.gfxdraw import rectangle as rect
from pygame import Surface as S
# just shoved everything in this script into main(), hence the subfuncs
def main():
x, y = 100, 100
@alexdelorenzo
alexdelorenzo / gol.py
Last active Dec 24, 2015
use along w/ play.py or pygletway.py in pypy
View gol.py
#!/usr/bin/env pypy
from random import randint as r
class Universe(list):
def __init__(self, x, y):
for num in range(x):
self.append([False for num in range(y)])
self.xlen = len(self)
self.ylen = len(self[0])
self.cardinals = self.north, self.north_east, self.north_west, self.west,\