Skip to content

Instantly share code, notes, and snippets.

View torufurukawa's full-sized avatar

Toru Furukawa torufurukawa

View GitHub Profile
from google.appengine.ext import db
class ReferenceProperty(db.ReferenceProperty):
"""A property that represents a many-to-one reference to another model.
This class has serveral enhancement on
google.appengine.ext.db.ReferenceProperty.
1. Its object returns None when referenced entity does not exist, nstead
of raising ReferencePropertyResolveError.
class DotDict(dict):
def __getattr__(self, attr):
return self.get(attr, None)
__setattr__= dict.__setitem__
__delattr__= dict.__delitem__
@torufurukawa
torufurukawa / gaedb.py
Created January 7, 2012 03:11
pdb.set_trace alternative for Google App Engine
def set_trace():
import pdb, sys
debugger = pdb.Pdb(stdin=sys.__stdin__,
stdout=sys.__stdout__)
debugger.set_trace(sys._getframe().f_back)
@torufurukawa
torufurukawa / gist:1598658
Created January 12, 2012 04:14
GAE DateTimeProperty index
from datetime import datetime, timedelta
from google.appengine.ext import db
class Foo(db.Model):
value = db.DateTimeProperty()
db.delete(Foo.all())
Foo(value=None).put()
Foo(value=datetime.now()).put()
@torufurukawa
torufurukawa / hgpelo.py
Created June 2, 2012 03:12
hg extension for pelo branching model
# coding: utf8
"""pelo
pelo branch management wrapper commands
"""
from datetime import datetime
from mercurial import commands
HELP_DOC = """COMMAND OPERATION [label]
@torufurukawa
torufurukawa / ticketinfo
Created July 3, 2012 01:56
Redmine のチケットから、タイトル、URL、期日を取得する bookmarklet
javascript:(
function(){
var url = document.location.toString();
var title_start_pattern = /(#.+)/;
var title_end_pattern = /- [^-]+ - Redmine/;
document.title.match(title_start_pattern);
RegExp.lastMatch.match(title_end_pattern);
var title = RegExp.leftContext;
var elements = document.getElementsByClassName('due-date');
var due = elements[1].firstChild.nodeValue;
@torufurukawa
torufurukawa / gist:4949837
Created February 14, 2013 01:05
Get running instance names on EC2
import boto.ec2
c = boto.ec2.connect_to_region('ap-northeast-1',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key)
reservations = c.get_all_instances()
instances = [item for sublist in reservations for item in sublist.instances]
for instance in instances:
if instance.state != 'running':
continue
;;; -*- coding: utf-8 -*-
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(column-number-mode t)
'(show-paren-mode t)
'(tool-bar-mode nil)
div#header-inner div.titlewrapper {
margin-left: 2px;
padding-bottom: 0px;
}
div.header-outer .descriptionwrapper {
width: 500px;
}
div#header-inner div.descriptionwrapper {
{
"author": {
"name": "wozozo",
"position": "co-founder"
},
"message": "hello"
}