Skip to content

Instantly share code, notes, and snippets.

View pamelafox's full-sized avatar

Pamela Fox pamelafox

View GitHub Profile
@pamelafox
pamelafox / gist:1261016
Created October 4, 2011 06:26
Sending JS errors to server
window.onerror = function(message, url, line_num) {
// Standard error information
var error = '\n JS Error: ' + message + ' from ' + url + ':' + line_num;
error += '\n URL: ' + document.URL;
// User agent info, using https://github.com/caseyohara/user-agent
var user_agent = new UserAgent();
error += '\n Browser: ' + user_agent.browser_name + ' ' + user_agent.browser_version + ' | OS: ' + user_agent.os + ' | Platform: ' + user_agent.platform;
@pamelafox
pamelafox / personalize.js
Created October 12, 2011 00:00
Javascript grammatical personalization library
/**
* A function that takes a template and grammatical options ('gender', 'person', 'name') and returns the computed string.
* See below for examples.
*
* See wikipedia for more on grammar:
* http://en.wikipedia.org/wiki/English_personal_pronouns
* http://en.wikipedia.org/wiki/Grammatical_conjugation
*/
function personalize(template, options) {
var GENDERS = ['neutral', 'female', 'male'];
@pamelafox
pamelafox / Makefile
Created October 13, 2011 21:43
Closure/YUI/JsHint Makefile
# Makefile for JS/CSS:
# Uses Closure for JS compiling, YUI for CSS compiling, and JsHint for code quality checking
MAKEFLAGS = --no-print-directory --always-make
MAKE = make $(MAKEFLAGS)
BUILDDIR = ./.build
CLOSUREURL = http://closure-compiler.googlecode.com/files/compiler-latest.zip
CLOSUREDIR = $(BUILDDIR)/closure
@pamelafox
pamelafox / views.py
Created October 18, 2011 07:40
Facebook logout (Flask)
@login_required
def handle_logout():
import facebook
if g.user.facebook_id:
base_domain = util.get_base_domain()
default_fb_data = FB_DATA['appspot.com']
fb_app_id = FB_DATA.get(base_domain, default_fb_data).get('appid')
fb_app_secret = FB_DATA.get(base_domain, default_fb_data).get('appsecret')
cookie = facebook.get_user_from_cookie(request.cookies, fb_app_id, fb_app_secret)
@pamelafox
pamelafox / phonegap.html
Created October 20, 2011 23:05
PhoneGap Timing Template
<!doctype html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width" />
<title>PhoneGap App</title>
<script>
var timedEvents = [];
function timeEvent(name) {
timedEvents.push({'name': name || 'unnamed', time: Date.now()});
}
@pamelafox
pamelafox / button.html
Created October 24, 2011 04:51
Changing button states (Bootstrap)
<button class="btn save-button primary" type="submit" data-startmsg="Save" data-loadingmsg="Saving..." data-successmsg="Saved!">Save</button>
@pamelafox
pamelafox / send.js
Created November 7, 2011 21:21
CORS XHR (jQuery/Flask)
function sendData(url, data, onSuccess, onError) {
$.ajax({
url: url,
type: 'POST',
data: data,
dataType: 'json',
xhrFields: {
withCredentials: true
},
@pamelafox
pamelafox / dimensions.js
Created November 18, 2011 23:58
outer/inner/Width/Height
['width', 'height'].forEach(function(dimension) {
var offset, Dimension = dimension.replace(/./, function(m) { return m[0].toUpperCase() });
$.fn['outer' + Dimension] = function(margin) {
var elem = this;
if (elem) {
var size = elem[dimension]();
var sides = {'width': ['left', 'right'], 'height': ['top', 'bottom']};
sides[dimension].forEach(function(side) {
size += parseInt(elem.css('padding-' + side), 10);
(function($) {
// Used by dateinput
$.expr = {':': {}};
// Used by bootstrap
$.support = {};
// Used by dateinput
$.fn.clone = function(){
var ret = $();
@pamelafox
pamelafox / dateinput.js
Created November 24, 2011 01:50
Zepto jQueryTools DateInput
/**
* @license
* jQuery Tools @VERSION Dateinput - <input type="date" /> for humans
*
* NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
*
* http://flowplayer.org/tools/form/dateinput/
*
* Since: Mar 2010
* Date: @DATE