Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
ryanflorence / flo.js
Created December 16, 2010 17:44
A mini element library
// Mini Framework
Object.extend = function(original, extensions){
original = original || {};
for (var i in extensions) if (extensions.hasOwnProperty(i)) original[i] = extensions[i];
return original;
};
flo = function(selector){
if (!(this instanceof flo)) return new flo(selector);
var str = 'foo';
switch (str) {
case true:
console.log('got it');
break;
default:
console.log('default');
break;
@ryanflorence
ryanflorence / natives.js
Created January 15, 2011 06:09
Experimental extending of native objects without touching prototypes
;(function(){
function typeOf(item){
if (item._family) return item._family();
return typeof item;
}
Array.prototype._family = function(){ return 'array'; };
var _ = this._ = function(obj){
<?php
/**
* CSV Class
*/
class CSV
{
public static function from_file($path = '')
{
@ryanflorence
ryanflorence / js-jquery-syntax.js
Created February 1, 2011 18:41
Some basic ideas to get a handle on JavaScript and jQuery syntax
// assign variables;
var a = 'whatever';
// create functions
function whatever(arg, arg2){
// use arguments
console.log(arg, arg2);
}
// same as above (basically)
@ryanflorence
ryanflorence / mediator.js
Created February 2, 2011 21:43
Pub/Sub for Objects
/*
Mediator
--------
This object mediates custom events among objects on the page. Objects don't need to know about other objects in order to communicate with them--they simply subscribe to global publications. This decouples all of the objects from each other. In most cases, an object's entire implementation can be described in one code block anywhere in the application code.
### mediator method: publish
Publishes an event to the application that objects can subscribe to, passing along information.
@ryanflorence
ryanflorence / app.js
Created February 4, 2011 18:10
Node.JS + Socket.IO + 10 minutes = Chat
/**
* Module dependencies.
*/
var express = require('express')
, io = require('socket.io');
var app = module.exports = express.createServer();
// Configuration
<?php
$arr = array(
'Color' => array('Red', 'Blue'),
'Size' => array('Regular', 'Large'),
'Material' => array('Metalic', 'Nylon')
);
function magic_algorithm($arr){
//
@ryanflorence
ryanflorence / iife.js
Created February 24, 2011 20:37
immediately invoked function expression
slideshow.addEvent('showComplete',
(
// this function is immediately called before passing in the argument to addEvent
function(){
// these are scoped variables, a lot like
// protected variables in PHP
var looped = false,
length = slideshow.slides.length - 1;
// this function is the actual argument that gets sent to addEvent
@ryanflorence
ryanflorence / pair.js
Created March 25, 2011 03:32
An object creation pattern
var pair = {}
pair.create = function (x, y){
var _x, _y, publik = {}
function init(x, y){
_x = x
_y = y
sum()
diff()
prod()