Categories
Coding

JavaScript keypress detection script

Method 1

Detect = {};
Detect.keydown = function(k) {
    var oEvent = document.createEvent("KeyboardEvent");

    // Chromium Hack
    Object.defineProperty(oEvent, "keyCode", {
                get : function() {
                    return this.keyCodeVal;
                }
    });     
    Object.defineProperty(oEvent, "which", {
                get : function() {
                    return this.keyCodeVal;
                }
    });     

    if (oEvent.initKeyboardEvent) {
        oEvent.initKeyboardEvent("keydown", true, true, document.defaultView, true, false, false, false, k, k);
    } else {
        oEvent.initKeyEvent("keydown", true, true, document.defaultView, true, false, false, false, k, 0);
    }

    oEvent.keyCodeVal = k;

    if (oEvent.keyCode !== k) {
        alert("keyCode mismatch " + oEvent.keyCode + "(" + oEvent.which + ")");
    }

    document.dispatchEvent(oEvent);
}
Detect.keydown(65);

Method 2

document.dispatchEvent(new window.KeyboardEvent("keydown", {key: "a", char: "a", keyCode: 65, ctrlKey:false}));

Method 3

var e = jQuery.Event("keydown");
e.which = 65;       // # G code value
e.ctrlkey = false;     // control key pressed
jQuery(document).trigger(e);// trigger event on document
Categories
Coding

Javascript detect keycodes tool

Type a key on your keyboard to find the key code / keyboard code

Javascript code is :

Categories
Python

Python Virtual Environment Wrapper

$ pip install virtualenvwrapper
$ which virtualenvwrapper.sh
/usr/local/bin/virtualenvwrapper.sh

Adding path

$ export WORKON_HOME=$HOME/.virtualenvs   # Optional
$ export PROJECT_HOME=$HOME/projects      # Optional
$ source /usr/local/bin/virtualenvwrapper.sh

Reloading Shell

$ source ~/.bashrc
$ echo $WORKON_HOME
/Users/mervinpraison/.virtualenvs

Functions

$ mkvirtualenv my-new-project
(my-new-project) $

To stop using the environment

(my-new-project) $ deactivate
$
$ workon
my-new-project

To activate the environment

$ workon my-new-project

-p parameter to choose the Python Version

$ virtualenv -p $(which python3) blog_virtualenv
Categories
Google Analytics Uncategorized

Click Tracking [Google Analytics]

Event Tracking

<script>
/**
* Function that tracks a click on a link in Google Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var trackLink = function(url) {
   ga('send', 'event', 'link', 'click', url, {
     'transport': 'beacon',
     'hitCallback': function(){document.location = url;}
   });
}
</script>

On Page Implementation

<a href="http://www.example.com" onclick="trackLink('http://www.example.com'); return false;">Visit example.com</a>

 

Categories
Coding Uncategorized

Don’t use template_redirect always

Follow this link 

Don’t use template_redirect to load an alternative template file