JSFiddle

  • Input filter example

    Using a regex on the input event, so it will work on mobile devices that don't support keypress (looking at you, Chrome on Android!)

    var inp = document.getElementById('target');
    
    var findDisallowedEmailChars = /[^A-Za-z0-9@._]/g; // just a sample -- don't really use this!
    var maxLength ...
  • Heap's Algorithm

    Given an array, will generate every permutation

    // As the input gets longer, the output grows factorially: (n-1)!
    // Avoid long inputs
    var input = ['A','B','C','D','E ...
  • Gravyroids

    Asteroids... with gravity.

    // canvas basics
    var c = document.getElementById('canvas');
    var ctx = c.getContext('2d');
    var screenWidth = c.width;
    var screenHeight = c.height ...
  • Tiny sqrt

    Nothing clever

    
    
    function s(x){for(t=x/2,a=1,b=x,i=0;i++<32;t=a+(b-a)/2)t*t-x>0?b=t:(a=t);return ...</32;t=a+(b-a)/2)t*t-x>
  • Salsa20

    From https://gist.github.com/dchest/4126510

    // Note: this is for scrypt implementation, which doesn't use diagonal constants, 
    // so the order of loading from x is ...
  • simple encoding

    No-Library (pure JS), HTML, CSS, JavaScript

    // just for play
    
    var codeStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234789!*&@#";
    
    function make() {
    	var iter  = parseInt(document.getElementById("iter").value);
    	var base  = document.getElementById("base ...
  • BWT

    Burrows Wheeler Transform

    
    // this is the inefficient 'table building' way
    function BWT (str) {
      var data = str.split('');
      var len = data.length;
      var index ...
  • JavaScript: base64 encode and decode

    No-Library (pure JS), HTML, CSS, JavaScript

    var Base64 = {
    
    
        _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    
    
        encode: function(input) {
            var output = "";
            var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
            var i = 0 ...
  • SpeechSynth

    for play

    /*
    
    Simple formant speech synth.
    
    Based on http://heckmeck.de/demoscene/tiny-speech-synth-js/ (credits at bottom)
    Similar to the one at https ...
  • Day on date algorithm

    No-Library (pure JS), HTML, CSS, JavaScript

    var DayOfWeek=[
    	"Sunday",
    	"Monday",
    	"Tuesday",
    	"Wednesday",
    	"Thursday",
    	"Friday",
    	"Saturday"
    ]
    
    function GetDayOfWeek(year, month, day)
    {
    	var monthAdjust = [ 0, 3, 2, 5 ...