Skip to content

Instantly share code, notes, and snippets.

View justinabrahms's full-sized avatar

Justin Abrahms justinabrahms

View GitHub Profile
"""
Fetches some valid oauth credentials from edX, using only the secret & app key.
Based primarly off of the Facebook example in flask-oauth
"""
from flask import Flask, redirect, url_for, session, request
from flask_oauth import OAuth
#!/bin/sh
# Originally from https://gist.github.com/dmkash/2355219
SESSION_NAME="ccxcon"
cd ~/src/github.com/mitodl/ccxcon
tmux has-session -t ${SESSION_NAME}
if [ $? != 0 ]
I really want a service where you can enter in 2 wikipedia pages and
it will tell you how they relate. It'd be especially cool if someone
else made it, so I'm writing up how I think it might be done in
Python.
Due to the nature of the queries you want to do (how does x relate to
y), I think this should end up in a graph database. In this graph
database, every page is a node. Links between pages are directed edges
in the graph, annotated with the paragraph of text they're linked
from.
@justinabrahms
justinabrahms / gist:7989647
Created December 16, 2013 16:14
Notes taken regarding interceptor pattern (similar to cujojs) ported to backend request handling. Needs to be better fleshed out and will probably only mean something to @phated
/*
goals:
middleware, like express.
no `.next()`, which express has.
use of promises (rejecting/resolving) unlike node's traditional (err, data) thing
immutable requests, preferring instead an explicit databag for state managment (continuous local storage)
"composable after the routing method"
@justinabrahms
justinabrahms / gist:7311596
Created November 5, 2013 00:02
Use a cached virtualenv during CI
VENV_DIR=`md5sum requirements/* | md5sum 2>&1 | awk '{print $1}'`
if [ -e $VENV_DIR ]; then
. /tmp/$VENV_DIR/bin/activate
else
virtualenv --no-site-packages /tmp/$VENV_DIR
. /tmp/$VENV_DIR/bin/activate
pip install --download-cache /var/lib/jenkins/.pip_download_cache -r requirements/ci.txt
fi
@justinabrahms
justinabrahms / gist:6973796
Last active December 25, 2015 12:09
Node transform which will turn variables (and similar) of the format `bar_` to indicate privateness, into `_bar`.
#!/usr/bin/env node
/*
* We have trailing underscores on variables to indicate
* private. That's silly. Preceeding underscores are the only obvious
* choice.
*
* var foo = function () {
* this.bar_ = '9';
* _.bindAll(this, 'foo_');
* }
@justinabrahms
justinabrahms / gist:6133950
Created August 1, 2013 18:31
Small linter using jsl which will detect python-style variable names and complain. Usable as a precommit hook with: git diff --cached --name-only --diff-filter=ACM | grep ".js" | xargs node lint.js
var lint = require('jsl')
, linter = lint();
linter.rule('variable > id',
function (node, subsource, alert) {
var var_name = node.name;
if (var_name.indexOf("_") !== -1) {
alert(node, 'Found variable name with underscores: ' + var_name);
}
}, 'error');
@justinabrahms
justinabrahms / gist:6027925
Last active December 19, 2015 22:29
Node.js script which transforms old-style AMD modules into modules with the sugar syntax outlined in http://requirejs.org/docs/whyamd.html#sugar The code is ugly and procedural, but it solves a need. *NOTE*: This hasn't yet been validated to work. Specifically it doesn't provide a return statement which the requirejs documentation indicates it s…
#!/usr/bin/env node
/**
* Transforms code from old-style requirejs modules into AMD sugared modules.
*
* define(['dep1','dep2'], function(arg1, arg2) {...})
*
* becomes:
*
* define(function(require) { var arg1 = require('dep1'), arg2 = require('dep2'); ... });
*
@justinabrahms
justinabrahms / gist:5777664
Last active December 18, 2015 11:39
Simple Go utility for mocking out a tags API that supports resort.
package main
import (
"encoding/json"
"errors"
"fmt"
"html"
"log"
"net/http"
)
@justinabrahms
justinabrahms / gist:5465490
Last active December 16, 2015 16:49
A method of getting per-user logs in python logging. It turns out my original plan which is /var/log/myapp/user.<pk>.log isn't a very good idea from performance b/c you're basically sitting there with a bunch of open files and a bunch of logging handlers each with their own per-user id filter applied. After you get logs in this format, you can w…
class UserLog(object):
"""
Simple log that will output specially formatted user id for logging
purposes.
-1 is used as a sentinal value to mean "no user". Otherwise, the user's `pk`
attribute is logged instead.
An explicit decision was made not to use a LoggerAdapter with a custom
format string because if we attach it to something that isn't the logger