Skip to content

Instantly share code, notes, and snippets.

Jeff Schroeder SEJeff

Block or report user

Report or block SEJeff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@SEJeff
SEJeff / gist:2999174
Created Jun 26, 2012
Sending eth0's ip as a variable to a salt template file
View gist:2999174
/var/www/myip.html:
file.managed:
- source: salt://roles/wordpress/files/myip.html.jinja
- user: root
- group: root
- mode: 640
- template: jinja
- context:
hostname: {{ grains['fqdn'] }}
ip: {{ salt['network.interfaces']()['eth0']['ipaddr'] }}
@SEJeff
SEJeff / gist:7310830
Last active Jan 16, 2020
Apache config to load balance across a cluster of elasticsearch instances on 2 different servers, "es-cluster-1", and "es-cluster-2".
View gist:7310830
<VirtualHost *:80>
ServerName balancer.local
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Location /balancer-manager>
ProxyPass !
SetHandler balancer-manager
#Require host example.com
Require host localhost
</Location>
View config.sls
{% macro postconf(key, value) -%}
postconf-{{ key }}:
cmd:
- run
- name:
- postconf -e {{ key }}='{{ value }}'
- unless: test "x$(postconf -h {{ key }} )" = 'x{{ value }}'
- require:
- pkg: postfix
@SEJeff
SEJeff / gist:4207694
Created Dec 4, 2012
Testing jinja from the python interactive shell
View gist:4207694
>>> from jinja2 import Template
>>> tmpl = """{% if name != "Jeff" %}Nothing to see here move along{% else %}
... hello {{name}}, how are you?{% endif %}"""
>>> template = Template(tmpl)
>>> print template.render({"name": "Jeff"})
hello Jeff, how are you?
>>> print template.render({"name": "John"})
Nothing to see here move along
>>>
@SEJeff
SEJeff / print_imports.py
Last active Apr 11, 2019
Print every python import for debugging import issues
View print_imports.py
# Courtesy of https://github.com/wimglenn
import sys
try:
import builtins
except ImportError:
# py2
import __builtin__ as builtins
@SEJeff
SEJeff / README.md
Last active Mar 21, 2019
Python learnings
View README.md
  1. Learn Python the Hard Way - Great introductory course to python and programming
  2. The Python Guide - After you have a cursory idea of python, this is great
  3. Code Like a Pythonista: Idiomatic Python - For learning the "pythonic" way of doing things
  4. Tango with Django - Great intro to building python web applications
  5. Intro to Flask, TDD, and jQuery
  6. Selenium's Page Object Pattern for testing websites
  7. The Python Yield Keyword Explained - Good precursor to the generator tricks
  8. Incredible guide on Python's __ (underscore) methods - Must read for anyo
@SEJeff
SEJeff / debug_middleware.py
Created Apr 8, 2011
Django debug middleware for displaying extra information when the request includes the "debug" query string.
View debug_middleware.py
# Originally based on: http://djangosnippets.org/snippets/1872/
# Requires sqlparse: http://pypi.python.org/pypi/sqlparse
import time
from django.test.signals import template_rendered
from django.conf import settings
from django.db import connection
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
TEMPLATE = """
@SEJeff
SEJeff / settings_ldap.py
Created Jul 8, 2011
Example django_auth_ldap configuration
View settings_ldap.py
############################## django-auth-ldap ##############################
import ldap
from django_auth_ldap.config import LDAPSearch, PosixGroupType
# django-auth-ldap configuration starts here
AUTH_LDAP_SERVER_URI = "ldap://ldap.els03.loc ldap://ldap.zbw03.loc ldap://ldap.cvg03.loc"
#AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=People,o=loc"
# JW is in ou=Admin,o=loc so we search over o=loc to find him
AUTH_LDAP_USER_SEARCH = LDAPSearch("o=loc",
@SEJeff
SEJeff / which.py
Created May 2, 2012
Implementation of Unix's which command in python
View which.py
def which(exe=None):
'''
Python clone of POSIX's /usr/bin/which
'''
if exe:
(path, name) = os.path.split(exe)
if os.access(exe, os.X_OK):
return exe
for path in os.environ.get('PATH').split(os.pathsep):
full_path = os.path.join(path, exe)
You can’t perform that action at this time.