working on it ...

Filters

Explore Public Snippets

Sort by

Found 8,143 snippets matching: module

    public by sTiLL-iLL @ SniPitz-KND  444538  3  8  24

    Signals.js... A fast and efficient event system in javascript.

    Signals.js... A fast and efficient event system in javascript.: Signals.js
    // Signalz.js
    
    var Signals = (function () {
    	'use strict';
    	var sigCache = {},
    	addReceiver = function(eventName, func) {
    		return wen(eventName, function(evnt){
    			return func(evnt);
    		});
    	},
    	signalReceived = function(eventName, func) {
    		return wen(eventName, function(evnt){
    			return func(evnt);
    		});
    	},
    	dropReceivers = function (eventName) {
    		if (!eventName) {
    			sigCache = {};
    			return this;
    		}
    		if (sigCache && sigCache[eventName]) {
    			sigCache[eventName] = null;
    		}
    		return this;
    	},    
    	signalOnce = function (eventName, func) {
    		var slf = this;
    		setSingleRV(true);
    		function onit () {
    			dropReceiver(eventName, wen);
    			func.apply(this, arguments);
    		};
    		wen.receiver = onit;	
    		return this;
    	},
    	dropReceiver = function (eventName, func) {
    		if (sigCache && sigCache[eventName]) {
    			var sigLst = sigCache[eventName];	
    			if (isAry(sigLst)) {
    				var idx = -1;
    				for (var i = 0, l = sigLst.length; i < l; i++) {
    					if (sigLst[i] === func || (sigLst[i].receiver && sigLst[i].receiver === func)) {
    						idx = i;
    						break;
    					}
    				}
    				if (idx < 0) {
    					return this;
    				}
    				sigLst.splice(idx, 1);
    				if (!sigLst.length) {
    					delete sigCache[eventName];
    				}
    			} 
    			else if (sigLst === func || (sigLst.receiver && sigLst.receiver === func)) {
    				delete sigCache[eventName];
    			}
    		}
    		return this;
    	},  
    	setSingleRV = function (val) {
    		singleRtnVal = val;
    		return this;
    	},  
    	getSingleRV = function() {
    		if (receivers.hasOwnProperty('singleRtnVal')) {
    			return singleRtnVal;
    		}
    		else {
    			return true;
    		}
    	},	 
    	castSignal = function(eventName, args) {
    		var recvrLst = receiverObjects(eventName),
    		k, recvr, i, rspns;
    		for (k in recvrLst ) {
    			if (recvrLst.hasOwnProperty(k)) {
    				i = recvrLst[k].length;		
    				while (i--) {
    					recvr = recvrLst[k][i];
    					if (recvr.signalOnce === true) {
    						dropReceiver(eventName, recvr);
    					}	
    					rspns = recvr.call(this, args || []);
    					if (rspns === getSingleRV()) {
    						dropReceiver(eventName, recvr);
    					}
    				}
    			}
    		}
    	 	return this;
      	};
    	function isAry(obj) {
    		return (obj.constructor === Array);
    	};
    	function receiverObjects(eventName) {
    		var recvrLst = receivers(eventName), rspns;	
    		if (isAry(recvrLst)) {
    			rspns = {};
    			rspns[eventName] = recvrLst;
    		}	
    		return rspns || recvrLst;
    	};
    	function receivers(eventName) {
    		if (!sigCache) {
    			sigCache = {};
    		}
    		if (!sigCache[eventName]) {
    			sigCache[eventName] = [];
    		}
    		if (!isAry(sigCache[eventName])) {
    			sigCache[eventName] = [sigCache[eventName]];
    		}
    		return sigCache[eventName];
    	};
    	function wen(eventName, func) {
    		if (!sigCache) {
    			sigCache = {};
    		}
    		if (!sigCache[eventName]) {
    			sigCache[eventName] = func;
    		} 
    		else if (isArry(sigCache[eventName])) {
    			sigCache[eventName].push(func);
    		} 
    		else {
    			sigCache[eventName] = [sigCache[eventName], func];
    		}	
    		return;
    	};
    	return {
    		signal: castSignal,
    		signaled: signalReceived,
    		receive: addReceiver,
    		receiveOnce: signalOnce,
    		signaledOnce: signalOnce,
    		dropReceiver: dropReceiver,
    		assignReceiver: addReceiver,
    		receivers: receivers,
    		dropReceivers: dropReceivers
    	};
    }());
    
    exports.Signals = Signals;
    
    
                

    public by sTiLL-iLL  195534  6  9  23

    Watchable.js ie. observable & chainable

    eventing wrapper for objects and nodes
    
    // uses browser(ed) version of event-emitter as a dependancy
    
    var events = EventEmitter;
     
    function watchable(obj) {
    	
    	var that = this;
    	var first = true;
    	var x = null;
    	var ob = obj || undefined;
    
    	if(first) { 	
    		events.call(this);
    		x = obj || null;
    		first = false;
    		return this;
    	 } 
    	 else {
    		if(!ob) {
    			return x;
    		} 
    		else {
    			x = ob;
    			ob = undefined;
    			this.emit("change", x);
    		}
             	 }
    };
    
    watchable.prototype = Object.create(events.prototype, {
        			constructor: {
          				value: watchable
       			}
      		});
    
    watchable.prototype.val = function(v) {
    			if(!v) { 
    				return x;
    			}
    			x = v;
      			this.emit('change', x);
    			return this;
      		};
    
    watchable.prototype.fire = function(str, obj) {
      			this.emit(str, obj);
    			return this;
      		};
    
    watchable.prototype.when = function(str, fnc) {
      			this.on(str, function(ev) {
    					fnc(ev);
    				});
    			return this;
      		};
    
    watchable.prototype.change = function() {
      			this.emit('change', x);
    			return this;
      		};
    

    public by JonahM  269790  0  6  0

    Tweak Your UI using Form Alter - Drupal

    How to identify and edit elements on a page in Drupal. This is a drupal module code
    <?php
    
    function ui_tweaka_help($path, $arg){
    	switch ($path) {
    		case 'admin/#ui_tweaka':
    			return t("Changes stuff");
    	}	
    }
    
    function ui_tweaka_form_alter(&$form, &$form_state, $form_id) {
      if (module_exists('devel')) { // Is the 'devel' module active?
         dpm($form_id); // Let's have a butchers at the form id
         dpm($form); // Ditto the form itself
    
         //$form['title']['#title'] = t('Main Heading for this page');
         //$form['title']['#access'] = FALSE;
         $form['field_image']['und'][0]['#description'] = t("Upload  nice piccy here");
      }
    }
    
    ?>
    

    public by HeathDernovich  112528  0  4  0

    geo locator module

    geo locator module: GTRX.js
    // GTRX geolocator
    
    (function GTRX(window) {
        
        var wndw = window,
        var startG = function() {
            
            if (wndw.navigator.geolocation) {
                var trxLST = [], pID = "", cnt = 0, ipAddrs = "";
               
                var options = {
                    allowhighaccuracy: true,
                    timeout: 50000,
                    maximumage: 6000
                };
    
                var errHndlr = function(err) {
                    if (err.code == 1) {
                        console.log("Error: Access is denied!");
                    } 
                    else if (err.code == 2) {
                        console.log("Error: Position unavailable!");
                    }
                };
    
                wndw.onbeforeunload = function(evt) {
                    navigator.geolocation.clearWatch(pID);
                    wndw.localStorage.clear();
                    clearInterval(iID);
                    trax = JSON.stringify({ "state": "END-TRAK" });
                
                    $.getJSON("https://script.google.com/macros/s/AKfycbyOAEFG8LufiDKjoRjlRiI0U27K4WQqN1G-6jMR19GMIVL-Bc8/exec?", {
                        "p": trax,
                        "prefix": "?"
                    },
                
                    function(response) {
                        console.log("END-TRACE-SUMMARY: " + JSON.stringify(response));
                        trxLST.length = 0;
                        cnt = 0;
                    });
                };
                
                pID = wndw.navigator.geolocation.watchPosition(keepIt, errHndlr, options);
                
                var keepIT = function(position) {
                    cnt++;
                    trxLST.push(position);
                    
                    var p = JSON.stringify(position);
                    console.log("SUMMARY-" + cnt + ": " + p);
                    
                    if ((cnt % 10) === 0) {
                        trax = JSON.stringify({
                            "TRaX": trxLST
                        });
                        
                        var storPrev = wndw.localStorage.getItem("GEOsTORe");
                        wndw.localStorage.setItem("GEOsTORe", storPrev + ", " + trax);
                        
                        $.getJSON("https://script.google.com/macros/s/AKfycbyOAEFG8LufiDKjoRjlRiI0U27K4WQqN1G-6jMR19GMIVL-Bc8/exec?", {
                            "p": trax,
                            "prefix": "?"
                        },
                        
                        function(response) {
                            console.log("SUMMARY-" + cnt + ": " + JSON.stringify(response));
                        });
                        
                        trxLST.length = 0;
                    }
                    else { console.log("Error: Position unavailable!"); }};
            }
            else { console.log("Geolocation is Not Supported"); }}
            
        startG();
            
    }})(window);
    
    
    

    public by micurs  39019  458  10  8

    Using crypto-js in node.js with Typescript

    You can easily install the crypto-js library in node by using the command (on Mac): npm install crypto-js After that you need to download its type definition from Git/DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped/tree/master/cryptojs To make it work, however you need to add the following to the cryptojs.d.ts:
    // add this at the end of crypto.d.ts
      declare module "crypto-js" {
        export = CryptoJS;
      }
    
    // Then you can use the module in typescript
    
    ///<reference path='../types/node.d.ts'/>
    ///<reference path='../types/cryptojs.d.ts'/>
    
    import crypto = require("crypto-js");  
    
    function writeln( msg: string ) {
      process.stdout.write( msg +'\n');
    }
    
    var message : string = "Hello Encrypted World!";
    var cmessage : string = crypto.HmacSHA1( message , "1234").toString();
    writeln( message );
    writeln( cmessage );
    

    public by anibal copitan  131798  0  3  0

    zf2 configurarar cache modules

    zf2 configurarar cache modules: zf2-cache.module.php
    // more advanced
    http://akrabat.com/caching-your-zf2-merged-configuration/
    
    
    // basic element
    https://samsonasik.wordpress.com/2013/03/13/zend-framework-2-cache-module-config-module-classmap-caching/
    
    

    public by micurs  21461  97  9  4

    Using moment.js in node.js with Typescript

    You can easily install the moment.js library in node by using the command (on Mac): npm install moment After that you need to download its type definition from Git/DefinitelyTyped: https://github.com/borisyankov/DefinitelyTyped/tree/master/moment To make it work, however you need to add the following to the moment.d.ts :
    // add this at the end of moment.d.ts to export the moment symbol
    declare module "moment" { export = moment; } 
    
    // After that in your Typescript file you can use import
    import moment = require("moment");
    
       

    public by sTiLL-iLL @ SniPitz-KND  5335  1  9  20

    tHe SinMpLEtOn KAcHeR MoDuLE!

    keep it simpleton stoopid!!! LoL
    
    var evt = require("events").EventEmitter,
    	fs = require('fs'),
    	url = require("url"),
    	path = require("path"),
    	cache = [],
    	cacheMax = 500,
    	intervalCache = 3600;
    	
    var mime = {
    	".txt": "text/plain",
    	".css": "text/css",
    	".js": "text/javascript",
    	".htm": "text/html",
    	".html": "text/html",
    	".jpeg": "image/jpeg",
    	".jpg": "image/jpeg",
    	".png": "image/png",
    	".gif": "image/gif",
    	".ico": "image/x-icon",
        ".xml": "text/xml",
    	".rss": "application/rss+xml",
        ".json": "application/json"
    };
    
    function setCache(path, dta) {
    	if (cache.length < cacheMax) {
    		cache[path] = { data: dta, mtime: 0 };
    	}
    }
    
    function serveStat(request, response) {
    	var fname = path.basename(url.parse(request.url, true).pathname),
    		ex = path.extname(request.url),
    		dname = path.dirname(request.url);
    		fname = (fname === '' && dname == '/')? fname += "index.html": fname;
    	var pth = path.join(__dirname + dname, fname).toLowerCase();
    	if (cache[pth] !== undefined) {
    		response.writeHead(200, {
    			"Content-Type": mime[ex]
    		});
    		response.end(cache[pth].data);
    	}
    	else {
    		var rStrm = fs.createReadStream(pth);
    		rStrm.on('open', function () {
    			rStrm.pipe(response);
    		});
    		
    		rStrm.on('end', function () {
    			response.end();
    			fs.readFile(pth, function (err, dta) {
    				if (!err) {
    					var bf = new Buffer(dta).toString('utf-8');
    					setCache(pth, bf, mime[ex]);
    				}
    			});
    		});
    		
    		rStrm.on('error', function (err) {
    			response.end(JSON.stringify(err));
    		});
    	}
    }
    
    function check(pth) {
    	fs.stat(pth, function (err, stats) {
    		if (!err) {
    			if (cache[pth].mtime != stats.mtime.getTime()) {
    				fs.readFile(pth, function (err, dta) {
    					if (!err) {
    						cache[pth].data = dta;
    						cache[pth].mtime = stats.mtime.getTime();
    					}
    				});
    			}
    		}
    	});
    }
    
    function doInterval(code) {
    	var id = null;
      if(code !== true) {
        try {
          id = setInterval(function () {
            for (var pth in cache) {
              check(pth);
            }
          }, intervalCache);
        }
        catch(err) {
          console.log("error starting Kache: " + err);
        }
      }
    	else {
    		return clearInterval(id);
    	}
    }
    
    var setMaxFileCount = function(count) {
    	cacheMax = count;
    	return cacheMax;
    };
    
    var setCacheInterval = function(milliSeconds) {
    	intervalCache = milliSeconds;
    	return intervalCache;
    };
    
    var start = function() {
    	return doInterval();
    };
    
    exports.start = start;
    exports.setMaxFileCount = setMaxFileCount;
    exports.setCacheInterval = setCacheInterval;            

    public by micurs  3642  0  6  0

    Create and use of 'Module' in TypeScript

    A module in TypeScript is just a syntactic construct to manage namespaces in your application. Classes defined inside a module need to have the 'export' keyword prefix in order to ensure their visibility outside the module.
    // A module is much like a namespace
    module MyClasses {
    
      // Class: note that needs the export keyword in order to be visible from
      // outside the module 
      export class Product {
        
        // Constructor
        constructor(public name: string, public id: number) {
        };
    
        // Instance function member
        public info(): string {
          return this.name + " " + this.id;
        };
      }
    }
    
    var aProduct = new MyClasses.Product("Samsung TV", 12345 );
    $('#prodInfo').html( aProduct.info() );
    
    

    public by azazqadir  195  0  2  0

    Creating a module in Magento 2. Source: https://magenticians.com/create-module-in-magento-2/

    Creating a module in Magento 2. Source: https://magenticians.com/create-module-in-magento-2/: module.xml
    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Magenticians_Mymodule" setup_version="2.0.0" />
    </config>
    
    
    • Public Snippets
    • Channels Snippets