Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Friday, 23 December 2016

WoW - Text Colour Codes


WoW - Add Button to Target Dropdown Menu

I was having a real issue trying to add buttons to the target right click dropdown menu in WoW.

After posting on a few questions on the CurseForge, WoW Interface and WoW UI & Macro forums without much success, I pulled apart the AddFriend addon and created the following chunk.

local function testDropdownMenuButton(self)
if self.value == "GreenButton" then
print("GreenButton clicked")
elseif self.value == "RedButton" then
print("RedButton clicked")
else
print(" WTF how did I fail?")
end
end

hooksecurefunc("UnitPopup_ShowMenu", function()
if (UIDROPDOWNMENU_MENU_LEVEL > 1) then
return
end
local info = UIDropDownMenu_CreateInfo()
info.text = "Dropdown Menu Button"
info.owner = which
info.notCheckable = 1
info.func = testDropdownMenuButton
if UnitName("target")=="Tauren Commoner" or UnitName("target")=="Orgrimmar Brave" then
info.colorCode = "|cff00ff00"
info.value = "GreenButton"
else
info.colorCode = "|cffff0000"
info.value = "RedButton"
end
UIDropDownMenu_AddButton(info)
end)

This is the most economical solution that I could work out, (proper coders could probably reduce the code further but this did work for me).
I also decided to have the button click to run a separate function for the sake of clarity.

I hope that this can provide benefit to other beginners.

Tuesday, 3 November 2015

Friday, 28 March 2014

Sunday, 11 August 2013

RegEx - Regular Expresions

I have been playing with RegEx in Java more and more, and it is fun working out how they work and even built some myself.

I needed RegEx to perform checks on strings to validate password and email strings.

Finding RegEx to check if a string has either capitals, lowercase or numbers was quite easy :-

Capital = ".*[A-Z].*";
Lowercase = ".*[a-z].*";
Number = ".*[0-9].*";

Finding Email validation RegEx was a bit harder as there are many different compositions, some being quite loose and others being way to precise.

After a lot of testing I settled on this one :-

Email = "\\b(?!,|/)(\\w+)(?!,|/)((-?\\w+)*)?(?!,|/)(\\.{1})?(\\w*)?@{1}(\\w*)(?!,|/)((-?)(\\w*)?)(?!,|/)(\\.{1}\\w+){1,2}\\b";

But finding a RegEx to find a symbol in a string was a bit harder still.

I read many many forums and tutorials and tried many many different compositions.

I even built an array of every RegEx I had built for each individual symbol using a break before each symbol to ensure no meta characters slipped by :-

@ Symbol = ".*[\\@].*"

Then I looped through he array and tested against my test stings.

Sure it worked, but what a lot of code for something that I though should have been quite straight forward.

Then after far too many hours I looked at this problem from a different angle, if I could not reliably test a string for a symbol why not test a string for a character that was not a capital, lowercase, whitespace, underscore or number.

So I built the following :-

 Regex = ".*[^A-Za-z0-9!@#$%^&*()_+=-{}~`].*";

In RegEx ^ = not, similar to Java ! = not.

This works but once again I am still defining each symbol.

So I kept working and testing until I built :-

BetterRegex = ".*[^A-Za-z0-9\s].*";

It took me far to long but wow I had some fun.

Now it is time to relax ... relax and eat chocolate.


Thursday, 8 August 2013

RegEx - Regular Expresions

RegEx, (Regular Expresions), are truncated code strings that can be used to search other strings for patterns of characters.

RegEx are a lot of fun to play with.


http://en.wikipedia.org/wiki/Regular_expression

A great resource site that can help teach, test and share RegEx strings.

http://gskinner.com/RegExr/

Friday, 24 May 2013

SQL

SQL

Wow my first taste of SQL and it is so much fun.

First download WampServer at http://sourceforge.net/projects/wampserver/?source=dlp

Here is my first go 

First I create the database -
create database MyFirstDatabase;

Now that it is created I can use it -
use MyFirstDatabase;

Now I create a table in the database, and define the data format for each of  the table fields -
create table MyFirstTable (TableID int auto_increment primary key, TableValue varchar (200) not null);

Now I can see my table and the format of the table -
show columns from MyFirstTable;

Now I can insert data into the first row -
insert into MyFirstTable (TableValue) values ('Hello World');

And now I can check the data in my table -
select * from MyFirstTable;

Some great online resources for SQL, (and most other languages), are

StackOverflow   http://stackoverflow.com

