Skip to content

Instantly share code, notes, and snippets.

View WebReflection's full-sized avatar
🎯
Focusing

Andrea Giammarchi WebReflection

🎯
Focusing
View GitHub Profile
@WebReflection
WebReflection / LICENSE.txt
Created May 22, 2011 14:23 — forked from 140bytes/LICENSE.txt
140byt.es -- Click ↑↑ fork ↑↑ to play!
Copyright (c) 2011 YOUR_NAME_HERE, YOUR_URL_HERE
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@WebReflection
WebReflection / Object.prototype.in.js
Created August 20, 2011 08:32
implementing "in" operator as generic object method
(function(Object, String){
// (C) WebReflection - Mit Style License
// @about implementing "in" operator as generic object method
// returns primitive value or object itself
function toValue(obj) {
switch (true) {
case isInstanceOf(obj, Boolean):
case isInstanceOf(obj, Number):
@WebReflection
WebReflection / track.js
Created August 23, 2011 16:45
how to track old libraries / namespaces
function track(object) {
// how to track old libraries, by Andrea Giammarchi
// var report = track(genericObject);
// ... run whatever you run usually ...
// console.log(report);
function createGetterSetterIfNecessary(key) {
return hasOwnProperty.call(result, key = key.slice(1)) ?
result[key]
@WebReflection
WebReflection / fake-script.js
Created August 24, 2011 19:03
hot to mock script requests
document.createElement = function (
createElement, // the native one
createResponse // the function "in charge"
) {
return function (nodeName) {
var result, src;
// if we are creating a script
if (/^script$/i.test(nodeName)) {
// result will be a place holder
result = createElement.call(
@WebReflection
WebReflection / document.retrieveSelector.js
Created August 27, 2011 09:28
retrieve a CSS selector out of a DOM node
document.retrieveSelector = (function (filter) {
// (C) WebReflection - Mit Style License
function elementsOnly(element) {
return element.nodeType == 1;
}
function createSelector(element, documentElement, path, first) {
var
@WebReflection
WebReflection / module.js
Created October 5, 2011 08:30
implicit require
var module = (function create(
namespace, handler, module, Proxy
) {
// ------------------------------------
// (C) WebReflection - MitStyle License
// ------------------------------------
// @dependency npm install node-proxy
// ------------------------------------
// var sys = module.sys;
// sys.print("it works!");
@WebReflection
WebReflection / properties.js
Created October 5, 2011 15:46
could be used by an IDE to inspect objects runtime
// could be used to inspect objects runtime
// e.g. with IDE for suggestion
// requires a modern JS engine in the IDE
var properties = function (
getNames, // alias Object.getOwnPropertyNames
getDescriptor,// alias Object.getOwnPropertyDescriptor
has, // alias {}.hasOwnProperty
toString // alias Function.prototype.toString
) {
// (C) WebReflection - Mit Style License
@WebReflection
WebReflection / Object.prototype.define.js
Created October 15, 2011 11:01
A simplified and intuitive way to define objects properties
(function (Object) {
/**
* @name Object.prototype.define
* @description A simplified and intuitive way to define objects properties.
* @requires Object.defineProperty, Array.prototype.forEach (native or shimmed)
* @author Andrea Giammarchi (@WebReflection)
* @license Mit Style
*/
@WebReflection
WebReflection / Object.prototype.define.html
Created October 15, 2011 12:25
100% code coverage for Object.prototype.define test
<!doctype html>
<html>
<head>
<title>wru</title>
<!-- https://github.com/WebReflection/wru -->
<script src="define.js"></script>
<script>function wru(wru){var assert=wru.assert,async=wru.async;
// enojy your tests!
@WebReflection
WebReflection / Object.prototype.on.js
Created October 15, 2011 16:25
Transform any sort of object into Event emitter/dispatcher
(function () {
// Andrea Giammarchi - Mit Style License
// note: it's not production ready
function dispatch(callback) {
callback.call(this.r, this.e);
}
function add(callback) {
this.handlers.indexOf(callback) < 0 &&