Skip to content

Instantly share code, notes, and snippets.

// Using only direct canvas method wrappers (which use the same
// name as official canvas methods):
ctx.shadowColor('green').shadowBlur(2).shadowOffsetX(5).shadowOffsetY(10);
// Using one utility method (at the end) amongst direct canvas method wrappers:
ctx.shadowColor('green').shadowBlur(2).$shadowOffset(5, 10);
// Using custom utility exclusively with its own simplified
// non-canvas (but easily derived) syntax:
ctx.$shadow({color:'green', blur:2, offset:[5, 10]});
@brettz9
brettz9 / C2D2-node-canvas.js
Created March 31, 2011 19:36
C2D2-node-canvas.js
var C2D2 = require('C2D2').C2D2([500, 400], {path: 'myImageFilePath.png'})
C2D2.
$shadow({color:'green', blur:2, offset:[15, 10]}).
$fill({color:'blue', xy:[[175, 150], [200,175], [200,125]]});
@brettz9
brettz9 / C2D2.html
Created March 31, 2011 19:39
C2D2.html
<!--[if lte IE8]><script type="text/javascript" src="explorercanvas/excanvas.js"></script><![endif]-->
<script type="text/javascript" src="canvas.js"></script>
@brettz9
brettz9 / XQueryHelper.js
Created April 3, 2011 05:43
XQIB hack to expose XQuery calls to user JavaScript
/*globals mxqueryjs*/
// This code is from https://gist.github.com/900225
/*
("Unlicense")
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
@brettz9
brettz9 / XQueryHelper-demo.html
Created April 3, 2011 12:33
Demonstrates ability of XQueryHelper kludge class to be used with XQIB to allow dynamic XQueries from JavaScript
See https://gist.github.com/900225 for JS code and HTML demo code or http://brett-zamir.me/demos/XQueryHelper/ for the demo instead.
@brettz9
brettz9 / getCSSPropertyValue.js
Last active March 29, 2018 23:41
getCSSPropertyValue.js
/**
* @example
* getCSSPropertyValue('.someClass', 'color');
*/
function getCSSPropertyValue (selectorText, propertyName) {
function _getPropertyFromStyleSheet (ss, selectorText, propertyName) {
let value = null;
[...ss.cssRules].some((rule) => {
if (rule.type === CSSRule.STYLE_RULE &&
rule.selectorText === selectorText
@brettz9
brettz9 / require.js
Created October 31, 2012 18:45 — forked from erikvold/require.js
Imports a commonjs style javascript file with loadSubScrpt for restartless Firefox add-ons.
/* Imports a commonjs style javascript file with loadSubScrpt
* By Erik Vold <erikvvold@gmail.com> http://erikvold.com/
*
* @param src (String)
* The url of a javascript file.
*/
(function(global) {
var modules = {};
global.require = function require(src) {
if (modules[src]) return modules[src];
@brettz9
brettz9 / bottomDollar.js
Last active October 12, 2015 09:58
bottomDollar
/**
Currently non-functional lite jQuery drop-in replacement.
"Bottom Dollar" as name is to express there being a bargain for the
amount of code, and the "_$" convention also spells this out).
@ todos
1. Replace __noSuchMethod__ with Proxy
*/
var _$;
@brettz9
brettz9 / String-test.html
Created November 10, 2012 05:46
Shim to allow array-like access on "new String()" characters
<!-- Add our shim to support array-like accessors on
String objects (i.e., those invoked with new String()) -->
<script src="String.js"></script>
<script>
// Regular string literals or String() invoked without 'new' will
// behave the same as without the shim in all browsers (i.e.,
// accessors are not supported in IE < 9)
var str = 'abc';
@brettz9
brettz9 / html5-dataset.js
Last active April 29, 2023 14:58
Dataset Shim
/**
* Add dataset support to elements
* No globals, no overriding prototype with non-standard methods,
* handles CamelCase properly, attempts to use standard
* Object.defineProperty() (and Function bind()) methods,
* falls back to native implementation when existing
* Inspired by http://code.eligrey.com/html5/dataset/
* (via https://github.com/adalgiso/html5-dataset/blob/master/html5-dataset.js )
* Depends on Function.bind and Object.defineProperty/Object.getOwnPropertyDescriptor (polyfills below)
* All code below is Licensed under the X11/MIT License