Skip to content

Instantly share code, notes, and snippets.

@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 / mongoid_money_usage.rb
Created February 23, 2011 14:46
Money represented with the Money gem, persistence using Mongoid
class Product
include Mongoid::Document
include Mongoid::Timestamps
field :description, :type => String
field :price_pence, :type => Integer, :default => 0
field :currency_iso, :type => String, :default => Money.default_currency.iso_code
validates_presence_of :description
@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 / 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 / vim_cheatsheet.md
Created April 10, 2012 09:26
My newbie Vim cheatsheet

Enter insert mode

i    insert before character under cursor
a    insert after cursor
I    insert at beginning of current line
A    insert at end of the line
o    starts insert mode in a new line below current one
O    insert in a new line above current one

Enter insert mode & replace

ciw ("change inner word") change word under cursor

@zefer
zefer / copy-s3-bucket.rb
Created April 4, 2011 11:24
Copy contents of an S3 bucket to a another bucket using an EC2 instance and a simple Ruby script. Useful for transferring large amounts of data and will work across geographic regions.
require 'rubygems'
require 'right_aws'
aws_access_key_id = 'your-access-key'
aws_secret_access_key = 'your-secret-key'
target_bucket = 'your-source-bucket'
destination_bucket = 'your-destination-bucket'
s3 = RightAws::S3Interface.new(aws_access_key_id, aws_secret_access_key)
@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 / ie8_spoofer.js
Created September 18, 2013 16:10
A bit of a bodge way to test JS fallback behaviour on old browsers like IE8, using PhantomJS.
navigator.geolocation = undefined;
window.FormData = undefined;
window.getComputedStyle = undefined;
window.matchMedia = undefined;
window.FileReader = undefined;
window.Worker = undefined;
window.WebSocket = undefined;
window.requestAnimationFrame = undefined;
window.performance = undefined;
window.EventSource = undefined;
@zefer
zefer / Skeleton Grid
Created November 2, 2011 10:03 — forked from dhg/Skeleton Grid
This is the Skeleton.gs grid example
<!-- The container is a centered 960px -->
<div class="container">
<!-- Give column value in word form (one, two..., twelve) -->
<div class="sixteen columns">
<h1>Full Width Column</h1>
</div>
<!-- Sweet nested columns cleared with a clearfix class -->
<div class="six columns clearfix">
require 'spec_helper'
describe OrdersController do
describe "GET express (/order/new/express)" do
context "with an empty basket" do
let(:current_basket) do
basket = mock(Basket, sub_total: 0.to_money)
controller.stub(:current_basket).and_return(basket)