Skip to content

Instantly share code, notes, and snippets.

View montylounge's full-sized avatar

Kevin montylounge

View GitHub Profile
@montylounge
montylounge / function-calling.ipynb
Created June 15, 2023 18:28 — forked from kylemcdonald/function-calling.ipynb
Example of OpenAI function calling API to extract data from LAPD newsroom articles.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@montylounge
montylounge / migrations.md
Created June 18, 2020 14:34 — forked from majackson/migrations.md
Django migrations without downtime

Django Migrations without Downtime

The following instructions describe a set of processes allowing you to run Django database migrations against a production database without having to bring the web service down.

Note that in the below instructions, migrations are all run manually at explicit points, and are not an automatic part of the deployment process.

Adding Fields or Tables

Adding a (nullable) field or a new table

  1. Make the model or column addition in your code.
@montylounge
montylounge / detect_ie.js
Created April 6, 2016 19:45 — forked from nathansmith/detect_ie.js
Function to detect Internet Explorer.
/*
Used like this...
detectIE('class-to-add-to-html-tag')
*/
function detectIE (classToAdd) {
'use strict'
from django.conf import settings
from django.core.files.storage import Storage
from django.utils import importlib
def load_class(class_string):
class_module, class_name = class_string.rsplit('.', 1)
class_module = importlib.import_module(class_module)
return getattr(class_module, class_name)
virtualenv --no-site-packages .
source bin/activate
bin/pip install Django psycopg2 django-sentry
bin/pip freeze > requirements.txt
bin/django-admin.py startproject mysite
cat >.gitignore <<EOF
bin/
include/
lib/
EOF
@montylounge
montylounge / current_page.disabled.py
Last active December 18, 2015 08:29
Cactus plugin to place current page and directory path list in context. Most applicable for setting active nav items, breadcrumbs, etc.
def preBuildPage(site, page, context, data):
"""
Cactus plugin to provide current page and directory path list to template.
Examples:
Request: /sports/team/foo.html
CURRENT_PAGE: foo.html
@montylounge
montylounge / flaskapp.py
Created June 11, 2012 01:31 — forked from kennethreitz/flaskapp.py
My typical flask app base
# -*- coding: utf-8 -*-
import os
from flask import Flask
from flask_heroku import Heroku
from flask_sslify import SSLify
from raven.contrib.flask import Sentry
from flask.ext.celery import Celery
@montylounge
montylounge / gist:1959270
Created March 2, 2012 15:50
Reusable Django Mixins from brack3t
# "Our Custom Mixins"
# http://brack3t.com/our-custom-mixins.html
class LoginRequiredMixin(object):
"""
View mixin which verifies that the user has authenticated.
NOTE:
This should be the left-most mixin of a view.
from django import template
from django.template.loaders.app_directories import load_template_source
register = template.Library()
def do_include_raw(parser, token):
"""
Performs a template include without parsing the context, just dumps the template in.
"""
bits = token.split_contents()
// Provides a device_scale class on iOS devices for scaling user
// interface elements relative to the current zoom factor.
//
// http://37signals.com/svn/posts/2407-device-scale-user-interface-elements-in-ios-mobile-safari
// Copyright (c) 2010 37signals.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell