Evil Science A whole load of stuff

9Apr/150

Notepad++ Emmet jQuery Template

Here's a little addition I've made for the excellent Notepad++ plugin Emmet. It's a shortcut that creates a HTML5 template with a link to jQuery "jquery-2.1.3.min.js" and a "$(document).ready" function, as shown below.

emmet

It's straightforwards to do, and requires three additions to Emmet's "snippets.json" file, that is located in the Notepad++ direction "\plugins\EmmetNPP\emmet\".

Addition 1, to the section "snippets", a child of "html":

"jqdocready": "\\$(document).ready(function() {\n\n});"

Additions 2 and 3, to the section "abbreviations", a child of "html":

"docjq2":"html>(head>meta[charset=UTF-8]+title{${1:Document}}+script[src=http://code.jquery.com/jquery-2.1.3.min.js]+script[type=text/javascript]>jqdocready)+body",

"html:5jq2":"!!!+docjq2[lang=${lang}]",

In situ, the three additions look like this:

emmet1

emmet2

 

Obviously, make changes at your own risk, but if done correctly, this will work. Cheers m'dears,

Filed under: HTML5, Main No Comments
28Feb/150

jQuery code hinting in Notepad++

Does what it says on the tin:

http://jamesallardice.com/jquery-code-hinting-in-notepad/

Great!

Filed under: Development No Comments
17Nov/140

FastStone Capture – Windows Screen Capture Tool

FastStone Capture is a powerful, flexible and intuitive screen-capture utility. It allows you to capture anything on the screen including windows, objects, full screen, rectangle regions, freehand-selected regions and scrolling windows/web pages.

http://www.portablefreeware.com/?id=775

Filed under: Main No Comments
7Oct/140

Simple C# colour picker

Here's a simple C# colour picker I've created. It's derived from a combobox with a simple override on the OnDrawItem() method. It looks like this:

ColourPicker

And you can find it over on my GitHub page.

This contains no error handling, and is simple as it can be, so use it and your own peril. It's not going to make your computer explode, but you know what I mean. Any problems, feed etc drop me a line.

Filed under: C# No Comments
30May/142

Harry invokes RASHOMON while talking about MALEFICENT!

Harry shows off his impressive ability to skim Wikipedia pages about a movie and then badly compare it to another movie. http://www.aintitcool.com/node/67505

A noteworthy snippet from his review:

Burton’s ALICE IN WONDERLAND is a bizarre strange marvel – and I call it a marvel cuz while watching it…  I marvel at how bizarre it was.

 

 

6May/140

Checking the validity of an NHS Number using 1 line of C#

This article is an implementation of the method for checking NHS Number validity, as described in the article:

http://www.datadictionary.nhs.uk/version2/data_dictionary/data_field_notes/n/nhs_number_de.asp?shownav=0

This is an experiment to reduce the checking method to one line of code, and makes no attempt at being efficient. This single line, below, is arranged into 8 lines to make it easier to read.


pNHSNumber.ToCharArray().Where (i=> i>= 48 && i <=57).Count() != 10 ? false :
new List() { pNHSNumber.ToCharArray()
.Where((value, index) => index < 9)
.Select((value, index) => (10 - index) * (value - 48))
.Sum() }
.Select(i=> i % 11)
.Select(i=> (11 - i) == 11 ? 0 : (11-i))
.First() == (pNHSNumber[pNHSNumber.Length - 1] - 48);

It is constructed as follows:

  • Line 1: Checking the string length is 10 and consists only of digits
  • Lines 2 - 5:  Multiply the first nine digits by a weighting factor and sum, storing the result, a single value, in a generic list.
    • Line 3 : select the first 9 digits of pNHSNumber.ToCharArray()
    • Line 4: Multiply each of the digits by it's weighting - first digit by 10 e.g. (10 - index of 0), second digit by 9 (e.g. 10 minus index of 1) etc
    • Lin 5: sum the values produced by line 4
  • Line 6: Get the remainder of the sum when divided by 11
  • Line 7: Subtract the remainder from 11, and if the resultant value is 11 change to 0
  • Line 8: Test if the check digit is equal to last digit

Usage

Wrap up the above in a function:


bool CheckNNHSNumber (pNHSNumber string)
{
pNHSNumber.ToCharArray().Where (i=> i>= 48 && i <=57).Count() != 10 ? false :
new List() { pNHSNumber.ToCharArray()
.Where((value, index) => index < 9)
.Select((value, index) => (10 - index) * (value - 48))
.Sum() }
.Select(i=> i % 11)
.Select(i=> (11 - i) == 11 ? 0 : (11-i))
.First() == (pNHSNumber[pNHSNumber.Length - 1] - 48);
}

