Skip to content

Instantly share code, notes, and snippets.

View sivy's full-sized avatar

Steve Ivy sivy

View GitHub Profile
@sivy
sivy / shard_array.py
Last active September 17, 2022 10:23
Split a large array (inlist) into sublists (shards) of length (shard_size). Good for batch-jobbing large lists of data.
def _shard_array(inlist, shard_size):
# inlist = 150-element list
# shard_size = 40
num_shards = len(inlist) / shard_size
# num_shards == 3
shards = []
for i in range(num_shards):
# i == 0
start = shard_size * i # start == 0, then 40, then 80...
@sivy
sivy / archive.html
Last active December 10, 2015 00:48 — forked from anonymous/archive.html
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Archive - {{ site.title }}</title>
<meta name="author" content="{{ user.display_name }}">
<meta name="description" content="{{ site.description }}">
<meta name="viewport" content="width=device-width; initial-scale=1; maximum-scale=1">
<link href="/atom.xml" rel="alternate" title="{{ site.url }} feed" type="application/atom+xml">
def sync_templates(client, uid, template_name=None):
templates = UserTemplate.query()
for t in templates.iter():
if not template_name or t.name == template_name:
try:
tresp, meta = client.get_file_and_metadata(
"/templates/" + t.name)
t.content = tresp.content.decode('utf8')
t.put()
except: # template doesn't exist for new users sometimes
def post(self):
uid = self.account.dropbox_uid
action = self.request.get('action', '')
if action != 'save':
self.error_out(500, 'Bad request, not action provided.')
template_name = self.request.get('template_name')
template_content = self.request.get('content')
@sivy
sivy / post.html
Created October 16, 2012 17:42
echoloquation sample post template
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="generator" content="Echoloquation - http://echoloquation.com" />
<title>{{ site.title }}</title>
<style type="text/css">
body {
margin-top: 0px;
app = WSGIApplication([
DomainRoute('<subdomain>.' + config.APP_HOST, [
# request for sub.foo.com passes subdomain=sub to IndexHandler
Route('/', blog.IndexHandler, name='blog'),
# request for sub.foo.com/path passes path=foo to PostHandler
# but NOT the subdomain
# I expected this route to get subdomain=sub, path=path
Route('/<path:.+>', blog.PostHandler, name='post'),
]),
], config=config.webapp_cfg, debug=True)
from google.appengine.ext import testbed
from google.appengine.ext import ndb # SDK 1.7, OS X
import unittest
from webtest import TestApp
from main import app
from models import compute_hash #, Subscription
from nose.tools import ok_, eq_
import unittest
from google.appengine.ext import testbed
from google.appengine.ext import ndb
from webtest import TestApp
from admin import app
import os
from django.utils import simplejson as json
import datetime
from google.appengine.ext import ndb
from google.appengine.ext import testbed
from models import Subscription
DATE_FMT = "%Y-%m-%d %H:%M:%S"
(Pdb) pp Key
<class 'google.appengine.ext.ndb.key.Key'>
(Pdb) pp value
Key('Subscription', None)
(Pdb) type(value)
<class 'google.appengine.ext.ndb.key.Key'>
(Pdb)