Skip to content

Instantly share code, notes, and snippets.

View adamcjoiner's full-sized avatar

Adam C. Joiner adamcjoiner

View GitHub Profile
@adamcjoiner
adamcjoiner / reddit.html
Created March 31, 2017 22:06 — forked from sente/reddit.html
An example of a retrieving data from reddit's JSON(p) api using jquery
<!DOCTYPE html>
<!--
Stuart Powers
http://sente.cc/
http://twitter.com/stuartpowers
-->
<html>
<head>
@adamcjoiner
adamcjoiner / fancybox-inline.html
Last active May 11, 2017 18:51
How to link to inline content using fancybox
<!-- via stackoverflow: http://stackoverflow.com/questions/3963338/loading-inline-content-using-fancybox -->
<!-- Question: How can I load inline (inner-page) content using fancybox? -->
<!-- Answer [Oct 18 '10 at 20:59 by Marko]: The solution is very simple, but took me about 2 hours and half the hair on my head to find it. Simply wrap your content with a (redundant) div that has display: none and Bob is your uncle. -->
<div style="display: none">
<div id="content-div">Some content here</div>
</div>
@adamcjoiner
adamcjoiner / injector.js
Created July 19, 2017 21:50
Inject remote Javascript file into currently loaded page via browser's location bar
javascript: javascript: (function() {
var s = 'https://nytimes.github.io/svg-crowbar/svg-crowbar.js';
var e = document.createElement('script');
e.setAttribute('src', s);
e.setAttribute('class', 'svg-crowbar');
document.body.appendChild(e);
})();
@adamcjoiner
adamcjoiner / js_objects.js
Created July 25, 2017 14:14
An example of how to use an object stored in a variable that contains multiple methods
var winston = require('winston');
winston.add(
winston.transports.File, {
filename: 'node-log-file.json.log',
level: 'info',
json: true,
eol: '\n', // for Windows, or `eol: '\n',` for *NIX OSs
timestamp: true
}
);
@adamcjoiner
adamcjoiner / debug_to_console.php
Created July 26, 2017 06:58
Send PHP debug message to Javascript console
<?php
/**
* Output debug message to browser console
*/
function debug_to_console($data) {
if(is_array($data) || is_object($data))
{
echo("<script>console.log('PHP: ".json_encode($data)."');</script>");
} else {
echo("<script>console.log('PHP: ".$data."');</script>");
@adamcjoiner
adamcjoiner / inject-remote-script.js
Last active March 11, 2023 18:53
Inject remote Javascript into page asynchronously without using vanilla JS (no jQuery)
// Method used in Google Analytics:
(function(d, script) {
script = d.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.onload = function(){
// remote script has loaded
};
script.src = 'http://www.google-analytics.com/ga.js';
@adamcjoiner
adamcjoiner / dom-to-object
Last active September 28, 2017 03:46 — forked from alain75007/elementToObject
DOM Node -> Object -> JSON
function elementToObject(element, o) {
var el = $(element);
var o = {
tagName: el.tagName
};
var i = 0;
for (i ; i < el.attributes.length; i++) {
o[el.attributes[i].name] = el.attributes[i].value;
}
@adamcjoiner
adamcjoiner / dom-to-json.js
Last active September 27, 2017 23:49 — forked from sstur/dom-to-json.js
Convert DOM Node ->JSON string format (and back again)
function toJSON(node) {
node = node || this;
var obj = {
nodeType: node.nodeType
};
if (node.tagName) {
obj.tagName = node.tagName.toLowerCase();
} else
if (node.nodeName) {
obj.nodeName = node.nodeName;
@adamcjoiner
adamcjoiner / xml-to-json.js
Created September 27, 2017 23:42
Convert XML -> JSON
// Changes XML to JSON
function xmlToJson(xml) {
// Create the return object
var obj = {};
if (xml.nodeType == 1) { // element
// do attributes
if (xml.attributes.length > 0) {
obj["@attributes"] = {};
@adamcjoiner
adamcjoiner / jquery-methods-in-vanilla-js.md
Last active September 28, 2017 03:43
Common Jquery Methods In Raw JS

Common Jquery Methods In Raw JavaScript

Events

// jQuery
$(document).ready(function() {
  // code
})