Skip to content

Instantly share code, notes, and snippets.

View Integralist's full-sized avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@Integralist
Integralist / Observer.js
Created January 3, 2011 18:40
Observer Design Pattern: Example from @StoyanStefanov's JavaScript Pattern book
/*
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 January 30, 2011 22:16
This script was written by @ded - I've just modified it slightly to take into account other browser vendor prefixes
/**
* @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 March 24, 2011 10:06
A extremely basic selector engine for mobiles that support querySelectorAll /via @WebReflection (Andrea Giammarchi)
var $ = (function (s) {
return function $(q) {
return s.call(document.querySelectorAll(q))
}
}([].slice));
@Integralist
Integralist / Generic JavaScript library
Created March 28, 2011 15:49
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)
@Integralist
Integralist / Quick 'n' Dirty Array.indexOf
Created July 12, 2011 08:12
Cheap 'inArray' trick by @ded
/*
* 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 July 13, 2011 14:36
Placeholder fallback script for browsers that don't natively support them.
/*
* The following script should be run on window.onload
*/
/*******************************************************
* VARIABLE SET-UP/CACHING
*******************************************************/
var doc = document,
body = doc.body,
@Integralist
Integralist / CSS Syntax Terminology
Created July 26, 2011 09:36
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 August 3, 2011 16:23
Problems with different regex implementations of lookbehind assertions
# 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 August 16, 2011 07:44
Using JavaScript to detect support for CSS pseudo-element selectors :before & :after (judges the width of the element)
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 August 16, 2011 08:21
A better way to detect :before and :after CSS pseudo-element selector support using JavaScript (Modernizr takes similar route)
body {
font: normal small Helvetica, Arial, Verdana, sans-serif;
}
h1 {
border-bottom: 1px solid #C00;
color: #666;
font-weight: bold;
margin-bottom: 10px;
}