Skip to content

Instantly share code, notes, and snippets.

View nathanborror's full-sized avatar

Nathan Borror nathanborror

View GitHub Profile
The University of Kansas,
Let me briefly explain the process in which I'm trying to give you money:
1) I click a total of seven times to get to the point where I can pay my tuition and I'm greeted with: "Security Error: The authentication process failed or the page is not accessible to you at this moment." I decide to call the IT department and they say I need to try FireFox, it works. They go on to say if I allow third-party cookies on my initial browser the site would work. This is a terrible recommendation, third-party cookies are very insecure and should never be allowed. I'm trying to give you a lot of money and this should be easy.
2) I go to make a payment using my credit card. You only accept Mastercard and Discover, seriously? I only have Visa (along with everyone else) so this isn't going to work, not to mention the $25 fee you charge which, by this point is the turning of the blade. I'm trying to give you a lot of money and this should be easy.
3) I call the Bursars office they say use a check.
@login_required
def comment_edit(request, comment_id, template_name='comments/edit.html'):
comment = get_object_or_404(Comment, pk=comment_id, user=request.user)
if request.POST:
data = request.POST.copy()
if not data.get('name', ''):
data["name"] = request.user.get_full_name() or request.user.username
if not data.get('email', ''):
data["email"] = request.user.email
function Jtl(tpl) {
this._nodelist = this._compile(tpl);
}
Jtl.prototype = {
_compile : function(tpl) {
var tag_str = this._formRegx();
var tag_re = new RegExp(tag_str,'g');
var bits = new Jtl.StringBuilder(tpl).bsplit(tag_re);
bits = new Jtl.ArrayBuilder(bits).filter('');
@nathanborror
nathanborror / xmltohtml.py
Created July 27, 2011 06:55
XML to HTML template rendering
from lxml import objectify
from django import template
from django.template.loader import render_to_string
register = template.Library()
class XMLNode(template.Node):
def __init__(self, xml):
Original code spread across 28 templates in various permutations. Anytime I wanted to restructure tabs I'd have to change every damn template:
<ul class="tabs">
<li><a{% if not group %} class="on"{% endif %} href="{% url user_books username=reader.username %}">{% trans "All" %}</a></li>
<li><a{{ group|is_on:'finished' }} href="{% url user_book_group username=reader.username,group="finished" %}">{% trans "Finished" %}</a></li>
<li><a{{ group|is_on:'reading' }} href="{% url user_book_group username=reader.username,group="reading" %}">{% trans "Reading" %}</a></li>
<li><a{{ group|is_on:'plan-to-read' }} href="{% url user_book_group username=reader.username,group="plan-to-read" %}">{% trans "Plan to read" %}</a></li>
</ul>
Abstract it out to an XML tree:
@nathanborror
nathanborror / gist:2884560
Created June 6, 2012 20:29
Mediator Pattern
define([], function(obj) {
var channels = {};
if (!obj) obj = {};
obj.subscribe = function(channel, subscription) {
if (!channels[channel]) channels[channel] = [];
channels[channel].push(subscription);
return channels[channel].length -1;
};
@nathanborror
nathanborror / gist:3470564
Created August 25, 2012 20:21
Readernaut API

Readernaut API

I'm going to be deprecating the current Readernaut API in favor of a newer more built-out version. People using the current version have two weeks to switch over to the new API. Currently you can find your API_KEY by viewing source on any page and searching for "api_key" in the output (this will get better later). Here are some example endpoints:

Notes

  • Old: /services/api/USERNAME/notes/
  • New: /api/v1/notes/note/?username=YOUR_USERNAME&api_key=YOUR_API_KEY&user__username=USERNAME

Books

@nathanborror
nathanborror / gist:9338630
Created March 4, 2014 01:39
constraintsWithVisualFormats
// NSArray *formats = @[
// @"H:|-[textView]-|",
// @"H:|-[moreButton]-|",
// @"V:|-[textView]-[moreButton]-|",
// ];
// [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormats:formats options:0 metrics:nil views:views]];
@implementation NSLayoutConstraint (Common)

Keybase proof

I hereby claim:

  • I am nathanborror on github.
  • I am nathanborror (https://keybase.io/nathanborror) on keybase.
  • I have a public key whose fingerprint is 5D26 8211 E160 5ED3 F5E2 D49E 9533 D273 8B6C BC97

To claim this, I am signing this object:

description "start and stop the go program 'my-project'"
start on filesystem or runlevel [2345]
stop on runlevel [!2345]
env USER='ubuntu'
env APP_DIR='/home/ubuntu/go/src/github.com/your-username/your-project-name/'
env APP_EXEC='your-project-name'
exec start-stop-daemon —start —chuid ${USER} —chdir ${APP_DIR} —exec ${APP_DIR}${APP_EXEC}