W3Schools   http://www.w3schools.com

Wednesday, 8 May 2013

Java Color - RGB to Hex


Wow I have had fun today.

I wanted to random generate RGB colors and then convert them to Hex.

I could not use the random generated Red Green Blue colors directly to form a Hex color as the generated numbers could be 1,2,3 characters long. 

It took me a good while with lots of reading an experimentation.

First create int variables that will random each Red Green Blue value.
int red = (int) (( Math.random()*255)+1);
int green = (int) (( Math.random()*255)+1);
int blue = (int) (( Math.random()*255)+1);

Instantiate an instance of Color that will uses the random generated Red Green Blue color ints.
Color RandomC = new Color(red,green,blue);

Create an int that will get the RGB values from the color.
int RandomRGB = (RandomC.getRGB());

Create a String that will convert RandomC RGB values to a HexString.
String RandomRGB2Hex = Integer.toHexString(RandomRGB);

Create an int variable that will convert the HexString to a HashCode.
int EndRGB = RandomRGB2Hex.hashCode();

And now you have a random generated HexCode.

Quite  a few steps, and no doubt within 10 min of posting this I will find a much easier and quicker way.

But for now I am happy that this flow works.

Monday, 15 April 2013

Java JPanel JFrame


I am still trying to get hold of the Aero Glass window borders on to my JPanel and JFrame.

But I have found some help to make JPanel borders translucent.

http://stackoverflow.com/questions/7035583/how-to-add-windows-aero-effects-to-a-jpanel/7036346#7036346

http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html


Original Post Oct 16th 2012


Java Color


Java basic colors are heavy and few.

eg.   setBackground(Color.orange);


But if you want your frames to match your OS colors you can access them;

eg.   setBackground(SystemColor.inactiveCaption);

http://nadeausoftware.com/node/105#UsingJavasSystemColors


Or even better yet use a hex code; 

