fresh-url: clean up URLs

Drop this script on your page and enjoy the freshest of URLs

Include this JavaScript at the bottom of your page:

<script src="//fast.wistia.net/labs/fresh-url/v1.js" async></script>

More:

  • Neat-URL
  • URL-Tracking-Stripper:  skipping tracking redirects and removing the tracking parameters from URLs to keep them short and cleaner for sharing, bookmarking, etc.  (trackers)
  • Link Cleaner : Unlike other legacy add-ons like CleanLinks, Link Cleaner doesn’t inject JavaScript into pages to change links. Instead, it listens to main url requests and changes them (if needed to remove redirects or tracking.

    That means it’s doing less unneeded work and consumes less resources (memory and CPU).

get URL Query params with jquery & js

// Assuming “?order=1&total=30”

While URLSearchParams is ideal, not all browsers support that API. There’s a polyfill available but if you want a tiny function for basic query string parsing, the following is a function stolen from the A-Frame VR toolkit which parses the query string to get the key’s value you’d like:

function getUrlParameter(name) {
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(location.search);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};

With the function above, you can get individual parameter values:

getUrlParameter('order'); // "1"

Converting Unicode in Python 3: from Character Code to Decimal

Given the Control Code column in the Wikipedia List of Unicode Characters:

 

Example 1: The Cent character

Code Glyph Decimal Description
U+0041 A 65 Latin Capital letter A

> Python Prompt:

> code = ‘0041’
>>> decimal = int(code,16)
>>> decimal
65
>>> chr(decimal)
‘A’

Example 2: The Cent character

Code Glyph Decimal Html Description
U+00A2 ¢ 0162 &cent; Cent sign          

> Python Prompt:

> code = ’00A2′
>>> decimal = int(code,16)
>>> decimal
162
>>> chr(decimal)
‘¢’

Example 3: The Greek Sigma character

Code Glyph Decimal Description
03A3 Σ 931 Greek Capital Letter Sigma

> Python Prompt

> code = ’03A3′
>>> decimal = int(code,16)
>>> decimal
931
>>> chr(decimal)
‘Σ’

Example 4: Soccer Ball

0 1 2 3 4 5 6 7 8 9 A B C D E F
U+26Bx

> Python Prompt:

> code = ’26BD’
>>> decimal = int(code,16)
>>> decimal
9917
>>> chr(decimal)
‘⚽’

Note: The Soccer ball did not display correctly in my Windows Shell, but rendered properly when I copied it into a Chrome WordPress textarea.

 

Example 5: Emoticons

1F60E 😎 smiling face with sunglasses

>>> code = ‘1F60E’
>>> decimal = int(code,16)
>>> decimal
128526
>>> chr(decimal)
‘😎’

Javascript: Audio play() Method

<!DOCTYPE html>
<html>
<body>

<audio id="myAudio">
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<p>Click the buttons to play or pause the audio.</p>

<button onclick="playAudio()" type="button">Play Audio</button>
<button onclick="pauseAudio()" type="button">Pause Audio</button> 

<script>
var x = document.getElementById("myAudio"); 

function playAudio() { 
  x.play(); 
} 

function pauseAudio() { 
  x.pause(); 
} 
</script>

</body>
</html>