Skip to content

Instantly share code, notes, and snippets.

@localpcguy
localpcguy / Truncate Multiline Copy.markdown
Created September 28, 2015 20:43
Truncate Multiline Copy
@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 / 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 / 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 / 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 / p4merge4git.md
Created May 9, 2017 20:59 — forked from tony4d/p4merge4git.md
Setup p4merge as a visual diff and merge tool for git
@localpcguy
localpcguy / getClass.js
Created May 31, 2017 18:12
Get the class type of a JavaScript element
function getClass(obj) {
if (typeof obj === 'undefined') {
return 'undefined';
}
if (obj === null) {
return 'null';
}
return Object.prototype.toString.call(obj).match(/^\[object\s(.*)\]$/)[1];
}
//<p class="name">hi {{name}}</p>
Handlebars.templates["hi"]=function(data) {
return "<p class=\"name\">hi "
+ escapeExpression(data['name'])
+ "</p>\n";
});
@localpcguy
localpcguy / .block
Last active June 14, 2017 20:57
SVG bar chart
license: mit