eg.   setBackground(Color.decode(“#FFFF00”));

Original Post Oct 15th 2012

Ascii Key - print to Console


This line of code will display the Ascii key number for each key pressed.

console.log(evt.keyCode);

Original Post Oct 31st 2012

Fibonacci - revisited


Wow, Grey Wolf continues to astound me.

He rewrote the Fibonacci JavaScript so that it builds an array and then returns the index value you wanted.
This allows for greater calculation values and no longer crashes your pc.
Negative values are a bit strange and huge numbers will more than likely return infinity.
var fibTicks = 0;

var FibonacciTerms = new Array();

 function fibonacciR(term) {

// recursive fibonacci method (the higher the number the more times the method gets called until we get to 1)

// we could use an array and iterate the array to find the value this would then be known as an iterative method.

// values greater than 30 are likely to crash javascript, for large numbers it is advised to use a language such as python using the recursive method.

fibTicks++;

if (term<=1) return term;

else return fibonacciR(term-1)+fibonacciR(term-2);

}

 function fibonacciI(n) {

// iterative method, here we are creating a loop which will determine what the next term is, append it to an array of terms until it reaches the dssired number

var neg = false;

if (n < 0) { n = n - n - n; neg = true; } // deal with negatives (we could just return an error here)

fibTicks = 0;

var i = 2; // we already have the 0th and first term so start counting from the 2nd term

FibonacciTerms = new Array(0,1); // clear the list of terms, add the 0th and 1st term

while (i <= n) { // loop through until we reach the desired term

fibTicks++;

FibonacciTerms.push(FibonacciTerms[i-1]+FibonacciTerms[i-2]); // add the term to the array

i++; // add 1 to our loop incrementor

} // end of loop

var r = FibonacciTerms[n]; // put the N’th term in to variable ‘r’

if (neg == false) return r; // exit the function giving back the number stored in ‘r’

else return r-r-r; // exit the function giving back the negative value for the number stored in ‘r’

}

Original Post Sep 2nd 2012

Campus Project Team A


UML Model


  • There are many buildings on campus.
  • Each building has a building number, a number of exits, and contains many rooms.
  • Each room has a room number, a room size, and a seating capacity.
  • Some rooms are computer labs and have many computers.
  • Each computer has an asset number and a tag & test date
  • Some rooms have a single overhead data projector.
  • Each overhead data projector has an asset number and a tag & test date.


Additional functionality/notes:

  • Add & remove buildings from campus.
  • Add & remove rooms from building.
  • A building must have a unique building number.
  • A room must have a unique room number.
  • Campus rooms can be searched by room number, to return the matching room.
  • Campus rooms can be searched by seating capacity, to return the matching rooms.
  • Computers & overhead data projectors must have a unique asset number.

Original Post Aug 20th 2012

Fibonacci



Fibonacci just blows my mind

Grey Wolf is amazing and helped me greatly with the following HTML + Javascript to test fibonacci principals based on a couple khanacademy video’s

Caution entering a value of 45 and above may cause serious lag or even crash issues

<body>
<h1> Fibonacci </h1>
<br><br>
<form>
<table>
<tr>
<th style=”text-align:center”>Enter Number</th>
</tr>
<tr>
<td><input type=”text” id=”fn” autocomplete=”off”/></td>
</tr>
<tr>
<td align=”center”><input type=”button” value=”Fibonacciate” onclick=”runFib();”/></td>
</tr>
</table>
</form>
<br><br>
<form>
<table>
<tr>
<th style=”text-align:center”>Fibonacci Jumps</th>
</tr>
<tr>
<td><input id=”fibonacci” readonly=”readonly”/></td>
</tr>
</table>
</form>
</body>

<script>
//Fibonacci function
fibonacci = function(fib) {
if (fib<=1) return fib;
else return fibonacci(fib-1) + fibonacci(fib-2);
}
//Run fibonacci function
runFib = function() {
var fib = document.getElementById(“fn”).value;
var v = fibonacci(fib);
document.getElementById(“fibonacci”).value=v;
}
</script>

Original Post Aug 15th 2012

Group Activity - Inheritance



A Player has the following attributes: 

  • Name
  • Health
  • Strength
  • intelligence
  • Location
    • X coordinate
    • Y coordinate
  • Inventory
    • a collection of InventoryItem's - each InventoryItem has the following attributes
      • ID
      • Price
      • Weight.
A Weapon is a type of InventoryItem. It has a single int attribute: DPS. 
  • An object of Weapon type may be constructed with or without providing a value for this attribute. 
    • A Gun is a type of Weapon. It has a single int attribute: ammoCount. A value for this attribute must be provided in the constructor. 
    • A Stick is a type of Weapon. It has a single int attribute: stickLength. A value for this attribute must be provided in the constructor.


A Tool is a type of InventoryItem. It has a single int attribute: numberOfUses. 

  • An object of Tool type may be constructed with or without providing a value for this attribute. 
    • A Key is a type of Tool. It has a single String attribute: keyName. A value for this attribute must be provided in the constructor. 
    • A Mirror is a type of Tool. It has a single String attribute: mirrorName. A value for this attribute must be provided in the constructor.


Original Post Jul 29th 2012

Inheritance Scenario: XYZ



yClass is a type of xClass. 

A XClass has 3 int states, x,y & z. 

An object of the xClass may be created by providing a value for all 3 of these states and also by providing only x & y. 

The yClass has 2 int states, a & b. 

An object of the yClass may be created by providing a value for a, or values for both a & b. 

The zClass is a type of yClass and has 1 int state called c. 

An object of the zClass may be created with or without supplying a value for c.

Original Post Jul 23rd 2012

Delimiters, Splits, Tokens, and Meta- Characters



So we have this text file that is full of World information on 10 players.

Each Player has the following information;

  • World Name
  • Player Name
  • Player Health
  • Player Strength
  • Player Intelligence
  • Player Location   -   each Player has a starting location
    • each location has 2 coordinates
      • X co-ordinate
      • Y co-ordinate
  • Player Inventory   -   each Player has 10 Items in their Inventory
    • each Item has 5 bits of Information 
      • Item Name
      • Item ID
      • Item Weight
      • Item Value
      • Item Level 

Now this information is all held in this World text file, but how do we read it effectively, it just seems to be a random wall of text.

We use a Delimiter.

In this case the delimiter is set as   ;

What that means is when we scan the text file each character preceded by   ;   will be recorded as a string.

Each of these strings is called a token.

Each token can be broken down further into smaller tokens using the split function.

In this case we have

  First split     :
  Second split     @
  Third split     *
  Fourth split     #
  Fifth split     ?

The issue we come across is that some characters already have assigned functions; these are called Meta- Characters, and using them as delimiters and splits will cause hang and crash issues.

Meta-Characters      .  ^  $  |  *  +  ?  (  )  [  {  \  

If you precede Meta-Characters with two forward slashes \\ it will turn them into a literal character.

eg.    scan.useDelimiter(”\\? “)     or    String[] StringName = Token.split(”\\* “)

Original Post Jun 30th 2012