Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
kara-ryli / yui-loader-third-party.js
Created November 11, 2011 19:23
Tricking YUI loader to allow third-party dependencies.
// ensure your application uses this YUI instance!
var Y = YUI().use(function (Y) {
var thirdPartyModules, moduleTest, win, cfg;
function emptyFunction() {}
function addMatches(match) { // match looks like ",facebook,"
var module = match.substring(1, match.length - 1); // e.g. "facebook"
YUI.add(module, emptyFunction);
}
@kara-ryli
kara-ryli / problem.html
Created October 29, 2011 22:01
Scalable SVG CSS Challenge
<!DOCTYPE html>
<html><head>
<title>Can you replicate this using &lt;object /&gt;?</title>
<style>
#image {
background-image: url(scalable-image.svg);
background-position: center top;
background-repeat: no-repeat;
background-size: contain;
height: 100%;
@kara-ryli
kara-ryli / yui-external-dependencies.js
Created October 22, 2011 00:35
Add external dependencies to YUI
/*global YUI*/
(function () {
var LOADED = ":loaded",
FAILED = " failed to load",
CUSTOM = ["event-custom"];
YUI().Array.each([
{
loading: false,
name: "facebook",
@kara-ryli
kara-ryli / MyAppDelegate.m
Created October 20, 2011 22:21
Create a device-specific identifier in Objective-C
@implementation MyAppDelegate
/**
* Generates a Universally Unique Identifier based on the time and
* hardware details of a device. CFUUIDCreate is the recommended
* way by Apple to generate an ID now that UIDevice-uniqueIdentifier
* is deprecated.
*
* Props: http://www.cocoabuilder.com/archive/cocoa/217665-how-to-create-guid.html#217668
*/
@kara-ryli
kara-ryli / NFLURLConnectionLoader.h
Created October 17, 2011 03:33
Manage multiple NSURLConnections with blocks.
//
// NFLURLConnectionLoader.h
//
// Created by Cannon, Ryan on 10/13/11.
//
#import <Foundation/Foundation.h>
@interface NFLURLConnectionLoader : NSObject {
}
@kara-ryli
kara-ryli / jquery.datatables.plugin.numeric-time.js
Created August 22, 2011 18:44
Enables time-based sorting for jQuery DataTables.
(function (dataTableExt) {
var TIME_RE = /^(\d+:)*(\d+.\d+)$/,
timeToSeconds = function (sTime) {
for (var i = aDaysHoursMin.length,
n = 1,
mDaysHoursMin = sTime.match(TIME_RE),
sDaysHoursMin = mDaysHoursMin[1],
aDaysHoursMin = sDaysHoursMin.substr(0, sDaysHoursMin.length - 1).split(":"),
nTime = parseFloat(mDaysHoursMin[2], 10);
@kara-ryli
kara-ryli / widget-functions.js
Created August 10, 2011 18:21
Widget functions I end up writing in almost every time I superclass.
/*global YUI*/
YUI.add("widget-functions", function (Y) {
"use strict";
var ADD = "addClass"
, REM = "removeClass"
, BBX = "boundingBox"
, GCN = "getClassName"
, NV = "newVal"
, PV = "prevVal"
, AN = "attrName"
@kara-ryli
kara-ryli / UIWebViewController.m
Created August 3, 2011 22:32
Firing an orientationchange event from a UIWebView
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
NSInteger orientation;
switch (interfaceOrientation) {
case UIInterfaceOrientationPortraitUpsideDown:
orientation = 180;
break;
case UIInterfaceOrientationLandscapeLeft:
orientation = -90;
@kara-ryli
kara-ryli / implementation.js
Created July 8, 2011 20:01
Create a singleton class in YUI3. This class can only be instantiated one time. All later instantiations return references to the original.
YUI().use("singleton-class", function (Y) {
var instance1 = new Y.SingletonClass(),
instance2 = new Y.SingletonClass();
Y.log(instance1 === instance2); // true!
window.instance1 = instance1;
});
YUI().use("singleton-class", function (Y) {
@kara-ryli
kara-ryli / dynamic-use.js
Created June 16, 2011 19:27
Dynamically Loading and using YUI modules
YUI({
modules: { /* define modules here */}
}).use("node", function (Y) {
function lazyLoadedCallback() {
// this is where you do the work after your modules are loaded
}
Y.once("click", function (event) {