Why So Scared

A blog about; Programming, Music and Random Stuff

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...
posted by Juo in Java and have No Comments
Tags:

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

posted by Juo in Java and have No Comments
Tags:

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

Configure ItsHidden with iPhone

With an increasing number of online users seeking solutions to hide their identities from the outside world, privacy services have seen a spike in customers recently. The most common and widely used privacy services are VPNs that allow users to connect to the Internet while hiding their own IP-address.

Ive been using ItsHidden a great free VPN service that allows for 1mbps of free unlimited traffic, I thought this sounded perfect to use on my iPhone, here is how to configure the iPhone to tunnel all internet traffic through ItsHidden

Read more…

posted by Juo in iPhone and have No Comments
Tags:

Terminal Command Mac Create RAR Archives

If you want to pack your files into RAR’s then use this simple Terminal command

rar a -v100000 MySplitRarArchive

rar a -v100000 MySplitRarArchive

where -vxx is the file size of each of the RAR files in kb’s

posted by Juo in tidbit and have No Comments