Skip to content

Instantly share code, notes, and snippets.

@jrosebr1
jrosebr1 / paths.py
Last active March 5, 2019 19:50
Image path generator for Python
# Author: Adrian Rosebrock
# Website: www.pyimagesearch.com
# import the necessary packages
import os
def list_images(basePath, contains=None):
# return the set of files that are valid
return list_files(basePath, validExts=(".jpg", ".jpeg", ".png"), contains=contains)
@jrosebr1
jrosebr1 / gist:2415182
Created April 18, 2012 17:19
This XML schema file is used to describe pills.
<?xml version="1.0" encoding="utf-8"?>
<!--
@brief
This XML schema file is used to describe pills.
@author Adrian Rosebrock
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.shiftybits.com">
<!-- define the 'pills' element -->
@jrosebr1
jrosebr1 / validators.py
Created March 20, 2012 20:04 — forked from dokterbob/validators.py
Validator for files, checking the size, extension and mimetype for Django.
# @brief
# Performs file upload validation for django. The original version implemented
# by dokterbob had some problems with determining the correct mimetype and
# determining the size of the file uploaded (at least within my Django application
# that is).
# @author dokterbob
# @author jrosebr1
import mimetypes
@jrosebr1
jrosebr1 / jqtouch_history.js
Created January 13, 2012 16:22
Using jQTouch to Remember the Last Visited Page.
// initialize the jQTouch variable and the current hash, then grab
// the app history from local storage
var jQT = null;
var currentHash = null;
var hist = localStorage.getItem("app_history");
// if the history is null, then reset the history list to include
// just 'home'
if (hist == null){
hist = ["home"];
@jrosebr1
jrosebr1 / hac_cluster.py
Created September 19, 2011 13:59
Methods to perform hierarchical agglomerative clustering using SciPy and parse the clusters.
def cluster(self):
# ... #
# cluster the codes together using hierarchical agglomerative
# clustering and then parse the returned clusters
self.clusters = hierarchy.linkage(clusterCodes, "single", "euclidean")
self.clusters = self.parseClusters(self.clusters, numClusters)
# ... #
@jrosebr1
jrosebr1 / time_difference.php
Created September 3, 2011 20:46
TimeDifference class used to display a date/time in human readable format (Facebook and Twitter style).
<?php
/**
* @brief
* Class used to calculate the human readable time from a supplied
* date.
*
* This class is used to calculate the human readable time from a
* supplied date such as on Facebook and Twitter. A returned value
* from this class would look like '4 minutes, 58 seconds ago' or