Skip to content

Instantly share code, notes, and snippets.

@keithshep
keithshep / gist:522948
Last active September 5, 2015 17:04
DB/apache httpd cheats
How to configure httpd to forward requests (tested on SuSE):
============================================================
* create /etc/apache2/proxies.conf
* change APACHE_CONF_INCLUDE_FILES="" to
APACHE_CONF_INCLUDE_FILES="/etc/apache2/proxies.conf" in
/etc/sysconfig/apache2
* add "proxy proxy_http" to the APACHE_MODULES list in
/etc/sysconfig/apache2
And the proxies.conf file might look like:
#!/usr/bin/env python -O
import argparse
import sys
import numpy
import h5py
import csv
class ColType:
UNKNOWN = 1
@keithshep
keithshep / python-cheats.md
Last active October 13, 2020 16:53
python cheats

Angle between two vectors

Note that this doesn't give you the direction the angle sweeps in

def angle_deg_between_vecs(vec1, vec2):
    """
    Computes an angle in degrees between two vectors
    :param vec1: the first vector (numpy array of length n >= 2)
    :param vec2: the second vector (numpy array of length n >= 2)

:return: the angle in radians

@keithshep
keithshep / hellowsgi.py
Created March 20, 2013 16:43
a minimal "hello world" wsgi application
from cgi import parse_qs, escape
def application(environ, start_response):
parameters = parse_qs(environ.get('QUERY_STRING', ''))
if 'subject' in parameters:
subject = escape(parameters['subject'][0])
else:
subject = 'World'
start_response('200 OK', [('Content-Type', 'text/html')])
return ['Hello %(subject)s' % {'subject': subject}]
import requests
import json
# a helper function that returns the error message in case there is one and
# None otherwise
def get_err_msg(x):
if 'errorMessage' in x:
return x['errorMessage']
else:
return None
@keithshep
keithshep / querybiomartexample.py
Created December 3, 2013 20:05
A small example for how to create XML queries for biomart using python
import requests
def main():
exampleTaxonomy = "mmusculus_gene_ensembl"
exampleGene = "ENSMUSG00000086981"
urlTemplate = \
'''http://ensembl.org/biomart/martservice?query=''' \
'''<?xml version="1.0" encoding="UTF-8"?>''' \
'''<!DOCTYPE Query>''' \
@keithshep
keithshep / tristate.js
Last active August 29, 2015 14:03
A little javascript class to help out with tri-state checkboxes.
/**
* A little "class" to help out with tri state checkboxes.
*/
function TriStateCheckbox(checkbox) {
var self = this;
var checkedVal = checkbox.prop("checked");
var indeterminatePropName = "indeterminate";
/**
@keithshep
keithshep / cppcheats.cpp
Created September 27, 2014 03:16
c++ cheats
// creating a priority queue with a lambda less operator
auto pt_less = [&mat](const cv::Point& pt1, const cv::Point& pt2) -> bool {
return mat.at<uint8_t>(pt1) < mat.at<uint8_t>(pt2);
};
priority_queue<cv::Point, vector<cv::Point>, decltype(pt_less)> erosion_candidates(pt_less);
@keithshep
keithshep / csv_to_hdf5.py
Created November 5, 2014 17:33
convert CSV file to HDF5 using h5py
#!/usr/bin/env python -O
import argparse
import sys
import numpy
import h5py
import csv
class ColType:
UNKNOWN = 1
@keithshep
keithshep / filedropify.js
Last active August 29, 2015 14:15
some code to simplify file drag-and-drop implementation in JavaScript
/**
* This callback will be called with the file that was dropped.
* @callback dropCallback
* @param file the file object
*/
/**
* Create a file drop area
* @param activeElement
* the element that the user can drop on to trigger a callback
* @param highlightElement