Why So Scared

A blog about; Programming, Music and Random Stuff

Archive for November, 2009

Vodaphone UK MMS Contract Settings

APN: wap.vodafone.co.uk
Username: wap
Password: wap
MMSC: http://mms.vodafone.co.uk/servlets/mms/
MMS Proxy: 212.183.137.012 (note the leading zero in the last octet)
MMS Max Message Size: (blank)
MMS UA Prof URL: (blank)

MMS_Screenshot

Tags:
posted by Juo in tidbit and have Comment (1)

Java Code – Shuffle A Pack Of Cards

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;

public class shuffle {

  public shuffle(){
    window.setSize(1100,550);
    window.setLayout(new FlowLayout());
    JLabel cards[] = new JLabel[52];
  int number = 0;
  int [] ranarray = new int[52];
  boolean used[] = new boolean[52] ;

  Random generator = new Random();

  for (int i = 0; i < 52; i++) {
    do { number = generator.nextInt(52); }
      while(!used[number] == false); //while number has been used before try again
        {
           ranarray[i] = number; //unique number? add it to the array
           used[number] = true; //set number to true for comparison
        }
     }

    for (int i = 0; i < 52; i++) {
    cards[ranarray[i]] = new JLabel(new ImageIcon("cards/" + ranarray[i] + ".png")); //display cards
    window.add(cards[ranarray[i]]); //add cards
     }

    //show the window
    window.setVisible(true);

    }

  private JFrame window = new JFrame("Shuffle");

  //open Shuffle
  public static void main(String[] args){
    new shuffle();

  }

}

Copy of code hosted at http://pastie.org/755948

Code saved as Shuffle.java

Tags:
posted by Juo in Java and have Comment (1)

Java Code – TicTac

import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import javax.swing.*;

public class TicTac implements ActionListener {

  public TicTac(){
    window.setSize(150,150);
    window.setLayout(new GridLayout(3,3));

    // display the buttons, smaller code with loop
    for(int i=0; i<=8; i++){
      buttons[i] = new JButton();
      window.add(buttons[i]);
      buttons[i].addActionListener(this);
    }
 Read more...
Tags:
posted by Juo in Java and have No Comments

Java Code – How Old Are You?

import java.util.Calendar;
import java.io.*;
import javax.swing.JOptionPane;

public class Age{
    public static void main(String args[])
    {
        String year = JOptionPane.showInputDialog
        ("Please Enter Your Year of Birth:");
        String month = JOptionPane.showInputDialog
        ("Please Enter The Month You Where Born:");
        String day = JOptionPane.showInputDialog
        ("Please Enter The Day You Where Born:");

        int y = Integer.parseInt(year);
        int m = Integer.parseInt(month);
        int d = Integer.parseInt(day);

        Calendar rightNow = Calendar.getInstance();
    	int yearnow = rightNow.get(rightNow.YEAR);
    	int monthnow = rightNow.get(rightNow.MONTH);
    	int daynow = rightNow.get(rightNow.DAY_OF_MONTH);
    	monthnow++;
    	yearnow -= y;
    		if (m>monthnow || m == monthnow && d>daynow)
    		{
    			yearnow--;
    		}
        JOptionPane.showMessageDialog
        (null, yearnow);
    }
}

Copy of code hosted at http://pastie.org/684706
Code saved as Age.java

Tags:
posted by Juo in Java and have Comment (1)

Parse MusicBrainz XML with jQuery

For a project I’m working on to help people make posts over at http://www.warez-dnb.com/ i’ve been looking into parsing MusicBrainz, I thought id make a quick post to discuss the challenges and solutions I’ve come up with so far.

<html>
 <head>
 <script type="text/javascript" src="jquery.js"></script>
 <script type="text/javascript">
 $(document).ready(function(){
	$.ajax({
		type: "GET",
		url: "http://www.warez-dnb.com/test/getid.php?name=Caspa",
		dataType: "xml",
		success: function(xml) {
			$(xml).find('artist-list').each(function() {

				alert($(this).find("name").text());
			});
		}
	});
 });
 </script>
 </head>
 <body>

 </body>
</html>



This is the index.html file and jQuery code, its pretty simple, I was just testing that I could get a valid connection, then parsing the XML within artist-list and outputting anything that has the XML tag name

One question that might arise from looking at this code is why the url is hosted at warez-dnb, jQuery wont let you import XML from a remote web host, it has to be from the local server, i’ve written an extremely simple PHP function that will query musicbrainz and copy the result it gets to host it locally.

<?php
// Set your return content type
header('Content-type: application/xml');

// Website url to open
$daurl = 'http://musicbrainz.org/ws/1/artist/?type=xml&name=' . $_GET["name"];

// Get that website's content
$handle = fopen($daurl, "r");

// If there is something, read and return
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>
posted by Juo in Programming, jQuery, tidbit and have No Comments