Pleased I knocked it out pretty quickly, possibly used too many variables but reads OK to me. Side note talking at work about hardest programming languages, I had brainfuck down as hard but Malbolge is another level of toughness.
package com.company;
import java.text.DecimalFormat;
public class XmasLights {
private final int hoursLightRequired;
private final int batteryCapacity = 1200;
private final int ledmA = 20;
private final double ledVoltage = 1.7;
private final int ledsPerCiruit = 5;
private final int batteryVoltage = 9;
public XmasLights(int hoursLightRequired) {
this.hoursLightRequired = hoursLightRequired;
}
public void go() {
int leds = amountOfLedsForTime();
resistanceNeeded();
drawCircuit(leds);
}
//part 1, input is the max amount of leds we can have for that time
public int amountOfLedsForTime() {
int maxLeds = (batteryCapacity / hoursLightRequired / ledmA) * ledsPerCiruit;
return maxLeds;
}
public void drawCircuit(int lights) {
String serialCircuit = "--|>|---|>|---|>|---|>|---|>|--";
String joiningBars = " | |";
System.out.println("Scheme:");
int ledsToDraw = lights / ledsPerCiruit;
for (int i = 0; i < ledsToDraw; i++) {
if (i == 0) {
System.out.println("*" + serialCircuit + "*");
} else {
System.out.println(serialCircuit);
}
if (i < ledsToDraw - 1) {
System.out.println(joiningBars);
}
}
}
public double resistanceNeeded() {
double voltageOverResister = batteryVoltage - (ledsPerCiruit * ledVoltage);
double ohms = voltageOverResister / (batteryCapacity / 1000d);
DecimalFormat df = new DecimalFormat("#.###");
System.out.println("Resistance needed: " + df.format(ohms));
return ohms;
}
}
Thursday, 24 December 2015
Tuesday, 22 December 2015
Lazyness
Fed up of writing to a text file everyday what I do in the day ready for tomorrow's scrum, from what I have read I can make a bat file put into windows start up folder and no more typing the same thing everyday.
It does need a couple of changes, keen to keep one file per year which then this program would create as needed once updated. It does seem a bit much on the try catch however I do not want to create new entries if I need to reboot during the work day.
Also seems strange to me that to add to the start of the file I need to write it all again.
package com.company;
import java.io.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* Created by R on 22/12/2015.
*/
public class diaryWriter {
private String path = "";
private LocalDate today = LocalDate.now();
private DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("dd-MM-yyy");
private String message;
public void writeMessageToDiary() {
message = today.format(formatter)
+ "\nTested"
+ "\nTest Cases"
+ "\nRaised"
+ "\nComplete"
+ "\nNotes"
+ "\n\n";
//Only write to file if not been written to today
if ( !isTodayLatest() ) {
prependMessageToFile();
}
}
private boolean isTodayLatest() {
String firstLine = "";
try (BufferedReader bufferedReader =
new BufferedReader(new FileReader(path))) {
firstLine = bufferedReader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return firstLine.equals(today.format(formatter));
}
private void prependMessageToFile() {
//Read file to a string
StringBuilder fileString = new StringBuilder();
String line;
try (BufferedReader bufferedReader =
new BufferedReader(new FileReader(path))) {
while ( (line = bufferedReader.readLine()) != null) {
fileString.append(line + "\n");
}
} catch (IOException e) {
e.getStackTrace();
}
//Write complete file back to path
try (BufferedWriter bufferedWriter =
new BufferedWriter(new FileWriter(path))){
bufferedWriter
.append(fileString.insert(0, message).toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
It does need a couple of changes, keen to keep one file per year which then this program would create as needed once updated. It does seem a bit much on the try catch however I do not want to create new entries if I need to reboot during the work day.
Also seems strange to me that to add to the start of the file I need to write it all again.
package com.company;
import java.io.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* Created by R on 22/12/2015.
*/
public class diaryWriter {
private String path = "";
private LocalDate today = LocalDate.now();
private DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("dd-MM-yyy");
private String message;
public void writeMessageToDiary() {
message = today.format(formatter)
+ "\nTested"
+ "\nTest Cases"
+ "\nRaised"
+ "\nComplete"
+ "\nNotes"
+ "\n\n";
//Only write to file if not been written to today
if ( !isTodayLatest() ) {
prependMessageToFile();
}
}
private boolean isTodayLatest() {
String firstLine = "";
try (BufferedReader bufferedReader =
new BufferedReader(new FileReader(path))) {
firstLine = bufferedReader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return firstLine.equals(today.format(formatter));
}
private void prependMessageToFile() {
//Read file to a string
StringBuilder fileString = new StringBuilder();
String line;
try (BufferedReader bufferedReader =
new BufferedReader(new FileReader(path))) {
while ( (line = bufferedReader.readLine()) != null) {
fileString.append(line + "\n");
}
} catch (IOException e) {
e.getStackTrace();
}
//Write complete file back to path
try (BufferedWriter bufferedWriter =
new BufferedWriter(new FileWriter(path))){
bufferedWriter
.append(fileString.insert(0, message).toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sunday, 20 December 2015
Luhn validator
Got a bit confused whilst testing something at work as one of the luhn validation tools at work decided to change it's mind around what the check digit should be, I wrote my own:
Luhn algorithm
package com.company;
public class luhnValidator {
public boolean isValidLuhn(String inputNumber) {
int[] numbers = stringToIntArray(inputNumber);
specialDoubler(numbers);
int total = sumIntArray(numbers);
return (total * 9) % 10 == numbers[numbers.length-1] ;
}
public int checkDigitCalc(String numberWithNoCheckDigit) {
int[] numbers = stringToIntArray(numberWithNoCheckDigit);
specialDoubler(numbers);
int total = sumIntArray(numbers);
return (total * 9) % 10;
}
private int[] stringToIntArray(String convertToNumbers) {
char[] brokenToChars = convertToNumbers.toCharArray();
int[] numbers = new int[brokenToChars.length];
for (int i = 0; i < brokenToChars.length; i++) {
numbers[i] = Character.getNumericValue(brokenToChars[i]) ;
}
return numbers;
}
/**
* Double every second number if greater than 10 add the products together
*/
private void specialDoubler(int[] numbers) {
int x2;
for (int i = numbers.length-2; i >= 0; i -= 2) {
x2 = numbers[i] * 2;
if (x2 < 10) {
numbers[i] = x2;
} else {
numbers[i] = (x2 - 10) + 1;
}
}
}
private int sumIntArray(int[] numbers) {
int total = 0;
for (int i = 0; i < numbers.length-1; i++ ) {
total += numbers[i];
}
return total;
}
}
Could still be optimised but it was fun to play with the intellij tests for jUnit, as they did help pick out a simple error where I missed out the '>' in >=.
Luhn algorithm
package com.company;
public class luhnValidator {
public boolean isValidLuhn(String inputNumber) {
int[] numbers = stringToIntArray(inputNumber);
specialDoubler(numbers);
int total = sumIntArray(numbers);
return (total * 9) % 10 == numbers[numbers.length-1] ;
}
public int checkDigitCalc(String numberWithNoCheckDigit) {
int[] numbers = stringToIntArray(numberWithNoCheckDigit);
specialDoubler(numbers);
int total = sumIntArray(numbers);
return (total * 9) % 10;
}
private int[] stringToIntArray(String convertToNumbers) {
char[] brokenToChars = convertToNumbers.toCharArray();
int[] numbers = new int[brokenToChars.length];
for (int i = 0; i < brokenToChars.length; i++) {
numbers[i] = Character.getNumericValue(brokenToChars[i]) ;
}
return numbers;
}
/**
* Double every second number if greater than 10 add the products together
*/
private void specialDoubler(int[] numbers) {
int x2;
for (int i = numbers.length-2; i >= 0; i -= 2) {
x2 = numbers[i] * 2;
if (x2 < 10) {
numbers[i] = x2;
} else {
numbers[i] = (x2 - 10) + 1;
}
}
}
private int sumIntArray(int[] numbers) {
int total = 0;
for (int i = 0; i < numbers.length-1; i++ ) {
total += numbers[i];
}
return total;
}
}
Could still be optimised but it was fun to play with the intellij tests for jUnit, as they did help pick out a simple error where I missed out the '>' in >=.
More links
https://www.ifixit.com/ actually looks handy and has my phone on there with a guide to replace the battery.
Article I liked http://allankelly.blogspot.co.uk/2015/10/software-has-diseconomies-of-scale-not.html
And a website I liked, seems simple enough and they accept bitcoin https://www.braintreepayments.com/
Article I liked http://allankelly.blogspot.co.uk/2015/10/software-has-diseconomies-of-scale-not.html
And a website I liked, seems simple enough and they accept bitcoin https://www.braintreepayments.com/
Wednesday, 16 December 2015
Quick challenge
Quick challenge after work, avoiding putting a front end on the lego app sigh.
package com.company;
import java.util.ArrayList;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String inputText = "The legend, propagated by email and message boards, purportedly demonstrates that readers can understand the "
+ "meaning of words in a sentence even when the interior letters of each word are scrambled. As long as all the necessary letters "
+ "are present, and the first and last letters remain the same, readers appear to have little trouble reading the text.";
String aPattern = "\\w+";
Pattern pattern = Pattern.compile(aPattern);
Matcher matcher = pattern.matcher(inputText);
ArrayList<String> words = new ArrayList<>();
while (matcher.find()) {
words.add(matcher.group());
}
StringBuilder outputWords = new StringBuilder(inputText.length());
String shuffledWord, middle;
char firstLetter, lastLetter;
for (String word : words) {
if(word.length() > 3) {
//build messed up words keeping edges same
firstLetter = word.charAt(0);
lastLetter = word.charAt(word.length()-1);
middle = wordShuffler(word.substring(1, word.length() - 1));
shuffledWord = firstLetter + middle + lastLetter;
} else {
shuffledWord = word;
}
outputWords.append(shuffledWord);
}
String nonWord = "\\W+";
pattern = Pattern.compile(nonWord);
matcher = pattern.matcher(inputText);
while (matcher.find()) {
outputWords.insert(matcher.start(), matcher.group());
}
System.out.println(inputText);
System.out.println(outputWords);
}
public static String wordShuffler(String wordToShuffle) {
char[] letterArray = wordToShuffle.toCharArray();
Random random = new Random();
int nextValue;
char swap;
for (int i = 0; i < letterArray.length; i++) {
swap = letterArray[i];
nextValue = random.nextInt(letterArray.length);
letterArray[i] = letterArray[nextValue];
letterArray[nextValue] = swap;
}
return new String(letterArray);
}
}
package com.company;
import java.util.ArrayList;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String inputText = "The legend, propagated by email and message boards, purportedly demonstrates that readers can understand the "
+ "meaning of words in a sentence even when the interior letters of each word are scrambled. As long as all the necessary letters "
+ "are present, and the first and last letters remain the same, readers appear to have little trouble reading the text.";
String aPattern = "\\w+";
Pattern pattern = Pattern.compile(aPattern);
Matcher matcher = pattern.matcher(inputText);
ArrayList<String> words = new ArrayList<>();
while (matcher.find()) {
words.add(matcher.group());
}
StringBuilder outputWords = new StringBuilder(inputText.length());
String shuffledWord, middle;
char firstLetter, lastLetter;
for (String word : words) {
if(word.length() > 3) {
//build messed up words keeping edges same
firstLetter = word.charAt(0);
lastLetter = word.charAt(word.length()-1);
middle = wordShuffler(word.substring(1, word.length() - 1));
shuffledWord = firstLetter + middle + lastLetter;
} else {
shuffledWord = word;
}
outputWords.append(shuffledWord);
}
String nonWord = "\\W+";
pattern = Pattern.compile(nonWord);
matcher = pattern.matcher(inputText);
while (matcher.find()) {
outputWords.insert(matcher.start(), matcher.group());
}
System.out.println(inputText);
System.out.println(outputWords);
}
public static String wordShuffler(String wordToShuffle) {
char[] letterArray = wordToShuffle.toCharArray();
Random random = new Random();
int nextValue;
char swap;
for (int i = 0; i < letterArray.length; i++) {
swap = letterArray[i];
nextValue = random.nextInt(letterArray.length);
letterArray[i] = letterArray[nextValue];
letterArray[nextValue] = swap;
}
return new String(letterArray);
}
}
Sunday, 13 December 2015
yousician
Actually impressed by an app, yousician, it actually looks good, I always wanted to learn to play then becoming an adult all the teachers only want to teach dam kids. Never mind :).
Pleased with the lego app, I got some more tests running and talking to people about should tests be run only the public methods or the private ones using reflection.
Pleased with the lego app, I got some more tests running and talking to people about should tests be run only the public methods or the private ones using reflection.
Sunday, 6 December 2015
Books and colours
Book I've been reading, Icarus deception by Seth Godin, enjoyed it, about making art is not comfortable and makes us feel vulnerable which is how you know you're making something new. I did like that Icarus could also fly too low.
Article I found interesting, Crash only software.
Sit stand desk, stand desks are normally so expensive but this looks good for the cost, varidesk.
12 years in software development article.
Been playing with a Lego picture maker and trying to get rgb values from Lego colours, after doing an average of the rgb values and using the closest average made a lot of thing purple. Delta-E 1976, fast enough with results accurate enough for what I want. My implementation, more info on it.
public static int[] getLegoColourEquiv(int[] rgb) {
int[] returnColourRGB = {1,1,1};
if(rgb == null) {
return returnColourRGB;
}
double lowestDelta = Double.MAX_VALUE;
double deltaE;
for (int[] colour : colours) {
//DeltaE76 (CIE 1976)
deltaE = Math.sqrt(
Math.pow(rgb[0] - colour[0], 2) +
Math.pow(rgb[1] - colour[1], 2) +
Math.pow(rgb[2] - colour[2], 2)
);
if(deltaE < lowestDelta) {
lowestDelta = deltaE;
returnColourRGB = Arrays.copyOf(colour,
colour.length);
}
}
return returnColourRGB;
}
Article I found interesting, Crash only software.
Sit stand desk, stand desks are normally so expensive but this looks good for the cost, varidesk.
12 years in software development article.
Been playing with a Lego picture maker and trying to get rgb values from Lego colours, after doing an average of the rgb values and using the closest average made a lot of thing purple. Delta-E 1976, fast enough with results accurate enough for what I want. My implementation, more info on it.
public static int[] getLegoColourEquiv(int[] rgb) {
int[] returnColourRGB = {1,1,1};
if(rgb == null) {
return returnColourRGB;
}
double lowestDelta = Double.MAX_VALUE;
double deltaE;
for (int[] colour : colours) {
//DeltaE76 (CIE 1976)
deltaE = Math.sqrt(
Math.pow(rgb[0] - colour[0], 2) +
Math.pow(rgb[1] - colour[1], 2) +
Math.pow(rgb[2] - colour[2], 2)
);
if(deltaE < lowestDelta) {
lowestDelta = deltaE;
returnColourRGB = Arrays.copyOf(colour,
colour.length);
}
}
return returnColourRGB;
}
Sunday, 22 November 2015
Update to lego thing as well
Link to MIT algorithms course, bought a book then omg this is hard.
Listening to podcasts https://codecombat.com/ came up, actually looks fun but bad memories of javascript under pressure.
I had another go at the lego picture maker, does seem to have a tendency to make the colours purple for some reason. Also IntStream just makes some of this stuff so easy.
Once it is in a better state I would like to get it on github. I get a bit hung up about poor code, I come back to it weeks later with wtf was I thinking. Need to add a front end, accept different input and output file types, and those actual lego nubs.
Must get away from magic numbers.
public static int[] getLegoColourEquiv(int[] rgb) {
int[] returnColourRGB = {1,2,3};
if(rgb == null) {
return returnColourRGB;
}
int rgbAverage = IntStream.of(rgb).sum() / rgb.length;
int gapFromColour = Integer.MAX_VALUE;
int colourAverage;
int rgbDiff;
for (int[] colour : colours) {
colourAverage = IntStream.of(colour).sum() / colour.length;
rgbDiff = rgbAverage - colourAverage ;
if(rgbDiff < 0) { rgbDiff *= -1;}
if(rgbDiff < gapFromColour) {
gapFromColour = rgbDiff;
returnColourRGB = Arrays.copyOf(colour, colour.length);
}
}
return returnColourRGB;
}
Listening to podcasts https://codecombat.com/ came up, actually looks fun but bad memories of javascript under pressure.
I had another go at the lego picture maker, does seem to have a tendency to make the colours purple for some reason. Also IntStream just makes some of this stuff so easy.
Once it is in a better state I would like to get it on github. I get a bit hung up about poor code, I come back to it weeks later with wtf was I thinking. Need to add a front end, accept different input and output file types, and those actual lego nubs.
Must get away from magic numbers.
public static int[] getLegoColourEquiv(int[] rgb) {
int[] returnColourRGB = {1,2,3};
if(rgb == null) {
return returnColourRGB;
}
int rgbAverage = IntStream.of(rgb).sum() / rgb.length;
int gapFromColour = Integer.MAX_VALUE;
int colourAverage;
int rgbDiff;
for (int[] colour : colours) {
colourAverage = IntStream.of(colour).sum() / colour.length;
rgbDiff = rgbAverage - colourAverage ;
if(rgbDiff < 0) { rgbDiff *= -1;}
if(rgbDiff < gapFromColour) {
gapFromColour = rgbDiff;
returnColourRGB = Arrays.copyOf(colour, colour.length);
}
}
return returnColourRGB;
}
Wednesday, 18 November 2015
Messy code which was fun to write
Some bits this week
cmd quser says when the user logged on, handy for when the boss asks why I am packing up so early, because I got here early :)
Found what looks like a good book, The Icarus Deception: How High Will You Fly?
rainforestQA awesome to have that many testers on standby.
Good pod cast, software engineering daily.
At the moment I like the idea of getting a laptop with a Linux on to play with even if it is dual boot.
So here is a mess but it works, trying to write a program that turns an image into lego blocks.
package com.company;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
public class LegoPictureMaker {
public String filePath;
public BufferedImage img;
public int legoSquareSideLength;
public LegoPictureMaker(String filePath) {
this.legoSquareSideLength = 16;
this.filePath = filePath;
}
public void makeImage() {
System.out.println("Grabbing file...");
img = grabFile();
System.out.println("Processing lego blocks");
processFile();
System.out.println("Done!");
}
//process file
private void processFile() {
//work out of squares needed in width and height
int xTiles = img.getRaster().getWidth() / legoSquareSideLength;
int yTiles = img.getRaster().getHeight() / legoSquareSideLength;
//build image I can write to
BufferedImage buildImage;
buildImage = new BufferedImage(
(xTiles * legoSquareSideLength),
(yTiles * legoSquareSideLength),
BufferedImage.TYPE_INT_RGB);
int totalTiles = xTiles * yTiles;
int red= 0, green = 0, blue = 0;
int[] testArray = new int[3];
img.getRaster().getPixel(0,0, testArray);
//make something usable
WritableRaster writableRaster = (WritableRaster)buildImage.getData();
int[][][] averageColour = new int[xTiles][yTiles][3];
for(int x = 0; x < xTiles; x++) {
for (int y = 0; y < yTiles; y++) {
averageColour[x][y] = getAverageColour(x * legoSquareSideLength, y * legoSquareSideLength);
writeTileColour(writableRaster, x * legoSquareSideLength, y * legoSquareSideLength, averageColour[x][y]);
}
}
saveImage(buildImage, writableRaster);
}
private void writeTileColour(WritableRaster writableRaster, int xPoint, int yPoint, int[] rgbValues) {
int endX = xPoint + legoSquareSideLength;
int endY = yPoint + legoSquareSideLength;
for (int x = xPoint; x < endX; x++) {
for (int y = yPoint; y < endY; y++) {
writableRaster.setPixel(x, y, rgbValues);
}
}
}
private int[] getAverageColour(int xPoint, int yPoint) {
int red= 0, green = 0, blue = 0;
int endX = xPoint + legoSquareSideLength;
int endY = yPoint + legoSquareSideLength;
int[] testArray = new int[3];;
for (int i = xPoint; i < endX; i++) {
for (int j = yPoint; j < endY; j++) {
img.getRaster().getPixel(i,j, testArray);
red += testArray[0];
green += testArray[1];
blue += testArray[2];
}
}
int amountOfPixels = legoSquareSideLength * legoSquareSideLength;
return new int[] { red / amountOfPixels,
green / amountOfPixels,
blue / amountOfPixels};
}
//save image
public void saveImage(BufferedImage buildImage, WritableRaster writableRaster) {
//save and close file
buildImage.setData(writableRaster);
File outputFile = new File("testest.png");
try {
ImageIO.write(buildImage, "png", outputFile);
} catch (IOException ex) {
ex.printStackTrace();
}
}
//get the file
public BufferedImage grabFile() {
BufferedImage img = null;
if (filePath != null && !filePath.isEmpty()) {
try {
img = ImageIO.read(new File(this.filePath));
} catch (IOException ex) {
System.out.println("broke here");
ex.printStackTrace();
}
}
return img;
}
}
cmd quser says when the user logged on, handy for when the boss asks why I am packing up so early, because I got here early :)
Found what looks like a good book, The Icarus Deception: How High Will You Fly?
rainforestQA awesome to have that many testers on standby.
Good pod cast, software engineering daily.
At the moment I like the idea of getting a laptop with a Linux on to play with even if it is dual boot.
So here is a mess but it works, trying to write a program that turns an image into lego blocks.
package com.company;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
public class LegoPictureMaker {
public String filePath;
public BufferedImage img;
public int legoSquareSideLength;
public LegoPictureMaker(String filePath) {
this.legoSquareSideLength = 16;
this.filePath = filePath;
}
public void makeImage() {
System.out.println("Grabbing file...");
img = grabFile();
System.out.println("Processing lego blocks");
processFile();
System.out.println("Done!");
}
//process file
private void processFile() {
//work out of squares needed in width and height
int xTiles = img.getRaster().getWidth() / legoSquareSideLength;
int yTiles = img.getRaster().getHeight() / legoSquareSideLength;
//build image I can write to
BufferedImage buildImage;
buildImage = new BufferedImage(
(xTiles * legoSquareSideLength),
(yTiles * legoSquareSideLength),
BufferedImage.TYPE_INT_RGB);
int totalTiles = xTiles * yTiles;
int red= 0, green = 0, blue = 0;
int[] testArray = new int[3];
img.getRaster().getPixel(0,0, testArray);
//make something usable
WritableRaster writableRaster = (WritableRaster)buildImage.getData();
int[][][] averageColour = new int[xTiles][yTiles][3];
for(int x = 0; x < xTiles; x++) {
for (int y = 0; y < yTiles; y++) {
averageColour[x][y] = getAverageColour(x * legoSquareSideLength, y * legoSquareSideLength);
writeTileColour(writableRaster, x * legoSquareSideLength, y * legoSquareSideLength, averageColour[x][y]);
}
}
saveImage(buildImage, writableRaster);
}
private void writeTileColour(WritableRaster writableRaster, int xPoint, int yPoint, int[] rgbValues) {
int endX = xPoint + legoSquareSideLength;
int endY = yPoint + legoSquareSideLength;
for (int x = xPoint; x < endX; x++) {
for (int y = yPoint; y < endY; y++) {
writableRaster.setPixel(x, y, rgbValues);
}
}
}
private int[] getAverageColour(int xPoint, int yPoint) {
int red= 0, green = 0, blue = 0;
int endX = xPoint + legoSquareSideLength;
int endY = yPoint + legoSquareSideLength;
int[] testArray = new int[3];;
for (int i = xPoint; i < endX; i++) {
for (int j = yPoint; j < endY; j++) {
img.getRaster().getPixel(i,j, testArray);
red += testArray[0];
green += testArray[1];
blue += testArray[2];
}
}
int amountOfPixels = legoSquareSideLength * legoSquareSideLength;
return new int[] { red / amountOfPixels,
green / amountOfPixels,
blue / amountOfPixels};
}
//save image
public void saveImage(BufferedImage buildImage, WritableRaster writableRaster) {
//save and close file
buildImage.setData(writableRaster);
File outputFile = new File("testest.png");
try {
ImageIO.write(buildImage, "png", outputFile);
} catch (IOException ex) {
ex.printStackTrace();
}
}
//get the file
public BufferedImage grabFile() {
BufferedImage img = null;
if (filePath != null && !filePath.isEmpty()) {
try {
img = ImageIO.read(new File(this.filePath));
} catch (IOException ex) {
System.out.println("broke here");
ex.printStackTrace();
}
}
return img;
}
}
Wednesday, 11 November 2015
Challenge where I got stuck
Annoyed something so simple took this long and still doesn't bloody work correctly, waaah!
package com.company;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class PasswordGame {
public String[] guessWords;
public String password;
enum difficultySettings {VERY_EASY, EASY, MEDIUM, HARD, VERY_HARD}
difficultySettings difficulty;
public int amountOfGuesses;
public PasswordGame(difficultySettings aDifficulty) {
this.difficulty = aDifficulty;
getGuessWordsAndPassword(difficulty);
}
public void gameRun() {
System.out.println("You have " + amountOfGuesses + " guess");
System.out.println("Your word list: ");
printWordList();
boolean gameWon = false;
String wordGuess;
System.out.println("Password is: " + this.password);
while (!gameWon && amountOfGuesses > 0) {
wordGuess = getGuess();
if (wordGuess.equals(password)) {
gameWon = true;
} else {
amountOfGuesses--;
System.out.println("Unlucky: " + passwordCompare(wordGuess) + " guesses left: " + amountOfGuesses);
}
}
if (gameWon) {
System.out.println("You WIN!!!");
} else {
System.out.println("You lose :(");
}
}
private String passwordCompare(String wordGuess) {
int correctChar = 0;
int correctCharAndPlace = 0;
ArrayList<Character> passWordCopy = new ArrayList<>();
for (char aChar : password.toCharArray()) { passWordCopy.add(aChar); }
ArrayList<Character> guess = new ArrayList<>();
for (char aChar : wordGuess.toUpperCase().toCharArray()) { guess.add(aChar); }
for(int i = 0; i < guess.size() && i < passWordCopy.size(); i++) {
if (guess.get(i) == passWordCopy.get(i)) {
correctChar++; correctCharAndPlace++;
} else if ( passWordCopy.contains(guess.get(i))) {
correctChar++;
passWordCopy.set(i, '+');
}
}
return "correct chracter: " + correctChar + " and in the correct place: " + correctCharAndPlace;
}
private String getGuess() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String wordGuessed = "";
try {
wordGuessed = reader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return wordGuessed;
}
private void printWordList() {
for (String word : guessWords) {
System.out.println(word);
}
}
public String[] getGuessWordsAndPassword(difficultySettings aDifficulty) {
switch (aDifficulty) {
case VERY_EASY:
amountOfGuesses = 20;
populateWordsAndPassWord(10,5);
break;
case EASY:
amountOfGuesses = 15;
populateWordsAndPassWord(10,6);
break;
case MEDIUM:
amountOfGuesses = 12;
populateWordsAndPassWord(10,7);
break;
case HARD:
amountOfGuesses = 10;
populateWordsAndPassWord(10,8);
break;
case VERY_HARD:
default:
amountOfGuesses = 8;
populateWordsAndPassWord(10,9);
break;
}
return new String[]{};
}
private void populateWordsAndPassWord(int wordLength, int amountOfWords) {
ArrayList<String> filteredList = this.filteredWordList(wordLength, amountOfWords);
Collections.shuffle(filteredList);
this.guessWords = filteredList.toArray(new String[filteredList.size()]);
this.password = guessWords[new Random().nextInt(this.guessWords.length)];
}
private ArrayList<String> filteredWordList(int wordLength, int amountOfwords) {
FileReader fileReader;
BufferedReader bufferedReader;
Set<String> wordSet = new HashSet<>(); //set to filter duplicates
try {
fileReader = new FileReader("someplace\\enable1.txt");
bufferedReader = new BufferedReader(fileReader);
String word;
while ((word = bufferedReader.readLine()) != null) {
if(word.length() == wordLength) {
wordSet.add(word);
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
ArrayList<String> words = new ArrayList<>(wordSet);
ArrayList<String> sizedWords = new ArrayList<>();
for (int i = 0; i < amountOfwords; i++) {
sizedWords.add(words.get(i).toUpperCase());
}
return sizedWords;
}
}
package com.company;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class PasswordGame {
public String[] guessWords;
public String password;
enum difficultySettings {VERY_EASY, EASY, MEDIUM, HARD, VERY_HARD}
difficultySettings difficulty;
public int amountOfGuesses;
public PasswordGame(difficultySettings aDifficulty) {
this.difficulty = aDifficulty;
getGuessWordsAndPassword(difficulty);
}
public void gameRun() {
System.out.println("You have " + amountOfGuesses + " guess");
System.out.println("Your word list: ");
printWordList();
boolean gameWon = false;
String wordGuess;
System.out.println("Password is: " + this.password);
while (!gameWon && amountOfGuesses > 0) {
wordGuess = getGuess();
if (wordGuess.equals(password)) {
gameWon = true;
} else {
amountOfGuesses--;
System.out.println("Unlucky: " + passwordCompare(wordGuess) + " guesses left: " + amountOfGuesses);
}
}
if (gameWon) {
System.out.println("You WIN!!!");
} else {
System.out.println("You lose :(");
}
}
private String passwordCompare(String wordGuess) {
int correctChar = 0;
int correctCharAndPlace = 0;
ArrayList<Character> passWordCopy = new ArrayList<>();
for (char aChar : password.toCharArray()) { passWordCopy.add(aChar); }
ArrayList<Character> guess = new ArrayList<>();
for (char aChar : wordGuess.toUpperCase().toCharArray()) { guess.add(aChar); }
for(int i = 0; i < guess.size() && i < passWordCopy.size(); i++) {
if (guess.get(i) == passWordCopy.get(i)) {
correctChar++; correctCharAndPlace++;
} else if ( passWordCopy.contains(guess.get(i))) {
correctChar++;
passWordCopy.set(i, '+');
}
}
return "correct chracter: " + correctChar + " and in the correct place: " + correctCharAndPlace;
}
private String getGuess() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String wordGuessed = "";
try {
wordGuessed = reader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return wordGuessed;
}
private void printWordList() {
for (String word : guessWords) {
System.out.println(word);
}
}
public String[] getGuessWordsAndPassword(difficultySettings aDifficulty) {
switch (aDifficulty) {
case VERY_EASY:
amountOfGuesses = 20;
populateWordsAndPassWord(10,5);
break;
case EASY:
amountOfGuesses = 15;
populateWordsAndPassWord(10,6);
break;
case MEDIUM:
amountOfGuesses = 12;
populateWordsAndPassWord(10,7);
break;
case HARD:
amountOfGuesses = 10;
populateWordsAndPassWord(10,8);
break;
case VERY_HARD:
default:
amountOfGuesses = 8;
populateWordsAndPassWord(10,9);
break;
}
return new String[]{};
}
private void populateWordsAndPassWord(int wordLength, int amountOfWords) {
ArrayList<String> filteredList = this.filteredWordList(wordLength, amountOfWords);
Collections.shuffle(filteredList);
this.guessWords = filteredList.toArray(new String[filteredList.size()]);
this.password = guessWords[new Random().nextInt(this.guessWords.length)];
}
private ArrayList<String> filteredWordList(int wordLength, int amountOfwords) {
FileReader fileReader;
BufferedReader bufferedReader;
Set<String> wordSet = new HashSet<>(); //set to filter duplicates
try {
fileReader = new FileReader("someplace\\enable1.txt");
bufferedReader = new BufferedReader(fileReader);
String word;
while ((word = bufferedReader.readLine()) != null) {
if(word.length() == wordLength) {
wordSet.add(word);
}
}
} catch (IOException ex) {
ex.printStackTrace();
}
ArrayList<String> words = new ArrayList<>(wordSet);
ArrayList<String> sizedWords = new ArrayList<>();
for (int i = 0; i < amountOfwords; i++) {
sizedWords.add(words.get(i).toUpperCase());
}
return sizedWords;
}
}
Tuesday, 10 November 2015
Short one
I went over board on an intermediate challenge so put off doing a post.
Links for much happiness,
http://12factor.net/
http://www.sunjw.us/jstoolnpp/ js tool, good plugin for notepad++
https://skillsmatter.com/ guys at work talking about clojure came across skills matter, over £2k to listen to uncle bob!
Got quite into evernote, beats the bits of paper I always lose by a large margin.
Since I am studying for the Java 8 OCA, http://enthuware.com/index.php apparently is the thing to do, the exam does seem quite pedantic to me but that also shows how dependent I am on autocomplete.
Links for much happiness,
http://12factor.net/
http://www.sunjw.us/jstoolnpp/ js tool, good plugin for notepad++
https://skillsmatter.com/ guys at work talking about clojure came across skills matter, over £2k to listen to uncle bob!
Got quite into evernote, beats the bits of paper I always lose by a large margin.
Since I am studying for the Java 8 OCA, http://enthuware.com/index.php apparently is the thing to do, the exam does seem quite pedantic to me but that also shows how dependent I am on autocomplete.
Sunday, 1 November 2015
Windows 10 start button not working and I also did a programming challenge
On windows 10 and needed some anti virus, installed Kaspersky, windows key no longer works and cannot click on any of the buttons except shortcuts. I may need another way of getting to applications other than win key and type.
Solution: https://www.techmesto.com/fix-start-menu-broken-windows-10-technical-preview/
Or run this in power shell
Solution: https://www.techmesto.com/fix-start-menu-broken-windows-10-technical-preview/
Or run this in power shell
Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage
-DisableDevelopmentMode
-Register "$($_.InstallLocation)\AppXManifest.xml"}
Challenge 238 Easy consonants and vowels
package com.company;
import java.util.Random;
import java.util.regex.*;
public class Main {
public static void main(String[] args) {
String inputString = "CVcvcvcc";
char[] consonants = "bcdfghjklmnpqrstvwxyz".toCharArray();
char[] vowels = "aeiou".toCharArray();
Random random = new Random();
Pattern pattern = Pattern.compile("[^vcVC]");
Matcher matcher = pattern.matcher(inputString);
if (matcher.find()) {
System.out.println("Invalid character in input");
} else {
StringBuilder output =
new StringBuilder(inputString.length());
for (char letter : inputString.toCharArray()) {
switch (letter) {
case 'c':
output.append(consonants[random.nextInt
(consonants.length)]);
break;
case 'C':
output.append(Character.toUpperCase
(consonants[random.nextInt(consonants.length)]));
break;
case 'V':
output.append(Character.toUpperCase
(vowels[random.nextInt(vowels.length)]));
break;
case 'v':
output.append(vowels[random.nextInt
(vowels.length)]);
break;
}
}
System.out.println(output);
}
}
}
Originally did this with multiple ifs' and it looked bloody awful.
Sunday, 25 October 2015
I'm not dead
I got a bit busy and a bit depressed
BCS foundation level test: DONE!
Changed the way I test, I need to get a better balance as it seems geared towards lots of documentation to the extent that I spend a lot of time documenting what I am doing rather than actually doing it. There has been the benefit that less is getting missed and managers can decide on risk relative to test cases run. A big benefit has been the confidence to say no and be able to back it up.
ITIL foundation: DONE!
Again a lot of documentation and process, a good trainer from Quanta. It was good as he was willing to engage and discuss that ITIL does not really deal with modern ways of doing project work (agile). From my point of view it is a way for the IT department to have the confidence to talk about business demands and maintaining a good relationship. It was an eye opener in what managers have to deal with in terms of scope creep.
BONUS, work paid for it all.
Getting back to programming now the above are out the way, started on the Java OCA 8, forgotten how much I enjoyed programming, big highs when it works, lows when it doesn't and a good challenge in between. So the habit I need to build is program everyday and build things, I want to mix in code challenges as a way of testing myself and doing something different.
And here is one I made earlier, I wanted an easy to paste example, it should have been a proper class.
BCS foundation level test: DONE!
Changed the way I test, I need to get a better balance as it seems geared towards lots of documentation to the extent that I spend a lot of time documenting what I am doing rather than actually doing it. There has been the benefit that less is getting missed and managers can decide on risk relative to test cases run. A big benefit has been the confidence to say no and be able to back it up.
ITIL foundation: DONE!
Again a lot of documentation and process, a good trainer from Quanta. It was good as he was willing to engage and discuss that ITIL does not really deal with modern ways of doing project work (agile). From my point of view it is a way for the IT department to have the confidence to talk about business demands and maintaining a good relationship. It was an eye opener in what managers have to deal with in terms of scope creep.
BONUS, work paid for it all.
Getting back to programming now the above are out the way, started on the Java OCA 8, forgotten how much I enjoyed programming, big highs when it works, lows when it doesn't and a good challenge in between. So the habit I need to build is program everyday and build things, I want to mix in code challenges as a way of testing myself and doing something different.
And here is one I made earlier, I wanted an easy to paste example, it should have been a proper class.
package com.company;
import java.io.*;
import java.util.HashSet;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
private static HashSet<String> words = new HashSet<>();
public static void main(String[] args) {
//read file into a set
FileReader fileReader;
BufferedReader bufferedReader;
try {
fileReader = new FileReader("C:\\enable1.txt");
bufferedReader = new BufferedReader(fileReader);
String currentWord = "";
while ((currentWord = bufferedReader.readLine()) != null) {
words.add(currentWord);
}
bufferedReader.close();
} catch (FileNotFoundException ex) {
System.out.println("File not found bro!");
ex.printStackTrace();
} catch (IOException ex) {
System.out.println("HDD broke bro!");
ex.printStackTrace();
}
// int how many lines to read
System.out.print("Lines to read: ");
Scanner scanner = new Scanner(System.in);
int linesToRead = scanner.nextInt();
// amount of lines specified above with string of what keys can be entered
String[] inputWords = new String[linesToRead];
for (int i = 0; i < linesToRead; i++) {
inputWords[i] = scanner.next();
}
System.out.println();
//output each user input line = longestWordFound
for (String word : inputWords) {
System.out.println(word + " = " + longestWordFromChars(word) );
}
}
// find the longest word that can be found using those keys
private static String longestWordFromChars(String chars) {
Pattern regex = Pattern.compile("\\b[" + chars + "]+\\b");
Matcher regexMatcher;
String longestWord = "";
for (String word : words) {
regexMatcher = regex.matcher(word);
if(regexMatcher.find()) {
if(word.length() > longestWord.length()) {
longestWord = word;
}
}
}
return longestWord;
}
}
Saturday, 18 July 2015
Another interview
It went OK i just panicked and forgot all the words, also if anyone interviews please do not ask them to work from a TV on the wall, what is so hard about getting them to use a proper workstation.
Any way from what I remember of the interview questions there were three, solve quadratic equations, formula given, connect to a db in c# and out order the values not to worry about displaying them, and a t-sql question from the pubs database.
Pubs was actually a not that easy to get hold of, a bit of searching and the database can be build by using a script from SQL from the trenches, use the script as the old db files are not compatible with modern iterations of mssql server.
Note code is not perfect as tried to keep to similar timescales
Question 1 & 2
using System;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
var dt = new DataTable();
var connectionString = @"Server=D\SQLEXPRESS;
Database=pubs;Integrated Security=true;";
var query = "SELECT * FROM authors";
var conn = new SqlConnection(connectionString);
var cmd = new SqlCommand(query, conn);
conn.Open();
var sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
conn.Close();
sda.Dispose();
DataView dv = dt.DefaultView;
dv.Sort = "au_lname ASC";
foreach (DataRow row in dv.ToTable().Rows)
{
Console.WriteLine("{0,-15}{1,-15}{2,-15}",
row["au_lname"], row["au_fname"], row["city"]);
}
var anAnswer = quadSolver(1, 9, 18);
Console.WriteLine("The answer is: {0} and {1}",
anAnswer.Item1, anAnswer.Item2);
Console.Read();
}
public static Tuple<double, double> quadSolver(double a, double b, double c)
{
double answer1 = 0.0;
double answer2 = 0.0;
answer1 = ((b * -1) + Math.Sqrt(Math.Pow(b, 2) -
(4 * a * c))) / (2 * a);
answer2 = ((b * -1) - Math.Sqrt(Math.Pow(b, 2) -
(4 * a * c))) / (2 * a);
return new Tuple<double, double>(answer1, answer2);
}
}
}
Question 3
SELECT (au_fname + ' ' + au_lname) AS NAME,
[PUBLISHED TITLES],
[AVERAGE COST],
[LAST PUBLISHED]
FROM authors AS A
JOIN
(
SELECT AU_ID,
COUNT(*) AS [PUBLISHED TITLES],
AVG(price) AS [AVERAGE COST],
FORMAT(MAX(pubdate), 'dd/MM/yyyy') AS [LAST PUBLISHED]
FROM [dbo].[titles] AS T JOIN [dbo].[titleauthor] AS TA
ON T.title_id = TA.title_id
GROUP BY au_id
) AS FT ON A.au_id = FT.au_id
ORDER BY NAME;
Any way from what I remember of the interview questions there were three, solve quadratic equations, formula given, connect to a db in c# and out order the values not to worry about displaying them, and a t-sql question from the pubs database.
Pubs was actually a not that easy to get hold of, a bit of searching and the database can be build by using a script from SQL from the trenches, use the script as the old db files are not compatible with modern iterations of mssql server.
Note code is not perfect as tried to keep to similar timescales
Question 1 & 2
using System;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
var dt = new DataTable();
var connectionString = @"Server=D\SQLEXPRESS;
Database=pubs;Integrated Security=true;";
var query = "SELECT * FROM authors";
var conn = new SqlConnection(connectionString);
var cmd = new SqlCommand(query, conn);
conn.Open();
var sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
conn.Close();
sda.Dispose();
DataView dv = dt.DefaultView;
dv.Sort = "au_lname ASC";
foreach (DataRow row in dv.ToTable().Rows)
{
Console.WriteLine("{0,-15}{1,-15}{2,-15}",
row["au_lname"], row["au_fname"], row["city"]);
}
var anAnswer = quadSolver(1, 9, 18);
Console.WriteLine("The answer is: {0} and {1}",
anAnswer.Item1, anAnswer.Item2);
Console.Read();
}
public static Tuple<double, double> quadSolver(double a, double b, double c)
{
double answer1 = 0.0;
double answer2 = 0.0;
answer1 = ((b * -1) + Math.Sqrt(Math.Pow(b, 2) -
(4 * a * c))) / (2 * a);
answer2 = ((b * -1) - Math.Sqrt(Math.Pow(b, 2) -
(4 * a * c))) / (2 * a);
return new Tuple<double, double>(answer1, answer2);
}
}
}
Question 3
SELECT (au_fname + ' ' + au_lname) AS NAME,
[PUBLISHED TITLES],
[AVERAGE COST],
[LAST PUBLISHED]
FROM authors AS A
JOIN
(
SELECT AU_ID,
COUNT(*) AS [PUBLISHED TITLES],
AVG(price) AS [AVERAGE COST],
FORMAT(MAX(pubdate), 'dd/MM/yyyy') AS [LAST PUBLISHED]
FROM [dbo].[titles] AS T JOIN [dbo].[titleauthor] AS TA
ON T.title_id = TA.title_id
GROUP BY au_id
) AS FT ON A.au_id = FT.au_id
ORDER BY NAME;
Wednesday, 8 July 2015
Github
Finally got github account set up and time to get updating my blog again!
https://github.com/Decimater/xfireDownloader
https://github.com/Decimater/xfireDownloader
Sunday, 26 April 2015
Bits and bobs
Little bits I suppose,
Getting rid of more hardware, and been drooling over the m.2 ssd available.
Apart from getting rid of old hardware, started to use SQL a lot more and Java.
Getting rid of more hardware, and been drooling over the m.2 ssd available.
Apart from getting rid of old hardware, started to use SQL a lot more and Java.
Sunday, 22 March 2015
Laws, JUnit, and Hamcrest
Came across a couple of different laws this week,
The robustness principal / Postel's law, interesting idea on how it can be used within software construction although originally for use in networking.
Be conservative in what you do, be liberal in what you accept from others (often reworded as "Be conservative in what you send, be liberal in what you accept").
Command query separation (CQS), the idea for what I write would be a function or method should return a value for query and for command which would change the system's state in some way should return void.
Installing JUnit for IntelliJ 14, although IntelliJ does come with JUnit installed and a test runner, JUnit has a dependency on Hamcrest. It was not entirely clear where what and how was going wrong, so...
Book read this month, The software craftsman, has some good ideas, I did like the whole job searching and what to look for, generally that a dev would have written the job description and more concerned about what the dev can deliver. I often see degree only, 10 or more years experience.
The robustness principal / Postel's law, interesting idea on how it can be used within software construction although originally for use in networking.
Be conservative in what you do, be liberal in what you accept from others (often reworded as "Be conservative in what you send, be liberal in what you accept").
Command query separation (CQS), the idea for what I write would be a function or method should return a value for query and for command which would change the system's state in some way should return void.
Installing JUnit for IntelliJ 14, although IntelliJ does come with JUnit installed and a test runner, JUnit has a dependency on Hamcrest. It was not entirely clear where what and how was going wrong, so...
- Hamcrest at Google code.
- IntelliJ -> File -> project structure
- Modules -> Dependencies -> + icon top right
- Point to hamcrest, YAY!
Book read this month, The software craftsman, has some good ideas, I did like the whole job searching and what to look for, generally that a dev would have written the job description and more concerned about what the dev can deliver. I often see degree only, 10 or more years experience.
Sunday, 15 March 2015
Back to learning Java
Little things from podcasts and bits online,
Strangler pattern, interesting idea, by taking the shape of current system you strangle the older system in the same way ivy does.
Conway's law, the idea that systems being developed mirror the social structure of the company creating it.
UK Business insider with an article about rates of pay and different technologies and skill sets.
Trying to get up to speed with Java doing basic coding challenges, very different to how intuitive I found visual studio.
Challenge 202 convert binary to English
public class Main {
public static void main(String[] args) {
String input "010010000110010101101100011011000
11011110010000001010111011011
11011100100110110001100100";
char[] inputs = input.toCharArray();
List<String> inputsAsWords = new ArrayList<String>();
int wordLength = 8;
int wordLettersinInput = input.length() / wordLength;
int counter = 0;
for (int i = 0; i < wordLettersinInput; i++)
{
String Word = "";
counter += wordLength;
for (int k = i*wordLength; k < counter; k++ )
{
Word = Word + inputs[k];
}
inputsAsWords.add(Word);
}
for (String word: inputsAsWords)
{
System.out.print((char) Integer.parseInt(word, 2));
}
}
}
More kit going to the recycling, this time it was a broken card, folding at home is hard on cards, removed the cooler for other projects. I did find whilst throwing rubbish out my old TIM-clean. TIM-clean, citrus based solvent that is actually friendly compared to isopropyl alcohol and effective.
Strangler pattern, interesting idea, by taking the shape of current system you strangle the older system in the same way ivy does.
Conway's law, the idea that systems being developed mirror the social structure of the company creating it.
UK Business insider with an article about rates of pay and different technologies and skill sets.
Trying to get up to speed with Java doing basic coding challenges, very different to how intuitive I found visual studio.
Challenge 203, display a black triangle |
Challenge 202 convert binary to English
public class Main {
public static void main(String[] args) {
String input "010010000110010101101100011011000
11011110010000001010111011011
11011100100110110001100100";
char[] inputs = input.toCharArray();
List<String> inputsAsWords = new ArrayList<String>();
int wordLength = 8;
int wordLettersinInput = input.length() / wordLength;
int counter = 0;
for (int i = 0; i < wordLettersinInput; i++)
{
String Word = "";
counter += wordLength;
for (int k = i*wordLength; k < counter; k++ )
{
Word = Word + inputs[k];
}
inputsAsWords.add(Word);
}
for (String word: inputsAsWords)
{
System.out.print((char) Integer.parseInt(word, 2));
}
}
}
More kit going to the recycling, this time it was a broken card, folding at home is hard on cards, removed the cooler for other projects. I did find whilst throwing rubbish out my old TIM-clean. TIM-clean, citrus based solvent that is actually friendly compared to isopropyl alcohol and effective.
Sunday, 8 March 2015
Recycling
Recycling old kit, you will be missed, go now to silicon heaven with all the old calculators.
Also frustrating and rewarding the app inventor, had to do some bits for uni. I am old so programming in this way is quite strange.
Also frustrating and rewarding the app inventor, had to do some bits for uni. I am old so programming in this way is quite strange.
Sunday, 22 February 2015
Noise cancelling headphones
Finally got some noise cancelling headphones, not the most expensive or the most effective but they really take the edge off the air compressor whine that I am near. They do not cancel voice well which actually has worked out so if people ask for me I can just hear them.
Don't under estimate documentation, I've been updating lots of it, systems that have been around for ages at least worth documenting the basics and business rules. As I found a lot of time has been used to find who knows this thing and then how to use it.
For the record these are 7dayshop AERO 7 Active Noise Cancelling Headphones with Aeroplane Kit and Travel Case from amazon. Another benefit has been being able to use my training time watching pluralsight videos at work.
Not really tech, having a big mouse mat is actually nice, tracks well when using the surface calibration in the synapse software.
Don't under estimate documentation, I've been updating lots of it, systems that have been around for ages at least worth documenting the basics and business rules. As I found a lot of time has been used to find who knows this thing and then how to use it.
Sunday, 1 February 2015
Shorty this week
Hanselman how to use word very handy as I had not been shown any of that, one of those things I just expected to be able to do.
The path finding algorithm Dijkstra which is the father of A* and then A* epsilon. A* builds on Dijkstra algorithm by being greedy.
A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding a global optimum.
en.wikipedia.org/wiki/Greedy_algorithm
From .net rocks about opening files in notepad, if the first line starts with PK this is a zip file. Tried this out and appears true.
The path finding algorithm Dijkstra which is the father of A* and then A* epsilon. A* builds on Dijkstra algorithm by being greedy.
A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding a global optimum.
en.wikipedia.org/wiki/Greedy_algorithm
From .net rocks about opening files in notepad, if the first line starts with PK this is a zip file. Tried this out and appears true.
Sunday, 25 January 2015
General stuff
Been doing quite a bit of reading for the testing istqb foundation, where I can get some exams going and see how I do.
Started using a new plugin to test API's, which is another thing I need to learn and read about, http://www.getpostman.com/.
Completed a programming challenge of validating an ISBN10 which is challenge 197. Compact code so left as is
using System;
namespace Challenge197ISBN
{
class Program
{
static void Main(string[] args)
{
var ISBN10 = "0-7475-3269-9";
Console.WriteLine("Validating: {0}", ISBN10);
int total = 0;
int counter = 10;
foreach (var letter in ISBN10)
{
if (letter != '-' && counter > 0)
{
var current = int.Parse(letter.ToString());
total += current*counter;
counter--;
}
}
Console.WriteLine("ISBN is valid: {0}", total % 11 == 0);
Console.Read();
}
}
}
Ordered some noise cancelling headphones as the open plan office can get a little noisey. A good demo of them in action https://www.youtube.com/watch?v=1EwkaRvIduw
Came across a good video on hacker news about Erlang, quite interesting the idea of bike shedding and trolls.
https://www.youtube.com/watch?v=3MvKLOecT1I
Started using a new plugin to test API's, which is another thing I need to learn and read about, http://www.getpostman.com/.
Completed a programming challenge of validating an ISBN10 which is challenge 197. Compact code so left as is
using System;
namespace Challenge197ISBN
{
class Program
{
static void Main(string[] args)
{
var ISBN10 = "0-7475-3269-9";
Console.WriteLine("Validating: {0}", ISBN10);
int total = 0;
int counter = 10;
foreach (var letter in ISBN10)
{
if (letter != '-' && counter > 0)
{
var current = int.Parse(letter.ToString());
total += current*counter;
counter--;
}
}
Console.WriteLine("ISBN is valid: {0}", total % 11 == 0);
Console.Read();
}
}
}
Ordered some noise cancelling headphones as the open plan office can get a little noisey. A good demo of them in action https://www.youtube.com/watch?v=1EwkaRvIduw
Came across a good video on hacker news about Erlang, quite interesting the idea of bike shedding and trolls.
https://www.youtube.com/watch?v=3MvKLOecT1I
Sunday, 18 January 2015
New desk!
With the new job money is a lot better, slowly getting myself sorted out.
The new desk is sturdy and nice to have some space, underestimated a little as I doubt a second monitor and 3d printer would fit, will have to see if I can move the modem and router underneath. Desk full name is Trexus Contract Plus Cantilever Desk Rectangular Silver Legs W1600xD800xH725mm Oak.
Audible is actually pretty good as an alternative to podcasts as some are a little heavy and can change topics quickly. Audible have a free trial then one audible book a month is £8 which is not bad, if bought singly they are expensive. A few do look good, the chimp paradox and here comes everybody. A shame pluralsight only really do videos which would not be worth while when driving.
Had to do some browser testing, not sure how reliable emulation is via the IE dev tools, either way a colleague mentioned modern.ie
where a virtual machine can be downloaded. I think something like virtual box is needed to make it all run.
The new desk is sturdy and nice to have some space, underestimated a little as I doubt a second monitor and 3d printer would fit, will have to see if I can move the modem and router underneath. Desk full name is Trexus Contract Plus Cantilever Desk Rectangular Silver Legs W1600xD800xH725mm Oak.
Audible is actually pretty good as an alternative to podcasts as some are a little heavy and can change topics quickly. Audible have a free trial then one audible book a month is £8 which is not bad, if bought singly they are expensive. A few do look good, the chimp paradox and here comes everybody. A shame pluralsight only really do videos which would not be worth while when driving.
Had to do some browser testing, not sure how reliable emulation is via the IE dev tools, either way a colleague mentioned modern.ie
where a virtual machine can be downloaded. I think something like virtual box is needed to make it all run.
Sunday, 4 January 2015
First post of the new year!
Was not going to bother this week, however imma tryin'. The new place I work for do a lot of java which conflicts with my c#, asp.net, visual studio experience. Making the most of it, it now looks like I will have to learn java and clojure. Seems a shame to throw all that work away.
Suggested to me that I can move from test to developer by taking the oracle certified developer exam.
It is nice to work with developers regularly now as we get to talk about different computing topics rather than strictly on topic working remotely. Talking of different architectures Endianness
came up.
I am now on twitter, there seems to be a high noise to signal ratio for some developers I am following. Some good has come from it already, the Not Just Code Monkeys presentation, quite fun and interesting about the use of dark patterns by certain companies.
Researching clojure, good youtube video by Tim Ewald Clojure: Programming with hand tools which contained very little clojure and a lot of craftsmanship. I did find it quite funny with the oh it is not in visual studio so does not exist.
Suggested to me that I can move from test to developer by taking the oracle certified developer exam.
It is nice to work with developers regularly now as we get to talk about different computing topics rather than strictly on topic working remotely. Talking of different architectures Endianness
came up.
I am now on twitter, there seems to be a high noise to signal ratio for some developers I am following. Some good has come from it already, the Not Just Code Monkeys presentation, quite fun and interesting about the use of dark patterns by certain companies.
Researching clojure, good youtube video by Tim Ewald Clojure: Programming with hand tools which contained very little clojure and a lot of craftsmanship. I did find it quite funny with the oh it is not in visual studio so does not exist.
Subscribe to:
Posts (Atom)