Skip to content

Instantly share code, notes, and snippets.

View artschwagerb's full-sized avatar

Brian Artschwager artschwagerb

View GitHub Profile
@artschwagerb
artschwagerb / jpeg_bmp.py
Created May 17, 2015 00:54
Convert JPEG to BMP
import os
from PIL import Image
size = 145, 145
dir_path = '/Users/brian/Desktop/systems'
for filename in os.listdir(dir_path):
if filename.endswith('.bmp'):
# Destroy Previously Converted BMP
try:
os.remove(os.path.join(dir_path,filename.replace('.jpg','.bmp')))
except:
@artschwagerb
artschwagerb / gist:7636463a718339b67768
Created July 15, 2015 18:00
Check AD Username/Password
$cred = Get-Credential #Read credentials
$username = $cred.username
$password = $cred.GetNetworkCredential().password
# Get current domain using logged-on user's credentials
$CurrentDomain = "LDAP://hillsborough.k12.nj.us"
$domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password)
if ($domain.name -eq $null)
{
### USAGE
###
### ./ElasticSearch.sh 1.5.0 will install Elasticsearch 1.5.0
### ./ElasticSearch.sh 1.4.4 will install Elasticsearch 1.4.4
### ./ElasticSearch.sh will fail because no version was specified (exit code 1)
###
### CLI options Contributed by @janpieper
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch
### ElasticSearch version
@artschwagerb
artschwagerb / osx_developer_installation.rst
Last active August 29, 2015 14:27 — forked from stefanfoulis/osx_developer_installation.rst
Instructions on how to setup an OSX developer machine for (python/django) development

OSX Developer System installation

This guide assumes a fresh install of Mac OSX 10.7 Lion.

Brew User

@artschwagerb
artschwagerb / routers.py
Created November 14, 2013 18:38
Django Database Router
import random
class MasterSlaveRouter(object):
def db_for_read(self, model, **hints):
"""
Reads go to a randomly-chosen slave.
"""
return random.choice(['master','slave1', 'slave2'])
def db_for_write(self, model, **hints):
@artschwagerb
artschwagerb / settings.py
Created November 14, 2013 18:43
Database Routers (settings.py)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'anotherdatabase',
'USER': 'anotherusername',
'PASSWORD': 'anotherpassword',
'HOST': '192.168.1.1',
'PORT': '',
},
'master': {
@artschwagerb
artschwagerb / mailbox.py
Last active December 29, 2015 02:49 — forked from cgoldberg/mailbox.py
#!/usr/bin/env python
"""MailBox class for processing IMAP email.
(To use with Gmail: enable IMAP access in your Google account settings)
usage with GMail:
import mailbox
@artschwagerb
artschwagerb / models.py
Last active December 29, 2015 20:39
Django Signals
from django.db import models
from django.contrib.auth.models import User
class Person(models.Model):
employee_id = models.IntegerField(unique=True,editable=False)
username = models.CharField(max_length=50,unique=True,editable=False)
state_id = models.IntegerField(unique=True,null=True,blank=True,editable=False)
email = models.EmailField(max_length=50,unique=True,editable=False)
firstname = models.CharField(max_length=50,editable=False)
lastname = models.CharField(max_length=50,editable=False)
@artschwagerb
artschwagerb / models.py
Created December 12, 2013 15:40
Django __unicode__ method
def __unicode__(self):
if self.name:
return u'%s' % (self.name)
elif self.assettag:
return u'%s' % (self.assettag)
elif self.mac_wired:
return u'%s' % (self.mac_wired)
elif self.model.chassis:
return u'%s' % (self.model.chassis)
else:
@artschwagerb
artschwagerb / deploy_django.yml
Created January 11, 2016 20:15
Deploy Django App using Ansible
---
- hosts: django_app_servers
serial: 1
remote_user: admin
sudo: yes
tasks:
- name: Send Maintenance Mode Command to HaProxy
shell: curl --data "s={{inventory_hostname}}&b=#12&action=drain" http://user:password@haproxy1.local:8080/haproxy?stats