Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@Integralist
Integralist / Observer.js
Created Jan 3, 2011
Observer Design Pattern: Example from @stoyanstefanov's JavaScript Pattern book
View Observer.js
/*
Let’s say you have a publisher paper, which publishes a daily newspaper and a monthly magazine. A subscriber joe will be notified whenever that happens.
The paper object needs to have a property subscribers that is an array storing all sub- scribers.
The act of subscription is merely adding to this array.
When an event occurs, paper loops through the list of subscribers and notifies them.
The notification means calling a method of the subscriber object.
Therefore, when subscribing, the subscriber provides one of its methods to paper’s subscribe() method.
The paper can also provide unsubscribe(), which means removing from the array of subscribers.
@Integralist
Integralist / Animate Class
Created Jan 30, 2011
This script was written by @ded - I've just modified it slightly to take into account other browser vendor prefixes
View Animate Class
/**
* @constructor Animate
* @param {HTMLElement} el the element we want to animate
* @param {String} prop the CSS property we will be animating
* @param {Object} opts a configuration object
* object properties include
* from {Int}
* to {Int}
* time {Int} time in milliseconds
* callback {Function}
@Integralist
Integralist / Mobile Selector Engine
Created Mar 24, 2011
A extremely basic selector engine for mobiles that support querySelectorAll /via @WebReflection (Andrea Giammarchi)
View Mobile Selector Engine
var $ = (function (s) {
return function $(q) {
return s.call(document.querySelectorAll(q))
}
}([].slice));
View Generic JavaScript library
(function(window, document, undef) {
// Generic library
var mylib = (function(){
// Private implementation
var __mylib = {
/**
* Following property indicates whether the current rendering engine is Trident (i.e. Internet Explorer)
View Quick 'n' Dirty Array.indexOf
/*
* jsFiddle: http://jsfiddle.net/integralist/fL2Xv/
* Original: http://twitter.com/#!/ded/status/90531502097575936
*/
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(item) {
return ( Math.abs( ~this.indexOf(item) ) )-1;
}
}
@Integralist
Integralist / Placeholder.js
Created Jul 13, 2011
Placeholder fallback script for browsers that don't natively support them.
View Placeholder.js
/*
* The following script should be run on window.onload
*/
/*******************************************************
* VARIABLE SET-UP/CACHING
*******************************************************/
var doc = document,
body = doc.body,
View CSS Syntax Terminology
/* Rule (the entire chunk of code below can just be referred to as a single 'rule') */
/* Selectors */
#myID, .myClass
/* Declaration Block */
{
/* Declaration */
/* Property */border: /* Value */1px solid #DCDDDE;
@Integralist
Integralist / gist:1123058
Created Aug 3, 2011
Problems with different regex implementations of lookbehind assertions
View gist:1123058
# taken from http://www.regular-expressions.info/lookaround.html
"The bad news is that most regex flavors do not allow you to use just any regex inside a lookbehind, because they cannot apply a regular expression backwards. Therefore, the regular expression engine needs to be able to figure out how many steps to step back before checking the lookbehind.
Therefore, many regex flavors, including those used by Perl and Python, only allow fixed-length strings. You can use any regex of which the length of the match can be predetermined. This means you can use literal text and character classes. You cannot use repetition or optional items. You can use alternation, but only if all options in the alternation have the same length.
PCRE is not fully Perl-compatible when it comes to lookbehind. While Perl requires alternatives inside lookbehind to have the same length, PCRE allows alternatives of variable length. Each alternative still has to be fixed-length.
Java takes things a step further by allowing finite repet
@Integralist
Integralist / detect.css
Created Aug 16, 2011
Using JavaScript to detect support for CSS pseudo-element selectors :before & :after (judges the width of the element)
View detect.css
body {
font: normal small Helvetica, Arial, Verdana, sans-serif;
}
h1 {
border-bottom: 1px solid #C00;
color: #666;
font-weight: bold;
margin-bottom: 10px;
}
@Integralist
Integralist / detect.css
Created Aug 16, 2011
A better way to detect :before and :after CSS pseudo-element selector support using JavaScript (Modernizr takes similar route)
View detect.css
body {
font: normal small Helvetica, Arial, Verdana, sans-serif;
}
h1 {
border-bottom: 1px solid #C00;
color: #666;
font-weight: bold;
margin-bottom: 10px;
}
You can’t perform that action at this time.