Skip to content

Instantly share code, notes, and snippets.

View danfairs's full-sized avatar

Dan Fairs danfairs

View GitHub Profile
@danfairs
danfairs / gist:956803
Created May 5, 2011 09:42
Python memory usage
>>> x = range(0, 100000000)
>>> import gc
>>> x = None
>>> gc.collect()
0
<!doctype html>
<html>
<script>
var response = prompt("Do you like me?");
if (response === "yes") {
console.log("I like you too!");
}
if (response === "no") {
console.log("GTFO");
}
@danfairs
danfairs / gist:2891161
Created June 7, 2012 19:51
couchapp dispatch
def get_or_create_db(self, db_name, designs=ALL_DESIGNS):
from couchapp import dispatch
couchapp_dir = os.path.join(
settings.PROJECT_DIR, '..', '..', 'couchdb', 'tweet_counts'
)
server = couchdbkit.Server(uri=settings.COUCHDB_SERVER_URI,
resource_class=couchdb.RequestsResource)
db = server.get_db(db_name)
try:
db.info()
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
def __init__(self, *args, **kwargs):
super(UserProfileForm, self).__init__(*args, **kwargs)
self.fields['country'].queryset = Country.on_site.all()
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
configure:3747: $? = 0
configure:3754: gcc -V >&5
llvm-gcc-4.2: argument to `-V' is missing
configure:3758: $? = 1
configure:3780: checking for C compiler default output file name
configure:3802: gcc -I/Users/dan/tmp/build-couchdb/build/include -I/Users/dan/tmp/build-couchdb/build/include/js -Xlinker -rpath=/Users/dan/tmp/build-couchdb/build/lib -L/Users/dan/tmp/build-couchdb/build/lib conftest.c >&5
ld: unknown option: -rpath=/Users/dan/tmp/build-couchdb/build/lib
collect2: ld returned 1 exit status
@danfairs
danfairs / gist:3499547
Created August 28, 2012 16:06
Class-based task
class BaseEnrich(object):
def __init__(self):
self.guesser = Guesser()
@task(ignore_result=True, base=BaseEnrich)
def enrich(self, data):
data['guess'] = self.guesser.guess('text')
return data
@task(ignore_result=True)
@danfairs
danfairs / gist:3817368
Created October 2, 2012 08:35
Recruiters
Hi,
This is an automated message.
I've sent several emails to recruiters at g2 over the past months
saying that I don't want any CVs. I'm not recruiting.
However, you've ignored me. Why would I use a recruitment agency
who ignores what I want? Hence, I'll never use you. I will also
strongly recommend that none of my contacts use you.
@danfairs
danfairs / gist:3905379
Created October 17, 2012 12:57
Reverse filtering on ForeignKey/ToManyFields
from tastypie.fields import NOT_PROVIDED, ToManyField
class OrmToManyField(ToManyField):
def __init__(self, to, attribute, related_name=None, default=NOT_PROVIDED,
null=False, blank=False, readonly=False, full=False,
unique=False, help_text=None, orm_attribute=None):
super(OrmToManyField, self).__init__(
to, attribute, related_name=related_name, default=default,
@danfairs
danfairs / gist:3938016
Created October 23, 2012 10:08
Traceback
[2012-10-22 13:46:19,817][DEBUG][action.search.type ] [Ariann] [production_tweets_for_2012_42][0], node[Nf8YZvJoRAm6s6JPWSx7Xg], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@711e0568]
org.elasticsearch.transport.RemoteTransportException: [Glorian][inet[/xxx.xxx.xxx.xxx:9501]][search/phase/query+fetch]
Caused by: java.lang.OutOfMemoryError: loading field [secondsync.geo] caused out of memory failure
at org.elasticsearch.index.cache.field.data.support.AbstractConcurrentMapFieldDataCache.cache(AbstractConcurrentMapFieldDataCache.java:137)
at org.elasticsearch.index.search.geo.GeoPolygonFilter.getDocIdSet(GeoPolygonFilter.java:60)
at org.elasticsearch.common.lucene.search.OrFilter.getDocIdSet(OrFilter.java:56)
at org.elasticsearch.common.lucene.search.AndFilter.getDocIdSet(AndFilter.java:56)
at org.elasticsearch.common.lucene.search.AndFilter.getDocIdSet(AndFilter.java:56)
at org.elasticsearch.common.lucene.search.NotDelete
Non-default config:
cluster.name: staging-es
http.port: 9600
transport.tcp.port: 9700
index.cache.field.type: soft
script.native:
excludetags.type: com.secondsync.elasticsearch.script.ExcludeTagsScriptFactory