Skip to content

Instantly share code, notes, and snippets.

View mhayes's full-sized avatar

Mark Hayes mhayes

View GitHub Profile
@mhayes
mhayes / geocode-autocomplete.js
Created December 14, 2010 17:16
uses Google Maps API for jQuery autocomplete
$(function(){
var geocoder = new google.maps.Geocoder();
/* use Google Geocoder in jQueryUI autocomplete widget */
$("#search").autocomplete({
minLength:8,
source:function(request,response) {
geocoder.geocode({address:request.term}, function(result,status){
var addresses = jQuery.map(result, function(address){ return address.formatted_address; });
@mhayes
mhayes / qr.cfc
Created December 16, 2010 18:31
Creates image tag that contains QR Code
component output="no" name="qr" {
function encode(required string message) {
var url = "http://chart.apis.google.com/chart";
url &= "?cht=qr&chs=200x200";
url &= "&chl=#message#";
return image_tag(url,200,200,message);
}
function image_tag(url,w,h,alt) {
@mhayes
mhayes / common_table_expression.sql
Created December 21, 2010 19:10
Common table expression usage in SQL Server
USE AdventureWorks2008;
WITH ShippingTime(OrderDate,ShipDate,DaysToShip) AS
(
SELECT OrderDate, ShipDate,DATEDIFF(day,OrderDate,ShipDate)
FROM Sales.SalesOrderHeader
)
SELECT *
FROM ShippingTime;
@mhayes
mhayes / dsn-listing.cfm
Created January 3, 2011 15:47
List DSN's that exist on a particular server
<h2>Server: <cfoutput>#CGI.SERVER_NAME#</cfoutput></h2>
<p>
The following ColdFusion DSN's are available on this server:
</p>
<cfscript>
// Instantiate CF Admin API
adminObj = createObject("component","cfide.adminapi.administrator");
@mhayes
mhayes / 960.html
Created January 3, 2011 22:40
Simple grid layout using 960.gs
<!DOCTYPE html>
<html>
<head>
<link href="grid.css" type="text/css" rel="stylesheet" />
<style type="text/css">
p {border:1px solid black;}
.container_12 {background:#ddd; }
body{background:#ccc; }
</style>
</head>
@mhayes
mhayes / puzzle.py
Created January 28, 2011 02:58
Python translation capabilities
"""
Decode a super-secret message
"""
import sys
from string import maketrans
# setup translation
in_wrds = "abcdefghijklmnopqrstuvwxyz"
out_wrds = "cdefghijklmnopqrstuvwxyzab"
trans_tbl = maketrans(in_wrds, out_wrds)
@mhayes
mhayes / mess.py
Created January 28, 2011 03:01
Locates alpha characters in a text file
# solution 1 - nested loops
temp = ""
f = open('mess.txt', 'r')
for l in f:
for c in l:
if c.isalpha():
temp += c
print temp
# solution 2 - list comprehension
@mhayes
mhayes / tag_filter.py
Created February 14, 2011 18:07
Finding a set of tags meeting certain criteria
import re
import gdata.photos.service
user = 'intakescreensinc'
service = gdata.photos.service.PhotosService()
tags = service.GetUserFeed(user=user, kind='tag').entry
cfs = re.compile("^(\d+)cfs$")
cfs_sizes = []
for tag in tags:
@mhayes
mhayes / photo.py
Created February 14, 2011 20:35
Retrieve photos from Picasa
import re
import gdata.photos.service
class Collection:
def __init__(self, username):
self.feed = "/data/feed/api/user/%s" % username
self.service = gdata.photos.service.PhotosService()
def fetch(self, feed):
"""Make a call to the photo service."""
return self.service.GetFeed(feed)
@mhayes
mhayes / supervisord.sh
Created March 12, 2011 01:13 — forked from danmackinlay/supervisord.sh
init.d for supervisord for Amazon Linux AMI
#!/bin/sh
# Amazon Linux AMI startup script for a supervisor instance
#
# chkconfig: 2345 80 20
# description: Autostarts supervisord.
# Source function library.
. /etc/rc.d/init.d/functions
supervisorctl="/usr/bin/supervisorctl"