Skip to content

Instantly share code, notes, and snippets.

@localpcguy
localpcguy / object-forin-forown.js
Created February 27, 2017 15:31 — forked from cowboy/object-forin-forown.js
JavaScript: Object#forIn and Object#forOwn
/*
* Object#forIn, Object#forOwn
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
Object.defineProperties(Object.prototype, {
forIn: {
@localpcguy
localpcguy / Truncate Multiline Copy.markdown
Created September 28, 2015 20:43
Truncate Multiline Copy
@localpcguy
localpcguy / font-mimetypes
Last active July 29, 2021 13:37
Mime Types for Fonts and Media
.eot - application/vnd.ms-fontobject
.woff - application/font-woff
.ttf - application/x-font-truetype
.svg - image/svg+xml
.otf - application/x-font-opentype
IIS (Web.Config)
<remove fileExtension=".eot" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<remove fileExtension=".ttf" />
@localpcguy
localpcguy / executeOnDomNodeLoaded.js
Created September 18, 2012 17:07
executeOnDomNodeLoaded polls the DOM repeatedly until the DOM node is in the DOM, and then executes the callback
function executeOnDomNodeLoaded(node, func) {
// This function will check, every tenth of a second, to see if
// our element is a part of the DOM tree - as soon as we know
// that it is, we execute the provided function.
var findUltimateAncestor = function(node) {
// Walk up the DOM tree until we are at the top (parentNode
// will return null at that point).
// NOTE: this will return the same node that was passed in
// if it has no ancestors.
var ancestor = node;
@localpcguy
localpcguy / FB Async Init Code
Created March 30, 2012 20:23
FB_AsyncInitCode.js
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: 'FBAPPID', // App ID
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
@localpcguy
localpcguy / AsyncOnload3rdPartyScriptLoaderExplicitRender.js
Created February 27, 2012 23:37
Async Third party script loader explicit render only (won't render on load of script)
<script>
(function(w, d, s) {
function go() {
var js, fjs = d.getElementsByTagName(s)[0], load =
function(url, id, inTextOption) {
if (d.getElementById(id)) { return; }
js = d.createElement(s); js.src = url; js.id = id;
if (typeof inTextOption !== "undefined" && inTextOption.length) {
try { js.text = inTextOption; } // in try because .text="string" fails in Opera
catch (e) { js.innerText = inTextOption; } // for Opera
@localpcguy
localpcguy / AsyncOnload3rdPartyScriptLoader.js
Created November 24, 2011 02:25
Async Third party script loader after body.onload
<script>
// Credit to:
// Original function adapted from Facebook async script at - http://www.phpied.com/social-button-bffs/
// http://twitter.com/aaronpeters
// http://www.aaronpeters.nl/blog/why-loading-third-party-scripts-async-is-not-good-enough
(function(w, d, s) {
function go(){
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id, cb) {
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.src = url; js.id = id;
@localpcguy
localpcguy / swipeFunc.js
Created November 17, 2011 16:00
Simple Mobile Swipe function to get the swipe direction
var swipeFunc = {
touches : {
"touchstart": {"x":-1, "y":-1},
"touchmove" : {"x":-1, "y":-1},
"touchend" : false,
"direction" : "undetermined"
},
touchHandler: function(event) {
var touch;
if (typeof event !== 'undefined'){