Skip to content

Instantly share code, notes, and snippets.

View AdamG's full-sized avatar

Adam Gomaa AdamG

  • San Francisco, CA
View GitHub Profile
class SitesPage(object):
def __init__(self, site, path):
self.site = site
self.path = path
self.load_data()
def load_data(self):
import gdata.sites.client
self.client = gdata.sites.client.SitesClient(
source="sitestest-v1", site=self.site)
@AdamG
AdamG / state.py
Created March 7, 2011 17:31
useless brainstorming
"""
Just some brainstorming. I don't really have a good repo for this.
So I've been thinking about state. The total state of an application
consists of the code, the data, and that's about it. There's external
state too. But everything, I dunno... should be *managed*, I guess. At
one level, that's the job of an OS. On the other hand, we're talking
potentially many machines.
This sounds like something plan9 would have already solved. That's OK.
;; modified version of zap-to-char from emacs CVS
;;
;; http://cvs.savannah.gnu.org/viewvc/emacs/emacs/lisp/simple.el?revision=1.1&view=markup
;;
;; Uncomment one line to get up-to-char behavior, as referenced in
;;
;; http://www.emacswiki.org/emacs/ZapToCharUsage#toc4
(defun zap-up-to-char (arg char)
"Kill up to ARG'th occurrence of CHAR.
@AdamG
AdamG / tagtimed.py
Created October 24, 2011 20:00
python tagtimed
#!/usr/bin/env python
"""
TagTime daemon, in python.
Only trying to get to 'worksforme' here - the perl daemon just isn't
launching anything 3/4 of the time, and I have no idea how to debug
it.
"""
@AdamG
AdamG / gist:1341479
Created November 5, 2011 13:00
NewsBlur reverse cron ordering
diff --git a/apps/reader/views.py b/apps/reader/views.py
index 1d7a89d..13c0a77 100644
--- a/apps/reader/views.py
+++ b/apps/reader/views.py
@@ -421,6 +421,10 @@ def load_single_feed(request, feed_id):
diff1, diff2, userstories_db and userstories_db.count() or '~SN0~SB', diff3))
FeedLoadtime.objects.create(feed=feed, loadtime=timediff)
+ prefs = json.decode(user.profile.preferences)
+ if prefs.get("chronological_ordering", "descending") == "ascending":
from django.db import models
from django.db.models.fields import CharField
class ModelField(CharField):
__metaclass__ = models.SubfieldBase
def __init__(self, **kwargs):
kwargs['blank'] = True
kwargs['max_length'] = 255
super(ModelField, self).__init__(**kwargs)
@AdamG
AdamG / imptest.py
Created July 28, 2012 13:23
Inner Import Overhead
import timeit
setup = """
import sys as sys_module_level
def outer_test():
return sys_module_level.version_info
def inner_test():
import sys
return sys.version_info
"""
$ du -sh srv/mysql-server
391M srv/mysql-server
$ # ^C the bzr branch lp:mysql-server
$ du -sh srv/mysql-server
84K srv/mysql-server
$ # ... for serious?
@AdamG
AdamG / gist:3796481
Created September 27, 2012 21:08
$HOME/bin/clean
#!/bin/sh
find -xdev -regextype posix-egrep -regex ".*\.(py[co]|orig|old|rej|bak)$" -print0 \
| xargs -0 rm -vf
def main():
testobj_0 = MemoMethods('test0')
testobj_1 = MemoMethods('test1')
wrong0 = testobj_0.foo_borked
right0 = testobj_0.foo_fixed
wrong1 = testobj_1.foo_borked
right1 = testobj_1.foo_fixed
# this is the bug, wrong0's method is run with test1 as self