Skip to content

Instantly share code, notes, and snippets.

View dandean's full-sized avatar
🌧️
It's raining.

Dan Dean dandean

🌧️
It's raining.
View GitHub Profile
@dandean
dandean / JSON-P for Prototype.js
Created July 14, 2009 20:24
JSONP for PrototypeJS
// See an updated version of this in it's own git repo:
// http://github.com/dandean/Ajax.JSONRequest
/* JSON-P implementation for Prototype.js somewhat by Dan Dean (http://www.dandean.com)
*
* *HEAVILY* based on Tobie Langel's version: http://gist.github.com/145466.
* Might as well just call this an iteration.
*
* This version introduces:
* - onCreate and onFailure callback options.
@dandean
dandean / gist:160728
Created August 3, 2009 18:11
RuntimeIframe Class (or Ajax.IFrame, or something... ) for dynamically loading iframes...
/**
* class RuntimeIframe (or Ajax.IFrame, or something... )
**/
var RuntimeIframe = Class.create({
/**
* new RuntimeIframe(options);
* - options (Object): Configuration options; currently limited to `width` and `height`
*
* Creates a new `RuntimeIframe`.
**/
@dandean
dandean / gist:162507
Created August 5, 2009 04:54
Number.prototype.isBetween implementation...
/**
* Number#between(low, high[, inclusive = false]) -> boolean
* - low(Number): Number must be greater than `low` value
* - high(Number): Number must be less than `high` value
* - inclusive(Boolean): [Optional] Include low and high numbers in the check.
* Defaults to `false`.
*
* Checks if the Number is between `low` and `high` values. Returns `true` or `false`
**/
Number.prototype.isBetween = function(low, high, inclusive) {
@dandean
dandean / gist:162509
Created August 5, 2009 04:56
MIN_VALUE / MAX_VALUE Examples
/**
* class Person
*
* An example use case for Number.MIN_VALUE and Number.MAX_VALUE.
**/
var Person = Class.create((function() {
var _age = Number.MIN_VALUE, _name;
return {
/**
* new Person(name[, age]);
@dandean
dandean / gist:162884
Created August 5, 2009 19:11
Guid class for generating and working with Guid-formatted strings...
/**
* class Guid
**/
var Guid = Class.create((function() {
var _value;
return {
/**
* new Guid(value);
*
* - value ([[String]]): Valid guid-formatted string.
@dandean
dandean / gist:162961
Created August 5, 2009 21:09
Object.prototype.toString enables really fucking cool equality comparison...
// Comparison in JavaScript is an interesting thing...
var Object1 = {
toString: function() { return "!!!"; }
};
var Object2 = {
toString: function() { return "!!!"; }
};
@dandean
dandean / gist:163773
Created August 7, 2009 07:56
Experimental mixins for decoupled object property watching
// This has been taken further here:
// http://github.com/dandean/shouter/tree/master
/**
* mixin Watchable enables sproutcore-style property watching... kinda.
* todo: - unwatch
* - allow property modification before setting
* - revisit naming
* - examples with UI elements
* - investigate potential performance issues
@dandean
dandean / gist:166783
Created August 12, 2009 21:37
Represents a Color and can be converted into multiple formats
/**
* class Color
**/
var Color = Class.create((function() {
function _testFormatSupport(format) {
var el = document.createElement("span");
var oldColor = el.style.color = "red";
try {
el.style.color = format;
@dandean
dandean / smart_link_to.rb
Created December 28, 2009 06:16
rails smart_link_to highlights itself when the URL matches it's href
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>test3</title>
<script type="text/javascript" charset="utf-8" src="_ui/js/lib/prototype.js"></script>
<script type="text/javascript" charset="utf-8" src="_ui/js/lib/s2.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8" src="_ui/js/application.js"></script>
</head>