Wednesday, 9 November 2016

Getting back to some java

Surprised I knocked this out very quickly for me, challenge 

https://www.reddit.com/r/dailyprogrammer/comments/5bn0b7/20161107_challenge_291_easy_goldilocks_bear/

package com.company;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<int[]> values = new ArrayList<>();

        String filePath = "someFile.txt";

        try {
            BufferedReader br = new BufferedReader(

            new FileReader(filePath));

            String currentLine;

            while ((currentLine = br.readLine()) != null) {
                int seatCapacity = Integer.parseInt(currentLine.

                substring(0, currentLine.indexOf(' ')));
                int temp = Integer.parseInt(currentLine.substring(currentLine.indexOf(' ') +1, currentLine.length()));
                values.add(new int[] {seatCapacity, temp});
            }

        } catch (IOException ex) {
            System.out.println();
        }

        StringBuilder suitableChairs = new StringBuilder();
        int weight =0, maxTemp =0;
        for (int i = 0; i < values.size(); i++) {
            if (i == 0) {
                weight = values.get(i)[0];

                maxTemp = values.get(i)[1];
            } else if (values.get(i)[0] >= weight && values.get(i)[1] <= maxTemp) {
                suitableChairs.append(i + " ");
            }
        }

        System.out.println(suitableChairs);
    }
}

Friday, 7 October 2016

Quality again

I am trying to cultivate an attitude of logical thinking and pragmatism, in the same way the main character in zen and the art of motorcycle maintenance fixes his bike by concentrating on quality, a job done properly. In the way he came across a washer which caused numerous problems which seemed unrelated, my car had a loose drive shaft bolt which caused the following errors, adaptive suspension unavailable, abs error, traction control error, stability service required. 

Due to poor workmanship from a main dealer, there is the below image.

two large bolts with one showing shiney threads where it has been cross threaded

The bolt on the right showing shiny threads where it has been cross threaded subsequently loosed due to vibration. I am not very mechanically inclined however applying a thought process of what I can see, what makes sense and applying the solution with patience worked well.

Monday, 3 October 2016

Learning linux

Surprisingly I've enjoyed learning a lot about BASH and some of the single use tools that just make things easy.

Editing multiple files at once, using vim, understanding what other people meant when they said ssh, making a patch file and installing packages to make it easy. Nice to also go over a lot of regex, on my list to learn but didn't really get until now. 

I have also done some minor scripting which was handy for downloading multiple files from usenet to check each file for integrity. Looked something like

for i in $(ls *1.par2); do par2 r $i; done;

Still a long way to scripting, compile, and remote admin. I am now a fan of no starch press books. 


On top of all of that I read Zen and art of motorcycle maintenance, which discusses in depth the idea of quality. To me the idea of quality came across as that happens when someone cares about what they are doing. Interesting ideas of being stuck the bolt which cannot be undone even with destruction as an option, that the bolt doesn't care it is what it is, that does not mean the problem is insurmountable. I have been there many times.

Sunday, 4 September 2016

Driver memory leak

An issue I've not before, machine starts to stutter, checking task manager memory usage is pinned at 99%. Sorting the processes by usage nothing untoward is shown. In the users tab it showed 4 gig for my user, so at least I knew it wasn't a process that belonged to me.

Informative posts that helped get to the bottom of it, 
Poolmon allowed me to see which processes where using the memory.

picture of text showing process NDNB trying to use 17 gig of ram

The big numbers in the seventh column point to NDNB. In cmd change the working directory to C:\Windows\System32\drivers and using find,
findstr /s NDNB. Resulting in a lot of garbage text with NDU.sys in the middle.

Solution from tomshardware

SOLUTION:
Windows Network Data Usage Monitoring Driver - Windows 8 Service

This service provides network data usage monitoring functionality.
This service exists in Windows 8 only.
Startup Type

Windows 8 edition without SP
Core Automatic
Professional Automatic
Enterprise Automatic
Default Properties

Display name: Windows Network Data Usage Monitoring Driver
Service name: Ndu
Type: kernel
Path: %WinDir%\system32\drivers\Ndu.sys
Error control: normal

Default Behavior

The Windows Network Data Usage Monitoring Driver service is a kernel mode driver. If the Windows Network Data Usage Monitoring Driver fails to start, the error is logged. Windows 8 startup proceeds, but a message box is displayed informing you that the Ndu service has failed to start.

To Fix Memory Leaks on Non-Paged-Pool:
Changed the registry value instead of using Autoruns:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Ndu

Change the Start value to 4 (for disable).


The only other issues I can see that are related to the memory leak are killer network drivers. Multiple reboots did not fix the issue. 

Monday, 27 June 2016

Challenge #272 [Easy] What's in the bag?

Another day another challenge, I need to program a lot more as at the moment all I have been doing is studying for the OCP exam, it is harder than I had anticipated with all the functional programming. As I had thought it would be similar to linq, perhaps the understanding was not there at the time. Either way I am not practicing enough and caught up in the what if I fail stuff.

User wins $10,000 due to botched forced Windows 10 upgrade.

Properly want an LED peggy board to make a flashing mooninite sign, it would change between Ignignokt and Err. 

YouTube 500 error that I actually experienced. 

500 error something went wrong with what appears to be a base 64 encoded string

And on to the challenge, I look it against the other examples on daily programmer, so I have a long way to go.

