Skip to content

Instantly share code, notes, and snippets.

View westonwatson's full-sized avatar

Weston Watson westonwatson

View GitHub Profile
@westonwatson
westonwatson / simbox.html
Created October 19, 2012 04:40
Simple LightBox jQuery Plugin
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SIMBOX EXAMPLE</title>
<style>
.black_overlay{
display: none;
position: absolute;
top: 0%;
left: 0%;
@westonwatson
westonwatson / auto-title-tooltip.js
Created October 23, 2012 19:34
Possible update for auto-title-tooltip
var autoTitleTooltip = function(){
var elementType = 'div';
var customClass = '';
domIdFromString = function(myStr){
myStr+=Math.random();
myStr=myStr.toLowerCase();
myStr=myStr.replace(/ /g,"");
myStr=myStr.replace(/[^a-zA-Z0-9]+/g,"");
@westonwatson
westonwatson / datafill.js
Last active October 12, 2015 07:28
datafill, simple templating system
/* major redo! now it works! and works well... */
function pushValue(domId, newValue){
if (jQuery){
jQuery("#" + domId).html(newValue);
}else{
document.getElementById(domId).innerHTML = newValue;
}
}
@westonwatson
westonwatson / gist:4154746
Created November 27, 2012 15:15
Replace BB Style Tags using Data from Objects and Arrays
static function replace_tags($full_text,$data_objects_array){
//using key => value pairs replace tag_names with object_sttributes
/* Example Object
*
* $object["user"] = $user;
* $object["dealer"] = $dealership;
* $awesome_text = replace_tags($tagged_text,$object);
*/
var page = require('webpage').create(),
address, output, size, timeOut, loops, cnt;
if (phantom.args.length < 2 || phantom.args.length > 6) {
console.log('Usage: westerize.js URL filename [timeout] [repeat] [width] [height]');
console.log(' timeout: miliSeconds');
console.log(' repeat: how many images to take');
console.log(' width/height: defaults to 1024x768');
phantom.exit();
} else {
@westonwatson
westonwatson / echo_server.js
Created January 29, 2013 20:35
node webSocket backend example
var sys = require('sys'),
http = require('http'),
io = require('socket.io'), // for npm, otherwise use require('./path/to/socket.io')
fs = require('fs');
var pageContent = ''; // content of the client page
// create web server and reply the client page on http request
var server = http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/html'});
@westonwatson
westonwatson / pure-linkify.js
Created February 1, 2013 13:29
# Pure Javascript Linkify Solution ======================== > pure-linkify.js
function linkify(textBlock){
return textBlock.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/(^|&lt;|\s)(www\..+?\..+?)(\s|&gt;|$)/g, '$1<a href="http://$2">$2</a>$3')
.replace(/(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g, '$1<a href="$2">$2</a>$5');
}
@westonwatson
westonwatson / fullpagefixedgb.css
Created February 8, 2013 01:15
Full Page Fixed Background Image CSS
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
@westonwatson
westonwatson / object-count.js
Created February 15, 2013 22:05
Add a 'count' method to Objects in Javascript.
Object.prototype.count = function () {var count = 0; for(var prop in this) { if(this.hasOwnProperty(prop)) count = count + 1;}return count;}
// Turn a (possibly) relative URI into a full RFC 3986-compliant URI
// With minor modifications, courtesy: https://gist.github.com/Yaffle/1088850
function absoluteUri(base, href) {
// Parse a URI and return its constituent parts
function parseUri(url) {
var match = String(url).replace(/^\s+|\s+$/g, '').match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
return (match ? { href: match[0] || '', protocol: match[1] || '', authority: match[2] || '', host: match[3] || '', hostname: match[4] || '',
port: match[5] || '', pathname: match[6] || '', search: match[7] || '', hash: match[8] || '' } : null);
}