Skip to content

Instantly share code, notes, and snippets.

Avoid jQuery When Possible

jQuery does good jobs when you're dealing with browser compatibility. But we're living in an age that fewer and fewer people use old-school browsers such as IE <= 7. With the growing of DOM APIs in modern browsers (including IE 8), most functions that jQuery provides are built-in natively.

When targeting only modern browsers, it is better to avoid using jQuery's backward-compatible features. Instead, use the native DOM API, which will make your web page run much faster than you might think (native C / C++ implementaion v.s. JavaScript).

If you're making a web page for iOS (e.g. UIWebView), you should use native DOM APIs because mobile Safari is not that old-school web browser; it supports lots of native DOM APIs.

If you're making a Chrome Extension, you should always use native APIs, not only because Chrome has almost the latest DOM APIs available, but this can also avoid performance issue and unnecessary memory occupation (each jQuery-driven extension needs a separate

{{define "body"}}
This is the start page.
<br><br>
Check out <a href="/user/5">user 5</a> or <a href="/user/7">user 7</a>.
{{end}}
type ApacheLogRecord struct {
http.ResponseWriter
ip string
time time.Time
method, uri, protocol string
status int
responseBytes int64
elapsedTime time.Duration
}
# 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'
# 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):
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
#
# 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',
@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
#
@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 / 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:
& < >