Thursday, 21 March 2019

Microcode for a SWAP Reg0, Reg1 (3 Clock Cycles)




For those wanted to extend their instruction set - without adding too much complexity to microcode instructions - a SWAP instruction, where two registers are swapped over - can be implemented in 3 clock cycles just by using a series of 3 exclusive-or operations between the two registers. I'm assuming that 'setting a register' is done on the opposing edge of the exclusive-or operation. We can achieve a swap with the following microcode instructions. SWAP A, B A <- A XOR B CLK 1 B <- A XOR B CLK 2 A <- A XOR B CLK 3 For example, if we start off with the two registers A and B A = 3, B = 32 CLK 0 A = 35, B = 32 CLK 1 A = 35, B = 3 CLK 2 A = 32, B = 3 CLK 3 I hope - someone finds this helpful!

Sunday, 17 March 2019

Git Cheat Sheet

git init   # initialise directory for git repos
git status # tells user what possible files need to be 'added' or what files have changed.
git add . # add all files
git add filename1 filename2 # add numerous files to git 'staging area'
git log # show log of commits with their hash codes


git diff filename # to find out difference between working directory and last commit in staging directory
git checkout filename # to revert back a particular commit (last commit ) COMPARE THIS TO BRANCH CREATION

git checkout -b branchname #

git remote add origin https://github.com/johnny/myproject.git
#git remote add <REMOTE> GIT_URL
git remote -v # check settings

git push -u origin master
git push -u <REMOTE> <BRANCH>


git clone https://github.com/johnny/myproject.git 

Sunday, 10 March 2019

BootStrap Grid layout - Base 12 System


<div class='row'>
    <div class='col' style='background-color:red; border: 1px solid;'>
        col
    </div>
    
    <div class='col' style='background-color:red; border: 1px solid;'>
       col
    </div>
</div>

<div class='row'>
    <div class='col-6' style='background-color:green; border: 1px solid;'>
        col-6
    </div>
    <div class='col-3' style='background-color:green; border: 1px solid;'>
        col-4
    </div>
    <div class='col-2' style='background-color:green; border: 1px solid;'>
        col-2
    </div>
    <div class='col-1' style='background-color:green; border: 1px solid;'>
        col-1
    </div>
</div>

<div class='row'>
    <div class='col-6' style='background-color:blue; border: 1px solid;'>
        col-6
    </div>
    <div class='col-6' style='background-color:blue; border: 1px solid;'>
        col-6
    </div>
</div>

<div class='row'>
    <div class='col-md-6' style='background-color:yellow; border: 1px solid;'>
        col-md-6
    </div>
    <div class='col-md-6' style='background-color:yellow; border: 1px solid;'>
        col-md-6
    </div>
    
</div>


<div class='row'>

    <div class='col-lg-3 col-md-4 col-sm-6' style='background-color:pink; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
    </div>

    <div class='col-lg-3 col-md-4 col-sm-6' style='background-color:pink; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
    </div>

    <div class='col-lg-3 col-md-4 col-sm-6' style='background-color:pink; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
    </div>

    <div class='col-lg-3 col-md-4 col-sm-6' style='background-color:pink; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
    </div>

</div>

<div class='row'>
    
 <div class='col-lg-2 col-md-3 col-sm-12' style='background-color:blue; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
 </div>
 <div class='col-lg-2 col-md-3 col-sm-12' style='background-color:blue; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
 </div>
  <div class='col-lg-2 col-md-3 col-sm-12' style='background-color:blue; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
 </div>
  <div class='col-lg-2 col-md-3 col-sm-12' style='background-color:blue; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
 </div>
  <div class='col-lg-2 col-md-3 col-sm-12' style='background-color:blue; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
 </div>
  <div class='col-lg-2 col-md-3 col-sm-12' style='background-color:blue; border: 1px solid;'>
        col-lg-3 col-md-4 col-sm-6
 </div>
</div>

Thursday, 7 March 2019

CSS 'position' property