and call it, thusly:


//valid NHS number
Console.WriteLine(CheckNHSNumber("4800963435"));

//invalid NHS Number
Console.WriteLine(CheckNHSNumber("4800963439"));

Filed under: C#, Main No Comments
11Mar/140

Doctor Who missing episode totals by year

DoctorWhoMissingEpisodesRecovery

The above says it all - the number of episodes of Doctor Who missing by year, the reason for the drop is due to pure look and the dedication of Doctor Who fans in searching for missing episodes.

For more information, go to The Destruction of Time: What Is Missing.

Tagged as: No Comments
1Mar/140

iPlayer Automator – download BBC iPlayer programs

Currently, Get iPlayer Automator allows you to download and watch BBC & ITV shows on your Mac. Series-Link/PVR functionality ensures you will never miss your favourite shows. Programmes are fully tagged and added to iTunes automatically upon completion. It is simple and easy to use, and runs on any machine running Mac OS X 10.6 or later.

https://www.macupdate.com/app/mac/39019/get-iplayer-automator

 

 

Filed under: Mac No Comments
25Feb/140

C# Brute Force Sudoku Algorithm

I've created in C# an algorithm that solves sudoku using the brute force method. This algorithm is contained in the class csSudokuBruteForce.cs that can be found on GitHub here.

A little bit about it

The csSudokuBruteForce class contains a class called csCell which represents a cell within a sudoku grid with properties representing the row, column, box that cell belongs to, the cell's value and whether it is solved; 81 of these cells are stored within a generic list called grid which represent sudoku.

The public method BruteForce is called to begin the brute algorithm, which returns a integer array representing the solved sudoku. Testing on Quad core PC shows that solutions can be found in under a second for any tried.

This algorithm doesn't test the validity of the provided sudoku before it starts the brute force algorithm, and may therefore crash out if what is given to it is incomplete, malformed, containing incorrect characters. It just assumes it'll get a string 81 characters in length that consists of only the numbers 1 to 9 and 0.

Using the code

This class is easy to use, and requires only a string of 81 characters representing the sudoku to be solved.  Here's an example of it's use:


csSudokuBruteForce b = new csSudokuBruteForce();

<span style="line-height: 1.5em;">string puzzle = "003020600900305001001806400008102900700000008006708200002609500800203009005010300";</span>

//solve the sudoku and return the result as an integer array

int [] solution =  b.BruteForce(puzzle);

If you're using this code in a C# Console Application and want to output the array containing the solution, here's how to do it using Linq:


Console.WriteLine (
solution.Select((val, ind) => val.ToString() + ((ind+1) % 9 == 0 ? "\n" : ""))
.Aggregate((total, current) => total + current)
);

What about Project Euler 96?

No. I'm not going to tell you how to to solve it.

Go on!

No.

Please?

I'll give you a hand, but no more. Here's how to extract one puzzle at a time from Euler 96's text file of puzzles:


//load the entire sudoku.txt file
List<string> puzzles = new StreamReader("sudoku.txt").sr.ReadToEnd().Split('\n').ToList();

string puzzle;

for (int ctr = 0; ctr <= 49; ctr++)</span>
{

puzzle = puzzles.Where((val, ind) => ind >= (ctr * 10) +1 &amp;amp;amp; ind < (ctr * 10) +10)
.Aggregate((total, current) => total + current);

}

It uses loads the text file into a generic list, and then uses Linq to extract the required data from that file. Use your brain and work out how to use it yourself.

You're welcome.

Filed under: C# No Comments
24Feb/140

A C# algorithm to build interesting cave systems for your Roguelike !!!UPDATE!!!

Export map array as Bitmap

I have noticed that people have expressed an interest in getting an image of the generated map to pass into Unity3D. So I have updated the Github link to add a new function to the class csCaveGenerator.cs, that when called generates a bitmap of the map array, and I have pasted it below for your interest.

/// <summary>
/// Generate a bitmap from the contents of the map array
/// </summary>
/// <returns></returns>
public Bitmap GetMapImage()
{
//adjust to change the pixel size on the image
Size blocksize = new Size(5, 5);

Bitmap bmp = new Bitmap(MapSize.Width * blocksize.Width, MapSize.Height * blocksize.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
using (SolidBrush sbBlack = new SolidBrush(Color.Black))
{
for (int x = 0; x < MapSize.Width; x++)
for (int y = 0; y < MapSize.Height; y++)
if (Map[x, y] == 1)
g.FillRectangle(sbBlack, new Rectangle(x * blocksize.Width, y * blocksize.Height, blocksize.Width, blocksize.Height));

}
}

Filed under: Main No Comments