Skip to content

Instantly share code, notes, and snippets.

View alanhamlett's full-sized avatar

Alan Hamlett alanhamlett

View GitHub Profile
@alanhamlett
alanhamlett / utils.js
Created September 29, 2015 23:11
Utility Function to Map JSON errors from wtforms-json onto an HTML form
(function() {
var utils = {};
utils.clear_form_errors = function($el) {
$el.find('.text-danger').each(function() {
$(this).empty();
});
return $el;
};
{% extends "common/base.html" %}
{% block subtitle %}Django vs Flask Worksheet{% endblock %}
{% block css %}
{% compress 'css' %}
<link href="{{STATIC_URL}}libs/fullpage.js/jquery.fullPage.css" rel="stylesheet" type="text/css">
<link href="{{STATIC_URL}}css/django-vs-flask-worksheet.less" rel="stylesheet" type="text/less">
{% endcompress %}
{% endblock %}
@alanhamlett
alanhamlett / wakatime_github_timeline.py
Last active August 29, 2015 14:14
WakaTime GitHub Commit Timeline
""" File: views.py
"""
@blueprint.route('/project/<path:project_name>/commits')
@api_utils.nocache
@auth.login_required
def project_commits(project_name):
user = app.current_user

Keybase proof

I hereby claim:

  • I am alanhamlett on github.
  • I am alanhamlett (https://keybase.io/alanhamlett) on keybase.
  • I have a public key whose fingerprint is 2A17 98FE 2E12 3F7C BCDB E05F 76C4 315D 71A9 FECC

To claim this, I am signing this object:

@alanhamlett
alanhamlett / UpdateHandler.java
Created December 8, 2014 23:05
Auto update class for a NetBeans IDE plugin
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
@alanhamlett
alanhamlett / test_oauth.py
Last active August 29, 2015 14:10
OAuth example
#!/usr/bin/env python
import base64
import requests
ACCESS_TOKEN = "XXX"
APP_SECRET = "XXX"
# get some JSON, authenticating with url args
r = requests.get('https://wakatime.com/api/v1/users/current/stats/complete', params={'access_token': ACCESS_TOKEN})
@alanhamlett
alanhamlett / models.py
Created September 22, 2014 01:57
django model manager example
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
from django.db import models, transaction
from django.utils import timezone
class Manager(models.Manager):
""" Use this class to define custom methods on models.
"""
def get_query_set(self):
@alanhamlett
alanhamlett / responsive.less
Last active September 30, 2020 18:19
Responsive helper classes for Bootstrap style margins, padding, aligning, and displaying per screen size
/* responsive.less
* ~~~~~~~~~~~~~~~
*
* Responsive helper classes for Bootstrap style margins, padding, aligning, and displaying per screen size.
* Works along with Bootstrap3.
*/
//== Media queries breakpoints from Bootstrap3
// Extra small screen / phone
@alanhamlett
alanhamlett / amqp.py
Last active October 22, 2021 21:18
send an error email when a Celery worker raises an unhandled exception
# -*- coding: utf-8 -*-
"""
wakatime.amqp
~~~~~~~~~~~~~
Setup for Celery distributed task queue.
"""
import socket
@alanhamlett
alanhamlett / Flask-Login-Example.py
Created April 23, 2014 19:25
Flask-Login Example
# -*- coding: utf-8 -*-
"""
More info:
http://flask.pocoo.org/docs/patterns/wtforms/
http://pythonhosted.org/Flask-SQLAlchemy/
https://flask-login.readthedocs.org/en/latest/
"""
from flask import current_app, request, render_template, redirect, url_for
from myapp.models import User