Skip to content

Instantly share code, notes, and snippets.

View gregorynicholas's full-sized avatar
💀
alter.

gregory nicholas gregorynicholas

💀
alter.
View GitHub Profile
@gregorynicholas
gregorynicholas / javascript-basic-sorted-array-binary-search.js
Created August 8, 2011 23:23
basic javascript sortes array binary search
var pages = [];
var page_height= 100;
var page_total= 2;
for (var i = 0; i < page_total; i++) {
var page = {min: i * page_height, max: i * page_height + page_height, page_no: i };
pages[i] = page;
}
/*for loop builds something like this: var pages = [{
@gregorynicholas
gregorynicholas / handler_utils.py
Created September 29, 2011 23:23
Python method decorator for appengine to ouput json to response.
def jsonresult(func):
'''
Decorator that sets response headers to output json data.
'''
def _func(self, *args, **kwargs):
self.response.headers['Content-Type'] = "text/plain"
logging.debug('--- Outputting JSON Result ---')
result = func(self, args, kwargs)
self.response.out.write(json.dumps(result))
return _func
@gregorynicholas
gregorynicholas / clearfix.css
Created October 27, 2011 14:41
CSS Clear Fix
/*
Example Usage:
<div style="float:left">
...
</div>
<div style="float:right;" class="clearfix">
...
</div>
@gregorynicholas
gregorynicholas / window.console.js
Created December 8, 2011 18:41
Window.console: One line console.log object checker.
if(!('console' in window)){window.console={log:function(){}}
@gregorynicholas
gregorynicholas / gist:1564364
Created January 5, 2012 09:10 — forked from kylefinley/gist:1059647
webapp2 auth User model
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import datetime
from ndb import model
from webapp2_extends.utils import Unique, UniqueConstraintViolation, \
check_password_hash, generate_password_hash
from webapp2_extends.auth import create_session_id
DEBUG = True
@gregorynicholas
gregorynicholas / withings.py
Created January 12, 2012 01:53 — forked from pamelafox/withings.py
Withings Python OAuth Wrapper
# -*- coding: utf-8 -*-
# Based on https://github.com/ikasamah/withings-garmin/blob/master/withings.py
import urllib
from datetime import datetime
import urlparse
import oauth2 as oauth
try:
import json
@gregorynicholas
gregorynicholas / gist:1598043
Created January 12, 2012 01:55 — forked from pamelafox/gist:1006753
Sendgrid Python Web API example
import urllib2, urllib
import logging
def send_mail_sendgrid(from, to, subject, body):
base_url = 'https://sendgrid.com/api/mail.send.json'
params = {
'api_user': '[email protected]',
'api_key': 'yourpassword',
'from': from,
'to': to,
@gregorynicholas
gregorynicholas / forms.py
Created January 14, 2012 02:34 — forked from kylefinley/forms.py
webapp2: Password reset
import models
from wtforms import Form
from wtforms import fields
from wtforms import validators
class PasswordRestForm(Form):
email = fields.TextField('email')
class PasswordChangeForm(Form):
current = fields.PasswordField('Current Password')
@gregorynicholas
gregorynicholas / gist:1610004
Created January 14, 2012 02:34 — forked from kylefinley/gist:1059647
webapp2 auth User model
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import datetime
from ndb import model
from webapp2_extends.utils import Unique, UniqueConstraintViolation, \
check_password_hash, generate_password_hash
from webapp2_extends.auth import create_session_id
DEBUG = True
@gregorynicholas
gregorynicholas / requestAnimFrame.js
Created January 14, 2012 20:16
window.requestAnimFrame - detect framerate from browser objects, with fallback to timer
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function */ callback, /* DOMElement */ element){
window.setTimeout(callback, 1000 / 60);
};
})();