Skip to content

Instantly share code, notes, and snippets.

@tvpmb
tvpmb / ad-hoc-library-load.js
Created June 18, 2012 17:02
Load External Libraries, via a simple AJAX call
(function() {
device.ajax(
{
url: 'http://underscorejs.org/underscore-min.js',
type: 'GET',
headers: {
'Content-Type': 'text/javascript'
}
},
function onSuccess(body, textStatus, response) {
@tvpmb
tvpmb / h-jst.js
Created June 22, 2012 15:55
handlebars-jst-fetch
/*
fetch: function(path) {
path = path + ".html";
path = path.slice(1);
window.JST = window.JST || {};
if (JST[path]) {
return Handlebars.template(JST[path]);
}
@tvpmb
tvpmb / jquery-unit.conf
Created June 28, 2012 21:11 — forked from tbranyen/jquery-unit.conf
nginx configuration for running jquery unit tests
#
# jQuery Unit Test Configuration File.
# Copyright 2012, Tim Branyen (@tbranyen)
# This configuration file may be freely distributed under the MIT license.
#
# Include this file (named jquery.conf) alongside the jquery folder and run
# with root privileges:
#
# sudo nginx -c /absolute/path/to/jquery.conf
#
@tvpmb
tvpmb / page.html
Created August 29, 2012 21:12
Simple Backbone Template
<div id="search_container"></div>
<script type="text/javascript">
SearchView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
// Compile the template using underscore
var template = _.template( $("#search_template").html(), {} );
@tvpmb
tvpmb / uri.js
Created September 5, 2012 23:36 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@tvpmb
tvpmb / native.js
Created September 5, 2012 23:41
Awesome Javascript URL Parsing
parser.href = url;
var hostname2 = parser.hostname;
var search2 = parser.search;
/*
Notes:
- extremely slow
*/
@tvpmb
tvpmb / original.js
Created September 13, 2012 01:31 — forked from rmurphey/original.js
DRYing out code using a function
function updateDates() {
var startDate = $("#start-date").datepicker("getDate");
$("#menu-item-1 .day").text(startDate.getDate());
$("#menu-item-1 .month").text(Util.monthToText(startDate.getMonth()));
$("#menu-item-1 .year").text(startDate.getFullYear());
var endDate = $("#end-date").datepicker("getDate");
$("#menu-item-2 .day").text(endDate.getDate());
@tvpmb
tvpmb / gist:3723738
Created September 14, 2012 18:25 — forked from ebidel/gist:3723309
Spotlight bookmarklet
// Save this in a bookmarklet and click it on a page:
javascript:(function(){function d(a,c){document.body.style.webkitClipPath="circle("+a+"px, "+c+"px, "+b+"px)"}var b=90;window.addEventListener("mousemove",function(a){d(a.pageX,a.pageY)});window.addEventListener("mousewheel",function(a){if(a.shiftKey){a.preventDefault();var c=a.wheelDeltaY;b+=-c;b=0<c?Math.max(90,b):Math.min(b,window.innerHeight/2);d(a.pageX,a.pageY)}})})();
// Or paste this in the console and mouse over the page.
// SHIFT+mousewheel scroll makes the circle bigger/smaller.
(function() {
var radius = 90; // px
@tvpmb
tvpmb / gist:3789404
Created September 26, 2012 17:38
Google Analytics for RequireJS Build Process (GruntJS)
requirejs: {
// Include the main configuration file.
mainConfigFile: "app/config.js",
// Output file.
out: "dist/debug/require.js",
// Root application module.
name: "config",
@tvpmb
tvpmb / nginx_cors_s3_upload_proxy_full
Created October 4, 2012 23:39 — forked from zefer/nginx_cors_s3_upload_proxy_full
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;