Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
kara-ryli / google-ima.js
Created November 13, 2012 02:17
Loads the google IMA library exactly once.
/*global YUI*/
/**
* Loads the google IMA library exactly once.
*
* https://developers.google.com/interactive-media-ads/docs/sdks/googlehtml5
*
* @module google-ima
* @requires event-custom
*/
@kara-ryli
kara-ryli / sampler.html
Created October 25, 2012 21:47
An HTML Element Sampler for testing the appearance of standard elements in context.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML Element Sampler</title>
</head>
<body>
<h1>HTML Element Sampler</h1>
<p>This is a paragraph. It's just something I threw together.
@kara-ryli
kara-ryli / node-media.js
Created July 20, 2012 00:45
Adds HTML5 MediaElement and full screen support to Y.Node
/*global YUI*/
/**
* Adds HTML5 Media Element support to Y.Node
*
* @module node
* @submodule node-media
* @main node
* @requires node-base
*/
YUI.add("node-media", function (Y) {
@kara-ryli
kara-ryli / subscriber-come-lately.js
Created July 19, 2012 00:00
Notify event new subscribers between events that happened on an interval in YUI
/*global YUI*/
YUI().use("event-custom", function (Y) {
var et = new Y.EventTarget(),
ce = et.publish("frob", {
defaultFn: function (event) {
et.frobs += 1;
},
emitFacade: true
});
@kara-ryli
kara-ryli / performant-events.js
Created July 17, 2012 19:48
Demonstrates YUI3 event subscription monitoring, for use with performance-intensive events.
YUI().use("widget", function (Y) {
var eventName = "frob",
widg = new Y.Widget(),
ce = widg.publish(eventName);
ce.monitor("attach", function (handler) {
var subs = ce.getSubs();
console.log("handler attached!", subs);
if (!ce.hasSubs()) {
console.log("enabling performance-intensive event");
}
@kara-ryli
kara-ryli / io-cors.js
Created June 21, 2012 18:29
Avoid an OPTIONS request when using DataSource.IO with CORS headers
YUI().use("datasource-io", function (Y) {
// Described in YUI 3.3.0's patch notes
// http://yuilibrary.com/projects/yui3/wiki/ReadMe/RollUp_3.3.0?version=3
//
var ds = new Y.DataSource.IO({
source: "http://www.example.com/",
ioConfig: {
headers: {
"X-Requested-With": "disable"
@kara-ryli
kara-ryli / write-sandboxed-html.js
Created June 13, 2012 19:14
Write arbitrary HTML into an iframe sandbox. Useful for untrusted 3rd-party code (e.g. ads).
/**
Writes a sandboxed block of HTML to the supplied node.
<p>Based on an example from <a href="https://github.com/RCanine/embed-code">Meebo</a>.</p>
@method writeSandboxedHTML
@namespace RC
@param {String} width a valid CSS width
@param {String} height a valid CSS height
@param {String} html a block of HTML code
@kara-ryli
kara-ryli / loader-size.as
Created June 8, 2012 19:16
Getting the height and width of a loaded image in ActionScript
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (event:Event):void {
// although these two values are the same, accessing the later doesn't
// work unless your image is on the same server as the HTML page, or
// you tell the loader to check a policy file first.
trace("loader width: " + loader.width); // Works
trace("bitmap width: " + loader.content.width); // Exception
});
loader.load(new URLRequest("http://www.example.com/image.png"));
@kara-ryli
kara-ryli / singleton-datasource.js
Created May 14, 2012 02:50
A simple wrapper around datasource that allows multiple instances to be created, but only a single request be made.
/*global YUI*/
/**
A simple wrapper around datasource that allows multiple
instances to be created, but only a single request be
made.
@module singleton-datasource
@requires base-build, base-base, datasource-local
**/
YUI.add("singleton-datasource", function (Y) {
@kara-ryli
kara-ryli / rem.scss
Created May 12, 2012 19:55
Easy brower-compatible rem units with SCSS
/* Note: this method disables user font scaling via browser preferences.
It's up to you whether this is a good thing. In this case, browsers
that don't support rem get the default (pixel) value, and don't get
the fancy scaling.
*/
$rem_size: 10;
$rem_px: #{$rem_size}px;
@mixin rem($property, $value) {
#{$property}: $value * $rem_size;
#{$property}: #{$value}rem;