Skip to content

Instantly share code, notes, and snippets.

View jcockhren's full-sized avatar
👨‍🍳
Cooking up something 🔥

Jurnell Cockhren jcockhren

👨‍🍳
Cooking up something 🔥
View GitHub Profile
@jcockhren
jcockhren / gist:ee10e6c66d7eb8f410f5
Created August 13, 2015 14:06
Port Forwarding for st2 (vagrant)
config.vm.network :forwarded_port, guest: 8080, host: 8080
config.vm.network :forwarded_port, guest: 9100, host: 9100
config.vm.network :forwarded_port, guest: 9101, host: 9101
https://github.com/junit-team/junit/wiki/Assertions
Download version 4.12 -> http://search.maven.org/#search|gav|1|g:"junit" AND a:"junit"
http://www.vogella.com/tutorials/JUnit/article.html
run_the_cmd:
module.run:
- name: cmd.run
- cmd: 'command you want to run'

Coming from puppet I really got used to the hierarchical data structure hiera provides. It's easy to use, yet pretty powerful when used in combination with the module_data puppet module, which allows you to put your hiera-data in the module directory itself, while still being able to globally override stuff from the main hiera source.

The approach I present here allows you to do something similar with salt and it's pillar data by using Jinja2 only. No additional modules whatsoever are required for this to work.

Configuration data is being split up into four levels:

  • state defaults
  • filtered state defaults
  • pillar data
  • filtered pillar data
from django.core.cache import cache
from django.http import HttpResponseForbidden
from functools import wraps
from django.utils.decorators import available_attrs
def ratelimit(limit=10,length=86400):
""" The length is in seconds and defaults to a day"""
def decorator(func):
def inner(request, *args, **kwargs):
ip_hash = str(hash(request.META['REMOTE_ADDR']))
http://pcottle.github.io/learnGitBranching/
http://rogerdudler.github.io/git-guide/
http://think-like-a-git.net/
http://gitimmersion.com/
http://gitref.org/
http://git-scm.com/documentation
@jcockhren
jcockhren / gist:9515467
Created March 12, 2014 20:21
error when creating virtualenv inside Iron Worker
Traceback (most recent call last):
File "/mnt/task/__pips__/__bin__/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2815, in <module>
working_set.require(__requires__)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 690, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 588, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: virtualenv==1.11.4
@jcockhren
jcockhren / views.py
Created February 2, 2014 19:47
Shouldn't this pull the most recent version of the user data on get? see https://gist.github.com/jcockhren/8762001 for supporting code.
class SettingsView(UpdateView):
model = CustomUser
form_class = UserForm
#form = UserForm(self.instance)
template_name = 'account/settings.html'
success_url = '/account/settings'
fields = ['first_name',
'last_name',
'email',
@jcockhren
jcockhren / forms.py
Created February 2, 2014 02:05
Currently, on successful POST, the form isn't propulated with the newer values.
from django import forms
from django.core.exceptions import ValidationError
from apps.content.models import Profile
from apps.content.models import CustomUser
class UserForm(forms.ModelForm):
class Meta:
model = CustomUser
@jcockhren
jcockhren / checks.py
Last active August 29, 2015 13:55
Example of an IronWorker that talks to couchDB
from couchdbkit import *
from models import Check
import requests
import datetime
# We need to preload the memory with a list of sites to check.
server = Server('somecouchserverhere')
sitedb = server.get_db('yourdbname')
sites_view = sitedb.view('someview', key="Site")