Skip to content

Instantly share code, notes, and snippets.

Taylor Fausak tfausak

Block or report user

Report or block tfausak

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tfausak
tfausak / interface-lift-scrape.py
Created Mar 14, 2011
Downloads all the wallpapers on InterfaceLIFT.
View interface-lift-scrape.py
#!/usr/bin/env python
from BeautifulSoup import BeautifulSoup
from urllib2 import urlopen
from re import compile, match
from urllib import urlretrieve
from sys import argv, stdout
from os.path import isfile
from time import sleep
@tfausak
tfausak / simple-desktops-scrape.php
Created Mar 14, 2011
Downloads all the wallpapers on Simple Desktops.
View simple-desktops-scrape.php
#!/usr/bin/env php
<?php
for ($page = 1; true; $page += 1) {
# Get the page of desktops
$url = 'http://simpledesktops.com/browse/' . $page . '/';
$html = @file_get_contents($url);
# Bail if we hit a 404
@tfausak
tfausak / clear-background.py
Created Mar 14, 2011
Zeros out (doesn't delete!) the current randomly-selected background in OS X.
View clear-background.py
#!/usr/bin/env python
from BeautifulSoup import BeautifulStoneSoup
from commands import getoutput
from os.path import expanduser, join
plist = '~/Library/Preferences/com.apple.desktop.plist'
xml = getoutput('plutil -convert xml1 -o - -- {0}'.format(plist))
soup = BeautifulStoneSoup(xml)
@tfausak
tfausak / famigodocument.py
Created Mar 17, 2011
Wrapper around mongoengine's Document class to avoid deleting things.
View famigodocument.py
from datetime import datetime
from mongoengine import *
from mongoengine.queryset import queryset_manager
from re import sub
class FamigoDocument(Document):
_active = BooleanField(default=True, required=True)
@queryset_manager
def active(cls, queryset):
@tfausak
tfausak / deepcopy.py
Created Mar 23, 2011
Minimal example that causes an error when deep copying a mongoengine Document.
View deepcopy.py
from copy import deepcopy
from mongoengine import Document, ReferenceField, connect
class Foo(Document):
pass
class Bar(Document):
foo = ReferenceField(Foo)
connect('tmp-deepcopy')
@tfausak
tfausak / backup.py
Created Mar 24, 2011
Back up Tumblr posts to XML files. (Doesn't save assets, like images and audio.)
View backup.py
#!/usr/bin/env python
from BeautifulSoup import BeautifulStoneSoup
from urllib2 import urlopen
from urllib import urlretrieve
from os.path import basename
import sys
def main(argv=None):
if argv is None:
@tfausak
tfausak / output.txt
Created Mar 24, 2011
Minimal example that causes a mysterious uniqueness constraint when inserting into mongoengine.
View output.txt
Traceback (most recent call last):
File "unique.py", line 15, in <module>
B(foo=True).save()
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/document.py", line 85, in save
mongoengine.queryset.OperationError: Tried to save duplicate unique keys (E11000 duplicate key errorindex: tmp-unique.a.$foo_1 dup key: { : null })
@tfausak
tfausak / output.txt
Created Mar 24, 2011
Minimal example that causes a uniqueness constraint when reading from mongoengine.
View output.txt
[<A: A object>, <A: A object>, <B: B object>]
Traceback (most recent call last):
File "unique3.py", line 20, in <module>
print B.objects
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/queryset.py", line 1131, in __repr__
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/queryset.py", line 776, in __getitem__
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/queryset.py", line 427, in _cursor
File "/usr/local/lib/python2.6/dist-packages/mongoengine-0.4-py2.6.egg/mongoengine/queryset.py", line 402, in _collection
File "build/bdist.linux-i686/egg/pymongo/collection.py", line 717, in ensure_index
File "build/bdist.linux-i686/egg/pymongo/collection.py", line 639, in create_index
@tfausak
tfausak / file-field-fail.py
Created Mar 25, 2011
Every mongoengine field can be deep copied, except for file fields.
View file-field-fail.py
from copy import deepcopy
from mongoengine import *
from pymongo import Connection
class A(Document):
binary_field = BinaryField()
boolean_field = BooleanField()
date_time_field = DateTimeField()
decimal_field = DecimalField()
dict_field = DictField()
@tfausak
tfausak / mongoengine-listfield-filefield.py
Created Oct 19, 2011
Shows MongoEngine's peculiar handling of ListField of FileFields.
View mongoengine-listfield-filefield.py
"""Python v2.7.1, MongoDB v1.8.2, PyMongo v1.10, MongoEngine v0.4
"""
from mongoengine import connect, Document, FileField, ListField
from mongoengine.base import ValidationError
from mongoengine.fields import GridFSProxy
from pymongo import Connection
from time import time
# Start with a clean slate.
You can’t perform that action at this time.