Skip to content

Instantly share code, notes, and snippets.

tell application "Safari"
set _source to do JavaScript "window.document.documentElement.outerHTML" in document 1
set _name to name of document 1
end tell
tell application "BBEdit"
make new text window with properties ¬
{contents:_source, source language:"HTML", name:"Generated source: " & _name}
select insertion point before character 1 of text window 1
@rogeriomarques
rogeriomarques / LazyControllerLoader.py
Created November 4, 2010 17:42 — forked from dound/LazyControllerLoader.py
LazyControllerLoader.py
# Adapted from http://appengine-cookbook.appspot.com/recipe/lazy-loading-webapp-handler/
def _istring(import_name):
"""Imports an object based on a string.
@param import_name the dotted name for the object to import.
@return imported object
"""
module, obj = import_name.rsplit('.', 1)
# __import__ can't handle unicode strings in fromlist if module is a package
if isinstance(obj, unicode):
@rogeriomarques
rogeriomarques / YAPTU
Created November 16, 2010 14:50
Yet Another Python Templating Utility
"""Yet Another Python Templating Utility, Version 1.2, by Alex Martelli.
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52305
(Specialized to HTML and modified by Peter Norvig.)
Copies input to output, with some substitutions. There are three types
of substitutions: lexical, expression, and statement.
LEXICAL SUBSTITUTIONS:
& < >
@rogeriomarques
rogeriomarques / yaml2py
Created November 16, 2010 19:30
Basic class code generator
import os
import sys
import re
import yaml
from new import classobj
"""
Yaml file looks like this -
Class:
@rogeriomarques
rogeriomarques / gist:708683
Created November 21, 2010 11:53
HTTP Decorators Plugin
# coding=UTF-8
#
# HTTP Decorators Plugin provides some HTTP decorators for your controller actions
# Usage:
# 1) Import the decorators ("from plugins.http_decorators import *")
# 2) Annotate your action. Example: To allow only GET-requests to the action 'myaction':
# @http_get_method_only
# def myaction(self):
# pass
#
#
# bon clarice, comme dans beaucoup de programme, nous avons de variables,
# des fonctions avec boucles et conditions, et une fonction principale.
# d'abord deux variables, globales dans ce cas.
# elles sont des listes, une est vide, l'autre pas.
ptichoux = []
ouf = [ 'houga houga',
import cgi
import os
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import memcache
from google.appengine.api import urlfetch
# based on http://amix.dk/blog/post/19574
from datetime import datetime, timedelta
GRAVITY = 0.5 # HN default: 1.8
WINDOW = 36 # max age in hours
now = datetime.now()
def hours_from_dt(dt):
# http://stackoverflow.com/questions/748324/python-convert-those-tinyurl-bit-ly-tinyurl-ow-ly-to-full-urls
#############
# urllib2
import urllib2
fp = urllib2.urlopen('http://bit.ly/rgCbf')
fp.geturl()
# ==> 'http://webdesignledger.com/freebies/the-best-social-media-icons-all-in-one-place'
type ApacheLogRecord struct {
http.ResponseWriter
ip string
time time.Time
method, uri, protocol string
status int
responseBytes int64
elapsedTime time.Duration
}