Skip to content

Instantly share code, notes, and snippets.

View donavon's full-sized avatar
🏁
nothing is happening

Donavon West donavon

🏁
nothing is happening
View GitHub Profile
@donavon
donavon / ArrayContains.js
Created July 5, 2011 23:40
Does a JavaScript array contain a search element
// Array.contains
// compares searchElement to elements of the Array using strict equality
// (the same method used by the ===, or triple-equals, operator) and returns true or false
// Requires Array.indexOf. If not, see:
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
// ex: [1,2,3].contains(2) returns true
if (!Array.prototype.contains) {
Array.prototype.contains = function (searchElement) {
return this.indexOf(searchElement) !== -1;
@donavon
donavon / gist:2353348
Created April 10, 2012 18:11 — forked from pbouzakis/gist:2352989
Documents
// super simple
// all you need is the relation key, since the rest of the hypermedia control info is instead the individual items self relation
{
"http://rel.nkstdy.co/document": [
{
"ean":"032cfa77face18c7ce5cdac190d34b202f4a0574eb6437427ab018b59495445c",
"title":"JS2",
"dateAdded":"2012-04-03T19:32:07.583Z",
"dateModified":"2012-04-05T17:22:10.796Z",
@donavon
donavon / hal-catalog.json
Created April 10, 2012 19:35 — forked from domenic/hal-catalog.json
HAL version of catalog
{
"title": "Catalog for Domenic, page 2",
"description": "Contains lots of books, which is cool",
"page": 2,
"pageSize": 10,
"_links": {
"prev": { "href": "/docs?page=1", "type":"application/vnd.sidearm+json" },
"self": { "href": "/docs?page=2", "type":"application/vnd.sidearm+json" },
"next": { "href": "/docs?page=3", "type":"application/vnd.sidearm+json" }
},
<!DOCTYPE html>
<!-- File > New Project > Templates > JavaScript > Blank App; replace default.html with this -->
<html>
<head>
<meta charset="utf-8" />
<title>App2</title>
<!-- WinJS references -->
<link href="//Microsoft.WinJS.1.0.RC/css/ui-dark.css" rel="stylesheet" />
<script src="//Microsoft.WinJS.1.0.RC/js/base.js"></script>
@donavon
donavon / getThumbnailFromWebView.js
Last active March 22, 2016 06:17
`transformImageStream` is a WinJS (Windows 8) utility to transform an image stream. The sample code to get a snapshot from a WebView control requires Windows 8.1.
// Takes a snapshot of WebView control (Windows 8.1) and returns a thumbnail URL.
function getThumbnailFromWebView(webviewControl, width, height) {
return capturePreviewToBlobAsync(webviewControl).then(function (completeEvent) {
var blob = completeEvent.target.result;
var streamIn = blob.msDetachStream();
var Imaging = Windows.Graphics.Imaging;
var transform = new Imaging.BitmapTransform();
transform.scaledHeight = height;
transform.scaledWidth = width;
@donavon
donavon / index.js
Created October 17, 2013 13:34
requirebin sketch
var xcop = require("xcop");
console.log("** XCOP DEMO **\n");
var options = {
xcopDocument: "/host/0B32WZ_OndfDhY0lkSTNaeTNvSzA/xcop.html"
};
var origin = "https://googledrive.com";
xcop(origin, options).done(function (xhr) {
var request = { url: "message.json" };
@donavon
donavon / index.js
Last active August 29, 2015 14:10
requirebin sketch
// Utility functions.
var console = {
log: function log(msg) {
var el = document.createElement("div");
el.textContent = msg;
document.body.appendChild(el);
}
}
// yuzu-pns-client package.
@donavon
donavon / index.js
Created November 21, 2014 01:57
requirebin sketch
// example using the raf module from npm. try changing some values!
var requestAnimationFrame = require("raf")
var canvas = document.createElement("canvas")
canvas.width = 500
canvas.height = 500
document.body.appendChild(canvas)
var context = canvas.getContext("2d")
@donavon
donavon / index.js
Created November 21, 2014 01:58
requirebin sketch
// example using the raf module from npm. try changing some values!
var requestAnimationFrame = require("raf")
var canvas = document.createElement("canvas")
canvas.width = 500
canvas.height = 500
document.body.appendChild(canvas)
var context = canvas.getContext("2d")
@donavon
donavon / index.js
Created November 21, 2014 01:58
requirebin sketch
// example using the raf module from npm. try changing some values!
var requestAnimationFrame = require("raf")
var canvas = document.createElement("canvas")
canvas.width = 500
canvas.height = 500
document.body.appendChild(canvas)
var context = canvas.getContext("2d")