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
Last active May 31, 2025 17:22
Observer Design Pattern #patterns
/*
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.
@Integralist
Integralist / Animate Class.js
Last active May 31, 2025 17:24
JavaScript CSS animation #js
// 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}
@Integralist
Integralist / Mobile Selector Engine.js
Last active May 31, 2025 17:25
Mobile Selector Engine #js
// 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.js
Last active May 31, 2025 17:26
Generic JavaScript library #js
(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.js
Last active May 31, 2025 18:17
Cheap 'inArray' trick by @ded #js
/*
* 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
Last active May 31, 2025 18:19
input placeholder polyfill #js
/*
* The following script should be run on window.onload
*/
/*******************************************************
* VARIABLE SET-UP/CACHING
*******************************************************/
var doc = document,
body = doc.body,
@Integralist
Integralist / CSS Syntax Terminology.css
Last active May 31, 2025 18:20
CSS Syntax Terminology #css
/* 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 / lookbehind implementations.md
Last active May 31, 2025 18:21
lookbehind implementations #regex

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
Last active May 31, 2025 19:49
detect CSS pseudo-element selector support #js
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
Last active May 31, 2025 19:51
better CSS pseudo-element selector detector #js
body {
font: normal small Helvetica, Arial, Verdana, sans-serif;
}
h1 {
border-bottom: 1px solid #C00;
color: #666;
font-weight: bold;
margin-bottom: 10px;
}