Skip to content

Instantly share code, notes, and snippets.

View sloria's full-sized avatar

Steven Loria sloria

View GitHub Profile
class Book:
...
def __hash__(self):
return hash(self.author) ^ hash(self.other)
@sloria
sloria / gist:5895768
Last active December 24, 2022 20:04
class Book:
...
def __lt__(self, other):
return (self.author, self.title) < (other.author, other.title)
class Config:
def __init__(self, **entries):
self.entries = entries
def __add__(self, other):
entries = (self.entries.items() +
other.entries.items())
return Config(**entries)
default_config = Config(color=False, port=8080)
config = default_config + Config(color=True)
# Awkward
for options_shortcut in self.options_shortcuts:
options_shortcut.this()
options_shortcut.that()
# Better
for each in self.options_shortcuts:
each.this()
each.that()
# Instead of this
self.release_water()
self.shutdown()
self.alarm()
class Reactor:
...
def release_water(self):
self.valve.open()
return self
# Meh
def match(self, items):
for each in items:
if each.match(self):
return each
# Is this supposed to reach the end? Is this a bug?
# Better
def match(self, items):
for each in items:
~/.ideas.md
# Software
- doomed startup idea 1
- some feature for an open-source project
- doomed startup idea 2
- ...
# Blog posts
- the .ideas file
This file has been truncated, but you can view the full file.
------------------------------------------------------------
/usr/local/bin/pip run on Mon Jul 1 12:34:07 2013
Downloading/unpacking lxml
Getting page https://pypi.python.org/simple/lxml/
URLs to search for versions for lxml:
* https://pypi.python.org/simple/lxml/
Analyzing links from page https://pypi.python.org/simple/lxml/
Skipping link https://pypi.python.org/packages/2.4/l/lxml/lxml-1.3.4.win32-py2.4.exe#md5=3007a5b7556d5115e34da2e220630d1d (from https://pypi.python.org/simple/lxml/); unknown archive format: .exe
Skipping link https://pypi.python.org/packages/2.7/l/lxml/lxml-2.2.8-py2.7-win32.egg#md5=62180a1bf41e037cd2712957fa4acf62 (from https://pypi.python.org/simple/lxml/); unknown archive format: .egg
@sloria
sloria / gist:5902928
Created July 1, 2013 17:40
Error when installing lxml
This file has been truncated, but you can view the full file.
------------------------------------------------------------
/usr/local/bin/pip run on Mon Jul 1 12:34:07 2013
Downloading/unpacking lxml
Getting page https://pypi.python.org/simple/lxml/
URLs to search for versions for lxml:
* https://pypi.python.org/simple/lxml/
Analyzing links from page https://pypi.python.org/simple/lxml/
Skipping link https://pypi.python.org/packages/2.4/l/lxml/lxml-1.3.4.win32-py2.4.exe#md5=3007a5b7556d5115e34da2e220630d1d (from https://pypi.python.org/simple/lxml/); unknown archive format: .exe
Skipping link https://pypi.python.org/packages/2.7/l/lxml/lxml-2.2.8-py2.7-win32.egg#md5=62180a1bf41e037cd2712957fa4acf62 (from https://pypi.python.org/simple/lxml/); unknown archive format: .egg
------------------------------------------------------------
/usr/local/bin/pip run on Mon Jul 1 12:47:31 2013
Downloading/unpacking lxml
Running setup.py egg_info for package lxml
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)