Skip to content

Instantly share code, notes, and snippets.

View shadybones's full-sized avatar

Jordan Williams shadybones

  • San Francisco
View GitHub Profile
@shadybones
shadybones / CMAPI_Integration.js
Last active January 29, 2024 08:59
Partial integration between the TrustArc Consent Manager API and Google Tag Manager. This code allows for GTM event-based tag firing solution.
var __dispatched__ = {}; //Map of previously dispatched preference levels
/* First step is to register with the CM API to recieve callbacks when a preference update occurs
You must wait for the CM API (PrivacyManagerAPI object) to exist on the page before registering
*/
var __i__ = self.postMessage && setInterval(function(){
if(self.PrivacyManagerAPI && __i__){
var apiObject = { PrivacyManagerAPI:
{ action:"getConsentDecision",
timestamp: new Date().getTime(),
@shadybones
shadybones / build.py
Last active August 29, 2015 14:09
Combine ( merge ) multiple JS files into a single one. Build JS files using imports. Use build-time bindings from property files. Meant to be used in conjunction with a maven or ant build system.
#!/usr/bin/python
#
# Combine ( merge ) multiple JS files into a single one. Build JS files using imports.
# Use bindings from multiple property files.
#
# Use @import {file path} to import js files (paste into the current JS in the output).
# Pasting occurs at the site of the import statement.
# Use ${binding_name} to inject values from a property file when you build
#
# I chose simplicity and ease of understanding over complexity and featurefull-ness.
@shadybones
shadybones / testDynamicCSSClass.html
Last active January 31, 2022 05:33
Test a snippet of JS for dynamically creating CSS classes using JS
<html>
<head>
<style type="text/css">
.ccc{ background-color: blue; }
</style>
</head>
<body>
<script type="text/javascript">
function createClass(name,rules){
@shadybones
shadybones / adfonic-test.html
Created January 23, 2014 20:48
From the original tag on the ticket, you can get here by adding <script src="https://rawgithub.com/mopub/mopub-android-sdk/master/mopub-sdk/etc/mraid.js"></script> script element before the image element. Then after the pages loads, call: mraidbridge.fireReadyEvent(); mraidbridge.fireChangeEvent({"viewable":true});
<html><body style="min-height: 50px; margin: 0px; padding: 0px; width: 100%; height: 100%;">
<div class="celtra-ad-v3">
<div style="overflow: hidden; display: block; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; bottom: auto; right: auto;">
<div id="celtra-banner" class=" celtra-creative-unit celtra-view appeared" style="background-color: rgb(255, 255, 255); overflow: hidden; position: absolute; width: 320px; height: 50px; left: 50%; margin-left: -160px; right: auto; top: 50%; margin-top: -25px; bottom: auto; background-position: initial initial; background-repeat: initial initial;">
<div class="celtra-screen-container" style="position: absolute; width: 100%; height: 100%;">
<div class="celtra-screen-holder" style="width: 100%; height: 100%;">
<div id="celtra-object-2" class=" celtra-screen celtra-screen-object-container celtra-view" style="width: 320px; height: 50px; overflow: hidden; display: none; z-index: -1;"></div>
<div id="celtra-object-2" class=" celtra-screen celtra-screen-objec
@shadybones
shadybones / buffer2File.js
Last active January 2, 2016 13:29
Saving a Typed Array ( ArrayBuffer ) to a file in Firefox Extension / Addon. What sucks: --1) FOS.write converts to a string (toString()) whatever buffer you pass and uses the returned primitive as the memory location of the buffer. --2) NetUtil.asyncCopy only accepts nsIInputStreams --3) Can't implement a nsIInputStream in javascript. --4) data…
function read2Buffer(from, to, maxN, offset){
if(!from || !to || !maxN) throw "Invalid Arguments";
from = from.buffer || from;
if(from.byteLength) from = new Uint8Array(from);
var tot = Math.min((from.length && (from.length - offset)) || (from.available && from.available()), maxN) + offset;
for(var i = offset; i < tot; i++){
to[i] = String.fromCharCode(from[i]);
}
return tot - offset;
};
@shadybones
shadybones / ContentPolicy.jsm
Last active December 23, 2015 23:09
Firefox Module barebones view of the required code for a ContentPolicy implementation. nsIContentPolicy
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
var EXPORTED_SYMBOLS = ["ContentPolicy"];
var ContentPolicy = {
classDescription: "Third Party Filtering", //some description
classID: Components.ID("dabef210-7f6b-11e0-b278-0800200c9a66"), //UUID. Generated using UUID tool.
contractID: "@${app_name}/filter/thirdparty;1", //structure: "@${app_name}/${generic_descriptor}/${name};1"
QueryInterface: XPCOMUtils.generateQI(
[ Components.interfaces.nsIContentPolicy,
Components.interfaces.nsIObserver,
Components.interfaces.nsIChannelEventSink,