Skip to content

Instantly share code, notes, and snippets.

View dstegelman's full-sized avatar

Derek Stegelman dstegelman

  • Colorado State University @csu-chhs
  • Northern Colorado, USA
View GitHub Profile
@dstegelman
dstegelman / AuthController.cs
Created February 17, 2018 15:28
Dot Net MVC Core with Shib
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace MyApp.Controllers
{
requirejs(['main'], function(main) {
requirejs(['jquery'], function($) {
// Jquery code goes here
});
});
@dstegelman
dstegelman / alert-dismiss.js
Created October 14, 2016 14:31
Auto dismiss bootstrap alert messages
$(document).ready(function () {
autoRemoveAlert($('.alert'));
function autoRemoveAlert(alertElement)
{
alertElement.fadeTo(2000, 800).slideUp(800, function () {
alertElement.slideUp(800);
});
}
@dstegelman
dstegelman / fixgit.sh
Created February 1, 2015 01:26
Check out all branche
#!/bin/bash
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master `; do
git branch --track ${branch#remotes/origin/} $branch
done
@dstegelman
dstegelman / Vagrantfile.ru
Created June 27, 2014 19:08
Base Vagrant File
Vagrant.configure("2") do |config|
## Choose your base box
config.vm.box = "precise64"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.synced_folder "", "/home/vagrant/test"
config.vm.network "forwarded_port", guest: 8080, host: 9090
config.ssh.forward_agent = true
[program:derek_stegelman_com]
command=/srv/www/virtualenvs/derek-stegelman-com/bin/python /srv/www/projects/derek-stegelman-com/manage.py run_gunicorn -c=/srv/www/projects/derek-stegelman-com/conf/gunicorn.conf.py --settings=settings.production
directory=/srv/www/projects/derek-stegelman-com
user=dstegelman
autostart=true
autorestart=true
redirect_stderr=True
from tastypie.serializers import Serializer
import datetime
from django.utils import feedgenerator
class RSSSerializer(Serializer):
formats = ['json', 'jsonp', 'xml', 'yaml', 'html', 'plist', 'rss']
content_types = {
'json': 'application/json',
'jsonp': 'text/javascript',
@dstegelman
dstegelman / Py Web Dev Environment.md
Last active July 4, 2017 14:55
Python Web Development Environment

This short list outlines necessary packages for Python/Django development on a factory Mac. It is assumed that you would also follow most of theese instructions for a Vagrant setup as well. In that case you can commit installing homebrew, libjpeg, etc.

Once again this is my personal preference for development, so IDEs, VCS, etc will vary.

OS Level Packages and Software

  • XCode - Make sure to open XCode -> Preferences -> Downloads -> Install Command Line Tools (xcode-select --install)
  • Homebrew
  • Install wget via homebrew
  • Install git via homebrew
@dstegelman
dstegelman / admin.py
Last active April 29, 2020 18:26
Adding Lookups to Django Generic Foreign Keys with Tabular Inlines
from itertools import chain
from django.utils.safestring import mark_safe
from django import forms
from django.contrib.contenttypes.models import ContentType
from django.forms import ModelForm
from django.contrib.admin.widgets import ForeignKeyRawIdWidget
from django.db.models.fields.related import ManyToOneRel
from django.contrib.admin.sites import site
@dstegelman
dstegelman / request_in_form.py
Created March 20, 2013 21:22
Access request object inside of a form
#Form
class MyForm(forms.Form):
def __init__(self, *args, **kwargs):
self.request = kwargs.pop('request', None)
super(MyForm, self).__init__(*args, **kwargs)
def clean(self):
#... access the request object via self.request ...