Skip to content

Instantly share code, notes, and snippets.

View jathanism's full-sized avatar
🍕
See below.

Jathan McCollum jathanism

🍕
See below.
View GitHub Profile
@bdarnell
bdarnell / django_tornado_handler.py
Created October 29, 2010 18:59
django_tornado_handler.py
# NOTE: This code was extracted from a larger class and has not been
# tested in this form. Caveat emptor.
import django.conf
import django.contrib.auth
import django.core.handlers.wsgi
import django.db
import django.utils.importlib
import httplib
import json
import logging
@esperlu
esperlu / mysql2sqlite.sh
Created April 27, 2011 05:46
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@ghoseb
ghoseb / gevent_example.py
Created July 27, 2011 09:27
Gevent spawn / link example
from gevent import monkey; monkey.patch_all()
import gevent
import gevent.greenlet
from functools import partial
from random import random
import urllib
import urllib2
def on_exception(fun, greenlet):
@tkersey
tkersey / gist:1130675
Created August 7, 2011 19:16
Getting a Motorola SBG6580 into “Bridge” mode

found at: http://fascinated.fm/post/2379188731/getting-a-motorola-sbg6580-into-bridge-mode-on

Getting a Motorola SBG6580 into “Bridge” mode on TimeWarner Wideband

  1. Unplug coax cable from Motorola
  2. Hold down the white reset button on the back panel with a pen for 30s.  This resets all settings to factory defaults. The modem will be auto-reconfigured once you plug in the coax cable.
  3. When modem is back on plug in a computer with an Ethernet cable into the modem.
  4. Connect to http://192.168.0.1 and login with “admin” / “motorola”
  5. Now you will make some changes:
 
  • Wireless -> Primary Network -> Disabled
@pmclanahan
pmclanahan / hostname_middleware.py
Created August 30, 2011 04:06 — forked from robballou/hostname_middleware.py
Django middleware for enforcing a hostname. Using at epio until they provide options for redirects at the loadbalancers.
from django.conf import settings
from django.http import HttpResponsePermanentRedirect
class EnforceHostnameMiddleware(object):
"""
Enforce the hostname per the ENFORCE_HOSTNAME setting in the project's settings
The ENFORCE_HOSTNAME can either be a single host or a list of acceptable hosts
"""
def process_request(self, request):
@rmax
rmax / merge_dicts.py
Created September 21, 2011 21:05
using itertools's chain and groupby to merge a list of dictionaries
def merge_dicts(dict_list):
"""Merge all values from dict list into a single dict
>>> d1 = {'a': 1, 'b': 2}
>>> d2 = {'a': 2, 'b': 3}
>>> merge_dicts([d1, d2])
{'a': [1, 2], 'b': [2, 3]}
"""
kviter = chain.from_iterable(d.iteritems() for d in dict_list)
@readevalprint
readevalprint / diff.py
Created September 23, 2011 04:48
Django instance Diff - Now it's the bestestest.
#!/usr/bin/env python
# By Tim Watts
# From http://readevalprint.com/blog/more-better-django-changed-instance-diff.html
# Updated on 9/22/2011 - Added Many2Many to supported fields
# Updated on 9/23/2011 - Fixed Many2Many fields
class Missing:
pass
@grugq
grugq / sshclient.py
Created December 6, 2011 02:58
twisted ssh client (based on conch.py) with an embedded cmd.Cmd shell for controllng the SSH session
from twisted.internet import reactor, defer, endpoints, task, stdio
from twisted.conch.client import default, options, direct
from twisted.conch.error import ConchError
from twisted.conch.ssh import session, forwarding, channel
from twisted.conch.ssh import connection, common
from twisted.python import log, usage
import signal
import tty
import struct
import fcntl
@moklett
moklett / openconnect.md
Created July 24, 2012 15:21
OpenConnect VPN on Mac OS X

Unfortunately, the Cisco AnyConnect client for Mac conflicts with Pow. And by "conflicts", I mean it causes a grey-screen-of-death kernel panic anytime you connect to the VPN and Pow is installed.

As an alternative, there is OpenConnect, a command-line client for Cisco's AnyConnect SSL VPN.

Here's how to get it set up on Mac OS X:

  1. OpenConnect can be installed via homebrew:

     brew update
    

brew install openconnect

@jathanism
jathanism / paramiko_statemachine.py
Last active October 10, 2015 08:28
Simple state machine to pipeline commands over an SSH channel using Paramiko and select
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This is a prototype of a simple state machine that remotely executes a list of
commands via SSH on network devices (expecting the prompt_pattern to match) and
returns the results to you.
"""
__author__ = 'Jathan McCollum'