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 / server-sent-event.php
Last active May 31, 2025 19:53
server-sent events #php
<?php
header("Content-Type: text/event-stream");
while(true) {
echo "Event: server-time\n";
$time = time();
echo "data: $time\n";
echo "\n";
flush();
sleep(3);
}
@Integralist
Integralist / css-props-accept-url.js
Last active May 31, 2025 20:09
displays CSS properties that support URL as value via @LeaVerou #js
var s = document.body.style;
for (var i in s) {
s[i] = "url('foo')";
if(s[i]) {
console.log(i);
s[i] = ''
}
}
@Integralist
Integralist / Access-Original-Value.js
Last active May 31, 2025 20:11
Access original value of property that has been over-written /via @jdalton and modified by @dperini #js
(function() {
var hasKey = {}.hasOwnProperty;
Object.prototype.hasOwnProperty = 1;
delete Object.prototype.hasOwnProperty;
var iframe = document.createElement('iframe');
document.documentElement.appendChild(iframe);
Object.prototype.hasOwnProperty = window.frames[0].Object.prototype.hasOwnProperty;
document.documentElement.removeChild(iframe);
@Integralist
Integralist / Grid.css
Last active May 31, 2025 20:11
Better CSS Grid System #css
/*
* Algorithm taken from:
* http://csswizardry.com/2011/08/building-better-grid-systems/
*/
.row {
width: (number of columns * width of one column) + (number of columns * width of one gutter) px;
margin-left: -width of one gutter px;
overflow: hidden;
clear: both;
@Integralist
Integralist / template.js
Last active May 31, 2025 20:12
@madrobby's 140 bytes template engine #js
function template(string, data, prop) {
for (prop in data) {
string = string.replace(new RegExp('{' + prop + '}', 'g'), data[prop]);
}
return string;
}
/*
String templating engine:
@Integralist
Integralist / createElement.js
Last active May 31, 2025 20:16
Create Elements using memoization technique (modified to @GarrettS' points) #js
/**
* The following method creates a new element or returns a copy of an element already created by this script.
*
* @param tagname { String } element to be created/copied
* @return { Element/Node } the newly created element
*/
createElement: (function(){
// Memorize previous elements created
var cache = {};
@Integralist
Integralist / app.build.js
Last active May 31, 2025 20:18
RequireJs Build Script #js
/*
* http://requirejs.org/docs/optimization.html
*
* Use NodeJs to execute the r.js optimization script on this build script
* node r.js -o app.build.js
*
* See: https://github.com/jrburke/r.js/blob/master/build/example.build.js for an example build script
*
* If you specify just the name (with no includes/excludes) then all modules are combined into the "main" file.
* You can include/exclude specific modules though if needed
@Integralist
Integralist / viewport.md
Last active May 31, 2025 20:20
Analyze the viewport size #js

It’s possible to analyze the viewport size in JavaScript but it’s a little messy:

  • Most browsers support window.innerWidth and window.innerHeight.

  • But IE6, 7, 8 and 9 in quirks mode require document.body.clientWidth and document.body.clientHeight.

  • All the main browsers support document.documentElement.clientWidth and document.documentElement.clientHeight but it’s inconsistent. Either the window or document dimensions will be returned depending on the browser and mode.

@Integralist
Integralist / index.html
Last active May 31, 2025 20:23
jQuery Ajax Test (using Deferred/Promises) #js
<!doctype html>
<html>
<head>
<title>jQuery Ajax Test</title>
<style type="text/css">
#test {
background-color:pink;
display:none;
padding:10px;
text-align:center;
@Integralist
Integralist / deferredImplems.md
Last active May 31, 2025 20:39 — forked from addyosmani/deferredImplems.md
Deferred implementations #js