Skip to content

Instantly share code, notes, and snippets.

View obeattie's full-sized avatar
🏖️
On holiday

Oliver Beattie obeattie

🏖️
On holiday
View GitHub Profile
@obeattie
obeattie / hide-blogger-warning.user.js
Created April 11, 2010 08:39
Automatically skips the obnoxious "Content warning" on Blogger sites (only those with blogspot.com domains) — and doesn't require a page reload to do so. Winnah. To install using Google Chrome or Grasemonkey, click raw and you'll be prompted to install th
// ==UserScript==
// @name Blogger Content Warning Skip
// @description Automatically skips the content warning on blogspot.com sites without reloading the page
// @match http://*.blogspot.com/*
// ==/UserScript==
var fireEvent = function(obj,evt){
var fireOnThis = obj;
if (document.createEvent) {
var evObj = document.createEvent('MouseEvents');
@obeattie
obeattie / db_utils.py
Created October 14, 2009 12:51
Exposes SQLAlchemy's sessions and transactions as context managers (so they will be managed automatically inside blocks), and also provides a transaction decorator, which wraps an entire function in a transaction
"""Utilities for managing database sessions."""
from __future__ import with_statement
import contextlib
import functools
@contextlib.contextmanager
def temp_session(session_cls, **kwargs):
"""Quick and dirty context manager that provides a temporary Session object
to the nested block. The session is always closed at the end of the block.
@obeattie
obeattie / s3signurl.py
Created July 19, 2011 10:27
Quick, dirty Python script that spits out a signed url for Amazon S3
#!/usr/bin/env python
import optparse
import sys
from boto.s3.connection import S3Connection
def sign(bucket, path, access_key, secret_key, https, expiry):
c = S3Connection(access_key, secret_key)
return c.generate_url(
expires_in=long(expiry),
@obeattie
obeattie / datetime_range.py
Created October 19, 2009 12:31
A datetime range class for Python, for (obviously) dealing with ranges of datetimes.
"""Provides a `DateTimeRange` class, which is used for managing ranges of datetimes."""
import datetime
class DateTimeRange(object):
"""Represents a range of datetimes, with a start and (optionally) an end.
Basically implements most of the methods on a standard sequence data type to provide
some lovely syntactic sugar. Specifically, you can iterate on this, index it, slice it,
use the in operator, reverse it, and use it in a boolean context to see if there is any
time in between the start and end."""
// Package h2c provides a HTTP/2.0 h2c client transport implementation
package h2c
import (
"bufio"
"bytes"
"context"
"encoding/base64"
"encoding/binary"
"fmt"
@obeattie
obeattie / group.js.coffee
Created April 11, 2013 13:49
CoffeeScript source for Paper.js modifications
_getClipItems: () ->
unless @_clipItems?
@_clipItems = (c for c in @_children when c._clipMask)
return @_clipItems
draw: (ctx, param) ->
clipItems = @_getClipItems()
# If the group is to be clipped, draw them to an in-memory canvas
@obeattie
obeattie / oauth-v2.html
Created October 21, 2012 14:12
Pretty version of the draft OAuth spec
<!doctype html>
<html>
<head>
<title>draft-ietf-oauth-v2-31 - The OAuth 2.0 Authorization Framework</title>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel=stylesheet type="text/css" href="http://pretty-rfc.herokuapp.com/style.css">
<meta name=viewport content="width=device-width, initial-scale=1.0">
</head>
import distutils.sysconfig as sysconfig
import re
import sublime
import sublime_plugin
FROM_IMPORT_RE = re.compile(r'^\s*from (?P<package>\.?\w*)(?P<package_extra>\S*)\s+import\s+(?P<subpackages>.+)')
PLAIN_IMPORT_RE = re.compile(r'^\s*import (?P<package>\.?\w*)(?P<package_extra>\S*)')
CONTINUATION_RE = re.compile(r'.*(\\\s*)$')
PARENTHESISED_START_RE = re.compile(r'^.+? import \(')
### Use the standard LV.Ticker event loop for jQuery animations, too (which uses requestAnimationFrame under the
covers, if supported by the client) ###
class LV.JQAnimation extends LV.Animation
constructor: (timer) ->
@timer = timer
@start()
return
step: () ->
@obeattie
obeattie / lv_import_sorter.py
Created June 12, 2012 07:01
Sublime Plugin to sort imports like momma used to
import distutils.sysconfig as sysconfig
import re
import sublime
import sublime_plugin
FROM_IMPORT_RE = re.compile(r'^\s*from (?P<package>\.?\w*)(?P<package_extra>\S*)\s+import\s+(?P<subpackages>.+)')
PLAIN_IMPORT_RE = re.compile(r'^\s*import (?P<package>\.?\w*)(?P<package_extra>\S*)')
CONTINUATION_RE = re.compile(r'.*(\\\s*)$')
PARENTHESISED_START_RE = re.compile(r'^.+? import \(')