Skip to content

Instantly share code, notes, and snippets.

@respondcreate
respondcreate / pyjwt_okta_access_token_local_validate.py
Created February 16, 2019 13:46
PyJWT RS256 Okta Access Token Local Validation Example
"""How to validate Okta Access Tokens Locally with Python"""
import jwt
from jwt.algorithms import RSAAlgorithm
# Key pulled from https://{example}.oktapreview.com/oauth2/{client-id}/v1/keys
key_json = '{"kty":"RSA","alg":"RS256","kid":"your-kid-value-here","use":"sig","e":"AQAB","n":"your-long-key-here"}'
aud = "your-audience-value-here"
token_to_validate = "your-access-token-value-here"
@kottenator
kottenator / simple-pagination.js
Created July 13, 2015 20:44
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
@janko
janko / 01-activerecord.rb
Created May 27, 2015 22:50
PostgreSQL JSON querying in Sequel (my presentation from our local Ruby meetup)
require "active_record"
ActiveRecord::Base.establish_connection('postgres:///testing')
ActiveRecord::Migration.verbose = false
ActiveRecord::Migration.class_eval do
create_table :played_quizzes, force: true do |t|
t.integer :player_ids, array: true
t.json :quiz_snapshot
end
@mahmoodkhan
mahmoodkhan / google_spreadsheet.py
Last active August 29, 2015 14:13
Exporting data to Google Spreadsheet using gdata.spreadsheets.client and gdata.gauth.OAuth2Token
from silo.models import Silo, DataField, ValueStore
from django.contrib.auth.decorators import login_required
import json as simplejson
from django.template import RequestContext
from django.contrib.auth.models import User
from django.http import HttpResponseRedirect, HttpResponseBadRequest, HttpResponse
from django.shortcuts import render_to_response, get_object_or_404, redirect, render
@mindlace
mindlace / middleware.py
Created October 19, 2012 13:43
Add user created/modified to every model
"""Add user created_by and modified_by foreign key refs to any model automatically.
Almost entirely taken from https://github.com/Atomidata/django-audit-log/blob/master/audit_log/middleware.py"""
from django.db.models import signals
from django.utils.functional import curry
class WhodidMiddleware(object):
def process_request(self, request):
if not request.method in ('GET', 'HEAD', 'OPTIONS', 'TRACE'):
if hasattr(request, 'user') and request.user.is_authenticated():
user = request.user