package com.company;

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Map<Character, Integer> fullBag = new HashMap<Character, Integer>() {{
   put('A', 9); put('B', 2); put('C', 2); put('D', 4); put('E', 12);
   put('F', 2); put('G', 3); put('H', 2); put('I', 9); put('J', 1);
   put('K', 1); put('L', 4); put('M', 2); put('N', 6); put('O', 8);
   put('P', 2); put('Q', 1); put('R', 6); put('S', 4); put('T', 6);
   put('U', 4); put('V', 2); put('W', 2); put('X', 1); put('Y', 2);
   put('Z', 1); put('_', 2);
        }};

        //String tilesToRemove = "PQAREIOURSTHGWIOAE_";
        String tilesToRemove = "LQTOONOEFFJZT";
        //String tilesToRemove = "AXHDRUIOR_XHJZUQEE";
        for (Character tile : tilesToRemove.toCharArray()) {
            if (fullBag.keySet().contains(tile)) {
                fullBag.put(tile, fullBag.get(tile) -1);
            }
        }

        boolean hasNegativeTiles = fullBag.values().stream().filter( x -> x < 0 ).limit(1).count() > 0;
        if (hasNegativeTiles) {
            List<Character> negativeTiles = new ArrayList<>();
            for (Character tile : fullBag.keySet()) {
                if (fullBag.get(tile) < 0) { negativeTiles.add(tile);}
            }
            System.out.println("Invalid input. More "
                    +  negativeTiles.toString().substring(1,  negativeTiles.toString().length()-1)
                    + " have been taken from the bag than possible.");
        } else {
            List<Character> charsNeeded;
            Map<Integer, List<Character>> filteredMap = 

              new HashMap<>();
            for (int i = 12; i >= 0; i-- ) {
                charsNeeded = new ArrayList<>();

                for (Character c : fullBag.keySet()) {
                    if (fullBag.get(c) == i) {
                        charsNeeded.add(c);
                    }
                }

                if (!charsNeeded.isEmpty()) {
                    filteredMap.put(i, charsNeeded);
                }
            }

            List<Integer> reversedList = new ArrayList<>(filteredMap.keySet());
            Collections.reverse(reversedList);
            for (Integer key : reversedList) {
                String collectionToPrint = filteredMap.get(key).toString();
                System.out.println(key + ":\t" + collectionToPrint.substring(1, collectionToPrint.length() -1));
            }
        }
    }
}

Monday, 13 June 2016

Passed Java OCA Programmer 1 1Z0-808!!!

Passed, it took a significant amount of work and hopefully I now have the confidence to build more of my own things. To avoid that I did a programming challenge. 

What did help on the exam is the enthuware tests, lots of unique questions with the tougher items having in depth descriptions. I liked the Jeanne Boyarsky and Scott Selikoff study guides, they do keep track of errata

Grey, white and red cover with the image of a light house for exam 1Z0-809

Having made a start, I am now thinking 3 months is optimistic if I am to include practice exams, jpassion, and other exam preparation. It is exciting as there are more interesting language features in the OCP exam, steams, lambdas, generics, and concurrency. They are a lot more fun than how many ways can the examiner confuse me with implicit type casting and chaining string methods.

I also need to keep my eye on the main goal of getting a job as a developer rather than just passing an exam, I have some ideas for my own projects.

There is a lot of doubt, as it is easy to give up where being a developer relies on patience, persistence, and methodical thought which if I am can get that down it would improve much more than my development career.

Pacman walk-through!

Challenge to transpose text, 

Dark coloured IDE showing solution and result of transpose




What I did notice from the solutions on reddit is that they are all different to each other including mine, although I do not agree with the solution using exceptions as program flow.

package com.company;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner keyboard = new Scanner(System.in);
        String line, EOF = "-1";
        List<String> lines = new ArrayList<>();
        boolean hasNextLine;

        do {
            line = keyboard.nextLine();
            hasNextLine = !line.equals(EOF);
            if (hasNextLine) {
                lines.add(line);
            }
        } while (hasNextLine);

        int rows = 0;
        for (String aline : lines) { 

            if (rows < aline.length()) rows = aline.length(); 
        }
        int cols = lines.size();

        char[][] charGrid = new char[rows][cols];
        for (char[] row : charGrid) {
            for( int i = 0; i < row.length; i++) { row[i] = ' '; }
        }

        for ( int i = 0; i < lines.size(); i++) {
            for (int j = 0; j < lines.get(i).length(); j++) {
                charGrid[j][i] = lines.get(i).charAt(j);
            }
        }

        for (char[] lineOfChars : charGrid) {
            System.out.println(new String(
lineOfChars));
        }
    }
}

Monday, 6 June 2016

Dodge viper parked on my street!

low sports car dodge viper side view orange with black wheels

back of low sports car dodge viper black wheels orange body

And after the excitement I have booked my Java OCA exam for Thursday July 7th, from the mocks it is looking good, some concern over how useful they will be however I would like something / someone else to say hey look this guy can do something. I do have some small ideas for programs to help build up even a small portfolio. Then again might get called on invert a binary tree or something. 

Been having some minor issues with VLC player moving off screen and windows key left right would not move it alt + space, then m, arrow keys to move the window to where you want.

TedX how to learn anything the first 20 hours.
 
Seems a shame most java developers are only really using catch statements for debugging and logging although recovery can be complicated. 

Good discussion on hacker news around two factor authentication and google, to be fair it is a social attack that has happened.

Free book on building problem solvers, added to the reading pile.