working on it ...

Filters

Explore Public Snippets

Sort by

Found 276 snippets matching: modular

    public by sTiLL-iLL @ SniPitz-KND  378532  6  9  29

    set.js... its my "Set", it runs this code-block

    Full on structure type implimentation of a Set
    
    // Set....   hut-1, hut-2, hike!
    
    function Set() {
       this.dStr = [];
       this.size = size;
       this.unionOf = unionOf;
       this.contains = contains;
       this.subSet = subSet;
       this.getDiff = getDiff;
       this.removeItem = removeItem;
       this.intersection = intersection;
       this.addItem = addItem;
       this.show = show;
    }
    
    function show() {
       return "[" + this.dStr + "]";
    }
    
    function size() {
       return this.dStr.length;
    }
    
    
    
    function addItem(dta) {
       if (this.dStr.indexOf(dta) < 0) {
          this.dStr.push(dta);
          return true;
       } 
       else {
          return false;
       }
    }
    
    function removeItem(dta) {
       var pstn = this.dStr.indexOf(dta);
       if (pstn > -1) {
          this.dStr.splice(pstn, 1);
          return true;
       }
       else {
          return false;
       }
    }
    
    function contains(dta) {
       if (this.dStr.indexOf(dta) > -1) {
          return true;
       }
       else {
          return false;
       }
    }
    
    function unionOf(set) {
       var tmp = new Set(),
           i = 0;
       for (;i < this.dStr.length; ++i) {
          tmp.add(this.dStr[i]);
       }
       i = 0;
       for (;i < set.dStr.length; ++i) {
          if (!tmp.contains(set.dStr[i])) {
             tmp.dStr.push(set.dStr[i]);
          }
       }
       return tmp;
    }
    
    function intersection(set) {
       var tSet = new Set();
       for (var i = 0; i < this.dStr.length; ++i) {
          if (set.contains(this.dStr[i])) {
             tSet.add(this.dStr[i]);
          }
       }
       return tmp;
    }
    
    function subSet(set) {
       if (this.size() > set.size()) {
          return false;
       }
       else {
          for each (var m in this.dStr) {
             if (!set.contains(m)) {
                return false;
             }
          }
       }
       return true;
    }
    i = 0;
    function difference(set) {
       var tmp = new Set();
       for (;i < this.dStor.length; ++i) {
          if (!set.contains(this.dStor[i])) {
             tmp.add(this.dStor[i]);
          }
       }
       return tmp;
    }  
    
    
    

    public by sTiLL-iLL  203291  1  8  27

    kWetntz.js ... next in line please...

    sequential async execution... NEXT!!! *** idk if this even werks, havent tried yet! ***
    //  sequential execution....
    
    var kWentz = (function() {
        var roster = {}, lastTime = {}, slf = this,
            signal = function(name, arg) {
               var idx=0, kall = {};
               if(roster[name]) {
                   for(idx; kall=roster[name][idx]; idx++) {
                       kall(arg);
                   }
               }
            },
            receive = function(name, receiver) {
               if(!roster[name]) {
                  roster[name] = [];
               }
               roster[name].push(receiver);
               return slf;
            },
            drop = function(name, receiver) {
               if(roster[name]) {
                   var lst = [], kall = {}, idx = 0;
                   for(idx; kall=roster[name][idx]; idx++) {
                       if(kall !== receiver) {
                           lst.push(kall);
                       }
                   }
                   roster[name] = lst;
               }
               return slf;
            },
            exec = function() {
              if(arguments.length > 0) {
                var cbks = [], kall = {}, elm = {}, idx = 0;
                for(idx; kall=arguments[idx]; idx++) {
                   cbks.push(kall);
                }
                elm = cbks.shift();
                if(typeof elm === 'function') {
                   elm(lastTime, function(dta) {
                         lastTime = dta;
                         exec.apply(slf, cbks);
                   });
                } 
                else if(typeof elm === 'object' && elm.length > 0) {
                   var kall = elm.shift(),
                      callBK = function(dta) {
                         lastTime = dta;
                         exec.apply(slf, cbks);
                      };
                   kall.apply(kall, elm.concat([callBK]));
                }
             } 
             else {
                  signal("done", lastTime);
             }
             return slf;
          };
          return {
              execute: exec,
              receive: receive,
              drop: drop
          };
    })();            

    public by marksimon232  4691  7  7  8

    Efficient ModExp for Cryptographic purpose in C

    How to implement an efficient routine to calculate the Modular exponentiation as stated in http://en.wikipedia.org/wiki/Modular_exponentiation.
    Using modular multiplication rules:
    i.e. A^2 mod C = (A * A) mod C = ((A mod C) * (A mod C)) mod C
    We can use this to calculate 7^256 mod 13 quickly
    7^1 mod 13 = 7
    7^2 mod 13 = (7^1 *7^1) mod 13 = (7^1 mod 13 * 7^1 mod 13) mod 13
    We can substitute our previous result for 7^1 mod 13 into this equation.
    7^2 mod 13 = (7 *7) mod 13 = 49 mod 13 = 10
    7^2 mod 13 = 10
    7^4 mod 13 = (7^2 *7^2) mod 13 = (7^2 mod 13 * 7^2 mod 13) mod 13
    We can substitute our previous result for 7^2 mod 13 into this equation.
    7^4 mod 13 = (10 * 10) mod 13 = 100 mod 13 = 9
    7^4 mod 13 = 9
    7^8 mod 13 = (7^4 * 7^4) mod 13 = (7^4 mod 13 * 7^4 mod 13) mod 13
    We can substitute our previous result for 7^4 mod 13 into this equation.
    7^8 mod 13 = (9 * 9) mod 13 = 81 mod 13 = 3
    7^8 mod 13 = 3
    We continue in this manner, substituting previous results into our equations.
    ...after 5 iterations we hit:
    7^256 mod 13 = (7^128 * 7^128) mod 13 = (7^128 mod 13 * 7^128 mod 13) mod 13
    7^256 mod 13 = (3 * 3) mod 13 = 9 mod 13 = 9
    7^256 mod 13 = 9
    This has given us a method to calculate A^B mod C quickly provided that B is a power of 2.
    However, we also need a method for fast modular exponentiation when B is not a power of 
    
    Let say.. How can we calculate A^B mod C quickly for any B ?
    => Step 1: Divide B into powers of 2 by writing it in binary
    Start at the rightmost digit, let k=0 and for each digit:
    
    If the digit is 1, we need a part for 2^k, otherwise we do not
    Add 1 to k, and move left to the next digit
    
    => Step 2: Calculate mod C of the powers of two ≤ B
    5^1 mod 19 = 5
    5^2 mod 19 = (5^1 * 5^1) mod 19 = (5^1 mod 19 * 5^1 mod 19) mod 19
    5^2 mod 19 = (5 * 5) mod 19 = 25 mod 19
    5^2 mod 19 = 6
    5^4 mod 19 = (5^2 * 5^2) mod 19 = (5^2 mod 19 * 5^2 mod 19) mod 19
    5^4 mod 19 = (6 * 6) mod 19 = 36 mod 19
    5^4 mod 19 = 17
    5^8 mod 19 = (5^4 * 5^4) mod 19 = (5^4 mod 19 * 5^4 mod 19) mod 19
    5^8 mod 19 = (17 * 17) mod 19 = 289 mod 19
    5^8 mod 19 = 4
    5^16 mod 19 = (5^8 * 5^8) mod 19 = (5^8 mod 19 * 5^8 mod 19) mod 19
    5^16 mod 19 = (4 * 4) mod 19 = 16 mod 19
    5^16 mod 19 = 16
    5^32 mod 19 = (5^16 * 5^16) mod 19 = (5^16 mod 19 * 5^16 mod 19) mod 19
    5^32 mod 19 = (16 * 16) mod 19 = 256 mod 19
    5^32 mod 19 = 9
    5^64 mod 19 = (5^32 * 5^32) mod 19 = (5^32 mod 19 * 5^32 mod 19) mod 19
    5^64 mod 19 = (9 * 9) mod 19 = 81 mod 19
    5^64 mod 19 = 5
    
    => Step 3: Use modular multiplication properties to combine the calculated mod C values
    5^117 mod 19 = ( 5^1 * 5^4 * 5^16 * 5^32 * 5^64) mod 19
    5^117 mod 19 = ( 5^1 mod 19 * 5^4 mod 19 * 5^16 mod 19 * 5^32 mod 19 * 5^64 mod 19) mod 19
    5^117 mod 19 = ( 5 * 17 * 16 * 9 * 5 ) mod 19
    5^117 mod 19 = 61200 mod 19 = 1
    5^117 mod 19 = 1
    
    Notes:
    More optimization techniques exist, but are outside the scope of this snippet. It should be noted that when we perform modular exponentiation in cryptography, it is not unusual to use exponents for B > 1000 bits.
    

    public by lbottaro  4271  1  6  2

    A simple IIFE and closure example in Javascript

    This snippet shows the beauty of Immediately Invoked Function Expression (IIFE) and closures in Javascript. Here we create a function and immediately invoke it. This is also known as 'self executing function'. With the syntax var car = (function(){...})(); we define the function and execute it at the same time. Closure instead allows develop
    var car=(function(){
    	var _name='Ferrari GTO'; 
    	return {
    		getName: function(){
    			return _name;
    		}
    	}
    })(); //function created and invoked
    
    console.log(car.getName()); //Ferrari GTO

    public by geertjanwielenga  3160  1  6  2

    Require.js Knockout.js

    How to wire up a Knockout.js application with Require.js for modularity.
    require.config({
        baseUrl: './',
        paths: {
            knockout: './bower_components/knockout/dist/knockout',
            text: './bower_components/requirejs-text/text',
            jquery: './bower_components/jquery/dist/jquery',
            initComponents: './js/initComponents'
        },
        waitSeconds: 2
    });
    require(['knockout', 'initComponents'],
        function (ko, initComponents) {
            ko.applyBindings(new initComponents());
        }
    );

    external by Zhouzi  40161  0  3  0

    Modular scale for font sizing with power math function

    Modular scale for font sizing with power math function: ms.scss
    // http://www.modularscale.com/
    // http://webdesign.tutsplus.com/articles/how-to-establish-a-modular-typographic-scale--webdesign-14927
    @function pow ($x, $n) {
      $ret: 1;
    
      @if $n >= 0 {
        @for $i from 1 through $n {
          $ret: $ret * $x;
        }
      } @else {
        @for $i from $n through 1 {
          $ret: $ret / $x;
        }
      }
    
      @return $ret;
    }
    
    @function ms ($ratio: 1.618, $base, $n) {
      @return pow($ratio, $n) * $base;
    }
    
    

    external by Ian Rose  687  1  3  0

    A typographic base that uses Compass's 0.13.alpha Vertical Rhythm and TeamSass's Modular Scale https://github.com/Team-Sass/modular-scale. Heavily inspired and built on Eric Meyer's example: https://gist.github.com/ericam/3601836

    A typographic base that uses Compass's 0.13.alpha Vertical Rhythm and TeamSass's Modular Scale https://github.com/Team-Sass/modular-scale. Heavily inspired and built on Eric Meyer's example: https://gist.github.com/ericam/3601836: typography.scss
    //Font Families
    // -------------------------------------
    $primary-font-regular: 'proxima_nova_rgregular', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    $primary-font-italic: 'proxima_novaregular_italic', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    $primary-font-semibold: 'proxima_nova_ltsemibold', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    $primary-font-semibold-italic: 'proxima_novasemibold_italic', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    $primary-font-bold: 'proxima_nova_rgbold', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    $primary-font-bold-italic: 'proxima_novabold_italic', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    $secondary-font: Georgia, Times, 'Times New Roman', serif;
    
    // Modular Scale Settings https://gist.github.com/ericam/3601836
    // -------------------------------------
    $ratio: major-third() fifth();
    $base-size: 16px;
    
    // Modular Scale Genereated Values
    // -------------------------------------
    $normpx : $base-size;
    $medpx : ms(1);
    $smallpx : ms(-1);
    $xsmallpx : ms(-2);
    $xxsmallpx : ms(-3);
    $xxxsmallpx : ms(-4);
    $largepx : ms(2);
    $xlargepx : ms(3);
    $xxlargepx : ms(5);
    $xxxlargepx : ms(8);
    //Uncomment the mixin below to have Terminal list out the Pixel values that are being genereated.
    //@include ms-list();
    
    //Vertical Rhythm Settings
    // -------------------------------------
    $base-font-size: $base-size;
    $base-line-height: $xxxsmallpx;//A smaller initial base line height allows for finer control over spacing between elements in layout.
    $rhythm-unit: 'rem';
    $rem-with-px-fallback: true;//Whether to output fallback values in px when using rem as the rhythm-unit.
    $round-to-nearest-half-line: false;
    
    @include establish-baseline();
    
    html {
      color: $primary-dark;
    	font-family: $primary-font-regular;
    	@include adjust-leading-to(3);//Takes our nice small base line value and sets the line-height of all text to a nice minimum. http://atendesigngroup.com/blog/vertical-rhythm-compass
    }
    
    h1 {
    	@include adjust-font-size-to($xxxlargepx);
    	@include margin-trailer(2);//Used over and over again to provide an example of a way to use margin-trailer
    }
    
    h2 {
    	@include adjust-font-size-to($xxlargepx);
    	@include margin-trailer(2);
    }
    
    h3 {
    	@include adjust-font-size-to($largepx);
    	@include margin-trailer(2);
    }
    	
    h4 {
    	@include adjust-font-size-to($medpx);
    	@include margin-trailer(2);
    }
    	
    h5 {
    	@include adjust-font-size-to($normpx);
    	@include margin-trailer(2);
    }
    
    h6 {
    	@include adjust-font-size-to($smallpx);
    	@include margin-trailer(2);
    }
    
    p, pre, label {
    	@include adjust-font-size-to($normpx);
    	@include margin-trailer(2);
    }
    
    hr { 
    	border: 0; 
    	height: 0;
    	margin: 0;
    	@include trailing-border;
    	@include margin-trailer(2);
    }
    
    ol, ul, dl {
    	@include margin-trailer(2);
    }
    
    li {
    	line-height: auto;
    }
    
    ul {
    	@include unordered-inside;//Custom mixin
    }
    
    ol {
    	@include ordered-inside;//Custom mixin
    }
    
    strong, b {
    	font-weight: bold;
    }
    
    em, i , q {
    	font-style: italic;
    }
    
    pre {
    	white-space: pre;
    	overflow: auto;
    }
    
    code {
    	white-space: pre;
    	font-family: monospace;
    }
    
    

    external by tedw  316  0  3  0

    Modular Scale Ratios - https://github.com/Team-Sass/modular-scale

    Modular Scale Ratios - https://github.com/Team-Sass/modular-scale: modular-scale-ratios.scss
    // Golden ratio
    $phi              : 1.618034          ;
    $golden           : $phi              ;
    
    $double-octave    : 4                 ;
    $major-twelfth    : 3                 ;
    $major-eleventh   : 2.666666667       ;
    $major-tenth      : 2.5               ;
    $octave           : 2                 ;
    $major-seventh    : 1.875             ;
    $minor-seventh    : 1.777777778       ;
    $major-sixth      : 1.666666667       ;
    $minor-sixth      : 1.6               ;
    $fifth            : 1.5               ;
    $augmented-fourth : 1.41421           ;
    $fourth           : 1.333333333       ;
    $major-third      : 1.25              ;
    $minor-third      : 1.2               ;
    $major-second     : 1.125             ;
    $minor-second     : 1.066666667       ;
    
    
    

    external by Github  91  0  1  0

    I'm on holiday <a href=" http://www.petstrawerving.nl/writing-a-literary-analysis-essay#baron ">high school experience essay</a> Jaguar says the C-X17 is a design study that showcases its new modular aluminium architecture and that it illustrates the ...

    I'm on holiday high school experience essay Jaguar says the C-X17 is a design study that showcases its new modular aluminium architecture and that it illustrates the diversity of vehicles that could be produced with it. The new platform is expected to form the basis for a new compact saloon that will be a rival for the BMW 3-Series, the next XF, a
    I'm on holiday <a href=" http://www.petstrawerving.nl/writing-a-literary-analysis-essay#baron ">high school experience essay</a>  Jaguar says the C-X17 is a design study that showcases its new modular aluminium architecture and that it illustrates the diversity of vehicles that could be produced with it. The new platform is expected to form the basis for a new compact saloon that will be a rival for the BMW 3-Series, the next XF, and an SUV that is likely to closely resemble the C-X17.
     
    
    

    external by Hubert Kario  68  0  1  0

    Calculate size of groups in modular exponentiation

    Calculate size of groups in modular exponentiation: groups.py
    from __future__ import print_function
    import sys
    import getopt
    import math
    
    g = None
    m = None
    
    argv = sys.argv[1:]
    opts, args = getopt.getopt(argv, "m:")
    for opt, arg in opts:
        if opt == '-m':
            m = int(arg)
        else:
            raise Exception("Unrecognised option: {0}".format(opt))
    if args:
        raise Exception("Not matching options: {0}".format(args))
    
    if m < 1:
        raise Exception("Must specify -m, must be positive integer")
    
    print("Groups modulo {0}".format(m))
    for g in range(m):
        group_el = []
        for e in range(m+1):
            val = pow(g, e, m)
            if val in group_el:
                break
            group_el.append(val)
        print('g: {0:>{width}}, {1}'.format(g, group_el,
                                            width=int(math.ceil(math.log10(m)))))
    
    
    • Public Snippets
    • Channels Snippets