Skip to content

Instantly share code, notes, and snippets.

@zefer
zefer / .gitconfig
Created February 22, 2011 11:20
config to use SmartSynchronize as a Git diff-viewer
[diff]
tool = smartsynchronize
[difftool "smartsynchronize"]
cmd = /Applications/SmartSynchronize.app/smartsynchronize.sh "$LOCAL" "$REMOTE"
[difftool]
prompt = false
@zefer
zefer / nginx_cors_s3_upload_proxy_full
Created February 18, 2011 13:29
My nginx config to allow CORS (cross-site) uploads to Amazon S3, with added config e.g. timeouts & security
# DO NOT RESPOND TO REQUESTS OTHER THAN yourdomain.com
server {
listen 80 default;
server_name _;
return 444;
}
# FILE UPLOADS
server {
listen 80;
@zefer
zefer / ajax_html5_file_upload.js
Created February 16, 2011 12:58
A working html5 AJAX uploader example, with progress logging
/**
* Define a namespace
*/
var your_namespace = your_namespace || {};
/**
* logging
* usage: log('inside coolFunc',this,arguments);
* http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
*/
@zefer
zefer / nginx_cors_s3_upload_proxy
Created February 16, 2011 12:37
Simple nginx config to allow CORS (cross-site) uploads to Amazon S3
location / {
if ($request_method = 'OPTIONS') {
more_set_headers 'Access-Control-Allow-Origin: *';
more_set_headers 'Access-Control-Allow-Methods: POST, OPTIONS';
more_set_headers 'Access-Control-Max-Age: 1728000';
more_set_headers 'Content-Type: text/plain; charset=UTF-8';
return 200;
}
@zefer
zefer / Install_nginx_from_src_with_module.sh
Created February 16, 2011 12:26
Compile nginx from source, include the Headers More module - Ubuntu
sudo su -
# stuff we need to build from source
apt-get install libpcre3-dev build-essential libssl-dev
# get the nginx source
cd /opt/
wget http://nginx.org/download/nginx-0.8.54.tar.gz
tar -zxvf nginx*
# we'll put the source for nginx modules in here
@zefer
zefer / get_currently_playing_via_lastfm.sh
Created January 26, 2011 15:12
queries last.fm and returns the currently playing song
#!/bin/bash
LASTFMUSER=${1:-"default_user_name"}
echo $LASTFMUSER ...
curl -s http://www.last.fm/user/$LASTFMUSER | grep -A 1 subjectCell | sed -e 's#<[^>]*>##g' | head -n2 | tail -n1 | sed 's/^[[:space:]]*//g' | cowsay
@zefer
zefer / ConsumerDAO.cfc
Created December 17, 2010 15:05
An example DAO using cfmongodb. The model object is an API consumer.
<cfcomponent extends="beans.model.AbstractServiceObject" output="false" hint="">
<cffunction name="init" access="public" output="false" returntype="beans.model.ConsumerDAO">
<cfscript>
// something random to append to passwords to prevent reverse md5 lookups
variables.salt = "_8sh3m9cc"
super.init( argumentcollection: arguments );
@zefer
zefer / TimeSpanNativeCfmlCache.cfc
Created November 1, 2010 18:09
some minor fixes
<!---
Mach-II - A framework for object oriented MVC web applications in CFML
Copyright (C) 2003-2010 GreatBizTools, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
<cfhttpparam type="Header" name="TE" value="deflate;q=0">
<cffunction name="allowCrossDomainAccess" returnType="void" access="public">
<cfset var stHeaders = getHttpRequestData().headers />
<cfif structKeyExists( stHeaders, "Origin" ) and cgi.request_method eq "OPTIONS">
<!---
Preflighted requests:
1. browser tells us it wants to make a non-basic x-domain request. Non-basic could mean it is a PUT, or contains custom headers, or a different content-type
2. based on what the browser tells us it wants to do, we respond and tell it what x-domain requests we allow