Skip to content

Instantly share code, notes, and snippets.

@rduplain
rduplain / README.md
Created October 17, 2011 20:04
Connect to MSSQL using FreeTDS / ODBC in Python.

Goal: Connect to MSSQL using FreeTDS / ODBC in Python.

Host: Ubuntu 11.10 x86_64

Install:

sudo apt-get install freetds-dev freetds-bin unixodbc-dev tdsodbc
pip install pyodbc sqlalchemy

In /etc/odbcinst.ini:

@rduplain
rduplain / app.py
Created October 24, 2011 17:02
Template helpers vs global context processing in Flask.
# Discussing Flask templating with Hazel|work on #pocoo.
# Mixing request args and view func args in a template.
# Re: http://pastebin.com/Jr8ZUb25
from flask import Flask, request, render_template
app = Flask(__name__)
@rduplain
rduplain / app.py
Created November 10, 2011 15:44
Customize Flask to select a template based on some criteria.
"Customize Flask to select a template based on some criteria."
import os
from flask import Flask, request, render_template
from flask.helpers import locked_cached_property
from jinja2 import FileSystemLoader, TemplateNotFound
# Import a detection utility from your project, not defined here.
# Takes a request object and returns True if browser is mobile.
@rduplain
rduplain / gist:1377951
Created November 18, 2011 22:16
Produce CSV of each installed package and full copyright of each package. (Debian/Ubuntu)
#!/bin/bash
# Produce CSV of each installed package and full copyright of each package. (Debian)
#
# Sample CSV:
# Package,Version,Section,Homepage,Source
# bash,4.1-2ubuntu3,shells,http://tiswww.case.edu/php/chet/bash/bashtop.html,
# git-core,1:1.7.0.4-1ubuntu0.2,vcs,,
# python,2.6.5-0ubuntu1,python,,python-defaults
AUDIT_DIR="${HOSTNAME}-package-audit/`date +'%Y-%m-%d'`"
@rduplain
rduplain / gist:1487917
Created December 16, 2011 20:50
Android: view holder without a ViewHolder class, when only one view to hold.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = activity.getLayoutInflater().inflate(layoutId, null);
convertView.setTag(convertView.findViewById(textViewId));
}
TextView textView = (TextView) convertView.getTag();
textView.setText(items.get(position).getTitle());
return convertView;
}
@rduplain
rduplain / generate_menu
Created January 1, 2012 17:24
Use MenuMaker to generate a Fluxbox menu, with a personal header stub.
#!/bin/sh
# Use MenuMaker to generate a Fluxbox menu, with a personal header stub.
# Goal: Start your fluxbox menu by hand, finish it with an auto-generated menu.
STUB=$HOME/.fluxbox/menu.stub
MENU=$HOME/.fluxbox/menu
# Add other modifiers to the pipeline as desired.
mmaker -f FluxBox -c -t Xterm | grep -v '\[begin\]' | cat $STUB - > $MENU
@rduplain
rduplain / dp2px.py
Created January 5, 2012 15:53
Convert dp dimensions to px dimensions, rewriting .xml files in place.
"Convert dp dimensions to px dimensions, rewriting .xml files in place."
# Rewrite all .xml files in res/ with:
# find res -name '*.xml' | xargs python dp2px.py
import decimal
import re
import sys
# scale = getResources().getDisplayMetrics().density; // In Activity.
@rduplain
rduplain / config.py
Created January 10, 2012 00:48
Web application config which picks values based on deployment/hostname.
"Web application config which picks values based on deployment/hostname."
# Ron DuPlain <ron.duplain@gmail.com>
# Developed by Ron DuPlain and Dan Lepage for Private Practice LLC.
#
# This listing serves as an example, extracted from a real-world config.py.
# The resulting config picks values based on hostname, which can be overriden
# by the DEPLOYMENT environment variable. Add to each .wsgi as appropriate:
#
# import os
@rduplain
rduplain / app.py
Created January 19, 2012 17:28
Plot a PNG using matplotlib in a web request, using Flask.
"Plot a PNG using matplotlib in a web request, using Flask."
# Install dependencies, preferably in a virtualenv:
#
# pip install flask matplotlib
#
# Run the development server:
#
# python app.py
#
@rduplain
rduplain / README.md
Created January 23, 2012 22:36
Fast recipe for memory monitoring.

First step toward Nagios: Fast recipe for memory monitoring.

You have a Linux box. It has RAM. You'd like to log and monitor memory usage. You have many options -- here's one: use a check_mem plugin for Nagios, but use it stand-alone at first. You'll have detailed memory logging in just a minute, and will take your first step toward full system monitoring with Nagios (later when you can formally install the plugin).

Download: https://raw.github.com/justintime/nagios-plugins/master/check_mem/check_mem.pl

Read it and make sure you feel comfortable running it. Then chmod a+x check_mem.pl and see help with ./check_mem.pl -h. In one shell, run it in a 5s loop, logging to /tmp/mem.log (Control-C to stop):