Skip to content

Instantly share code, notes, and snippets.

View 7LayersDesign's full-sized avatar

Andy Hutchins 7LayersDesign

View GitHub Profile
@7LayersDesign
7LayersDesign / appendAutoSlot.js
Created August 12, 2014 16:12
appendAutoSlot update.
/**
* Append a special DFP bigbox slot that will update at set interval automatically. The interval is controlled by
* ad operations using the global config file
* @param {string} target ID of element that slot is appended to.
* @return {string} The new slot name.
*/
api.appendAutoSlot = function(target){
if( typeof(target) !== "string" ){
throw new SniAds.SniAdsError("Invalid argument: target value must be a string.");
}
@7LayersDesign
7LayersDesign / sniads.ready.js
Created July 24, 2014 19:29
SniAds.ready example.
// Delay initialization of the gallery module until library is ready.
var galleryCfg = {foo:bar}; // Gallery settings
SniAds.ready(function(){
// You can put any code in here
SniAds.Gallery.init(galleryCfg);
});
@7LayersDesign
7LayersDesign / apicopy.js
Created July 17, 2014 17:49
Copy SniAds API methods and Submodules to clipboard.
// Copy all public methods and modules to clipboard
var api = [];
for( var method in SniAds ){
if(SniAds.hasOwnProperty(method) ){
api.push(method);
}
copy(api)
}
<!-- Current bigbox code -->
<div id="bigbox">
<script>
if(typeof mdManager != "undefined"){
BigboxAd(5, mdManager.getParameterString("keyterm"));
} else {
BigboxAd(5);
}
</script>
</div>
@7LayersDesign
7LayersDesign / ads-descriptors.js
Created July 7, 2014 21:21
photo_descriptor idea.
var dfpAdDescriptors = [];
/**
* Photo Descriptor Configuration
*
* Each custom photo descriptor set as a item in the dfpAdDescriptors array and it an object with two propeties. The keys property is the set of page key-value pairs to match against. All keys must match for the descriptor to pass. The descriptor property is the data itself. When setting up, the keys should be as specific as possible to avoid un-desired matching.
*
* In cases where two or more blocks match on a page, the last matching block will be used.
*/
@7LayersDesign
7LayersDesign / 0_reuse_code.js
Created July 4, 2014 22:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@7LayersDesign
7LayersDesign / asyncload.js
Created June 25, 2014 22:34
sniads async load.
// Run the queued functions.
var SniAdsQueue = function() {
this.push = function() {
var method, methodParts;
for (var i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === "function") {
arguments[i]();
} else {
if( typeof(method) === "string" ){
// If method is string. Than we assume it is a submodule like 'Gallery.init'
@7LayersDesign
7LayersDesign / file_split.sh
Created June 24, 2014 19:28
Split file by lines.
split -l 10000 sourceFile.sql splitFilePart-
@7LayersDesign
7LayersDesign / randbetween.js
Last active August 29, 2015 14:02
Generate random integer betweek two values.
function(min, max){
return Math.floor(Math.random() * max) + min;
}
@7LayersDesign
7LayersDesign / console.save.js
Created June 6, 2014 17:55
Save console output to file and download immediately.
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'