Skip to content

Instantly share code, notes, and snippets.

View andymccurdy's full-sized avatar

Andy McCurdy andymccurdy

  • San Francisco, CA
View GitHub Profile
cat_to_remove = <category_publishable_is_being_removed_from>
categories = [all_current_leaf_categories_publishable_is_in];
categories.remove(cat_to_remove);
all_cats = set()
for cat in categories:
while cat:
all_cats.add(cat)
cat = cat.parent
# all_cats should now be a set of all categories the publishable should still be in after the removal
YOUR_USERNAME = 'andy'
import scout.recon.register
from django.contrib.auth.models import User
u = User.objects.get(username=YOUR_USERNAME)
u.profile['plan_id'] = 2
u.profile['next_billing_date'] = '2012-09-01'
u.save()
# == ella ==
# fetching
# you should switch ella to branch 1a1360c90efcce3fafd9016051192533c6e3ef0b:
cd /Users/andy/momme/ella; git checkout 1a1360c90efcce3fafd9016051192533c6e3ef0b || git checkout -b 1a1360c90efcce3fafd9016051192533c6e3ef0b origin/1a1360c90efcce3fafd9016051192533c6e3ef0b
HEAD is now at 1a1360c... run generate_publish_signals way more often
fatal: ambiguous argument '..origin/1a1360c90efcce3fafd9016051192533c6e3ef0b': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
<shockwave:andy : ~ > brew install python3 --framework --universal -v
==> Downloading http://python.org/ftp/python/3.2.3/Python-3.2.3.tar.bz2
Already downloaded: /Library/Caches/Homebrew/python3-3.2.3.tar.bz2
/usr/bin/tar xf /Library/Caches/Homebrew/python3-3.2.3.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/python3/3.2.3 --enable-ipv6 --enable-framework=/usr/local/Cellar/python3/3.2.3/Frameworks
./configure --prefix=/usr/local/Cellar/python3/3.2.3 --enable-ipv6 --enable-framework=/usr/local/Cellar/python3/3.2.3/Frameworks
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... darwin
checking machine type as reported by uname -m... x86_64
class Script(object):
"An executable LUA script object returned by ``register_script``"
def __init__(self, registered_client, script):
self.registered_client = registered_client
self.script = script
self.sha = None
def __call__(self, keys=[], args=[], client=None):
"Execute the script, passing any required ``args``"
LUA Scripting with redis-py
===========================
redis-py supports the EVAL, EVALSHA, and SCRIPT commands. However, there are
a number of edge cases that make these commands tedious to use in real world
scenarios. Therefore, redis-py exposes a Script object that makes scripting
much easier to use.
To create a Script instance, use the `register_script` function on a client
instance passing the LUA code as the first argument. `register_script` returns
Tech
Smartphones
Tablets
PCs
Accessories
iOS
Android
Windows
Windows Phone
Mac OS
import time
from redis import ConnectionPool, Redis
class WaitingConnectionPool(ConnectionPool):
"Connection Pool that blocks if a connection is not available"
def make_connection(self):
while True:
if self._created_connections >= self.max_connections:
time.sleep(0.01)
self._created_connections += 1
<?php
require_once('workflows.php');
$w = new Workflows();
function get_icon($weather) {
$icon = '';
switch($weather):
case 'Chance of Rain': $icon = 'icons/007.png'; break;
case 'Chance of Snow': $icon = 'icons/014.png'; break;
class TemplateWidget(object):
"Uses a template to render the widget"
def __init__(self, template, get_value_callable=None):
self.template = template
self.get_value_callable = get_value_callable
def __call__(self, field, **kwargs):
kwargs.update({'field': field})
if self.get_value_callable:
kwargs['value'] = self.get_value_callable(field)