DOCTYPE html>
<html lang="en" dir="ltr">

  <head>
    <meta charset="utf-8">
    <title>Colour Block Alignment with absolute position</title>
    <script>
      var t = 0 ;
      var refresh = 24 ;
      var freq = 0.33 ;
      var radius = 80 ;
      var centre_x = 180 ;
      var centre_y = 180 ;

      function onLoad() {

        window.setInterval(function(){

          var el = document.getElementById('animate-block');
          el.style.backgroundColor = "green";

          var y = centre_y + radius * Math.sin(6.3 * freq * t) ;
          var x = centre_x + radius * Math.cos(6.3 * freq * t) ;

          el.style.top = y + 'px' ;
          el.style.left = x + 'px' ;

          t += (refresh/1000)
          console.log('t = ' + t) ;

        }, refresh);
      }

    </script>
  </head>

  <body onload="onLoad()">

    <div class='middle_container' style="background-color: purple; width:200px; height:300px;">
        middle container
    </div>

    <div class='colourblocktest' id='animate-block' style="z-index: -1; background-color: green; width:300px; height:300px; position: absolute; left: 60px; top: 37px; ">

      <div class='red' style="background-color: red; width:100px; height:100px; position: absolute; left: 200px; top: 200px">
      </div>

      <div class='blue' style="background-color: blue; width:100px; height:100px;position: absolute; left: 100px; top: 100px">
      </div>

      <div class='yellow' style="background-color: yellow; width:100px; height:100px;position: absolute; left: 0px; top: 0px">
      </div>

    </div>


  </body>
</html>

Monday, 4 March 2019

Crude Permutations


import java.util.*;


public class Dynamic {


public int calls = 0;

public int depth = 0;

public HashMap<String,HashSet<String> > cache = new HashMap<>();

public boolean cacheCheck = true;

public HashSet<String> preIndexList(String preIndexChr, HashSet<String> list) {

        // insert preindex char 'preIndexChr' to each element in list
        //System.out.printf("Pre Indexing with %s lst = %s",preIndexChr,list) ;
        HashSet<String> nList = new HashSet<>();
        for(String ele : list) {
                nList.add(preIndexChr + ele);
        }
        return nList;
}

// Depth

public HashSet<String> perm(String s,int dpth) {
        if (dpth > depth) {
                depth = dpth;
                //System.out.printf("Depth %d\n",depth) ;
        }
        if (cacheCheck && cache.containsKey(s)) {
                return cache.get(s);
        }

        calls++;


        HashSet<String> slst =  new HashSet<>();


        if (s.length() == 1) {

                slst.add(s);
                cache.put(s,slst);
                return slst;
        }

        for(int i = 0; i < s.length(); i++) {


                String left = s.substring(0,1);

                String right = s.substring(1);
                slst.addAll(preIndexList(left,perm(right,dpth++)));
                s = right + left;
        }
        cache.put(s,slst);
        return slst;

}


public String buildString(int size) {

        char [] ch = new char[size];
        for(int i = 0; i < size; i++) {
                ch[i] =  (char)(65 + i);
        }
        return new String(ch);
}
public static void main(String [] args) {
        for(int i = 1; i < 10; i++) {
                Dynamic d = new Dynamic();
                String s = d.buildString(i );
                HashSet<String> r = d.perm(s,0);
                //    System.out.printf("Perm of '%s' size = %d (built with %d calls)\nLIST %s\n",s,r.size(),d.calls,r) ;
                //System.out.printf("Size of HashMap %d\n",d.cache.size()) ;
                //System.out.printf("Perm of '%s' size = %d (built with %d calls)\n",s,r.size(),d.calls) ;
                // number of Calls can be expressed as recurance relation.
                // Kn = n * Kn-1 +  1
                System.out.printf("'%s' string size = %d list size = %d calls %d  depth %d\n",s,s.length(),r.size(),d.calls,d.depth);
                //System.out.printf("LIST %s",r) ;
        }
}

}


Friday, 1 March 2019

Docker Cheat List

# Swarm App Lifecycle

## Using Secrets With Local Docker Compose

docker node ls

docker-compose up -d

docker-compose exec psql cat /run/secrets/psql_user

docker-compose 11

pcat docker-compose.yml

## Full App Lifecycle: Dev, Build and Deploy With a Single Compose Design

docker-compose up -d

docker inspect TAB COMPLETION

docker-compose down

docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d

docker inspect TAB COMPLETION

docker-compose -f docker-compose.yml -f docker-compose.prod.yml config --help

docker-compose -f docker-compose.yml -f docker-compose.prod.yml config

docker-compose -f docker-compose.yml -f docker-compose.prod.yml config > output.yml

## Service Updates: Changing Things In Flight

docker service create -p 8088:80 --name web nginx:1.13.7

docker service ls

docker service scale web=5

docker service update --image nginx:1.13.6 web

docker service update --publish-rm 8088 --publish-add 9090:80

docker service update --force web

## Healthchecks in Dockerfiles

docker container run --name p1 -d postgres

docker container ls

docker container run --name p2 -d --health-cmd="pg_isready -U postgres || exit 1" postgres

docker container ls

docker container inspect p2

docker service create --name p1 postgres

docker service create --name p2 --health-cmd="pg_isready -U postgres || exit 1" postgres