Sunday, July 6, 2008

[News] My Latest Java

I wrote my first Java program today.
Besides the fact that it's Java, it rocks.

package vk_root;

import java.io.InputStreamReader;
import java.io.BufferedReader;

/*
* This program can find the root of any positive real integer
* at any given (positive real) base.
* It's my first Java program, so please don't laugh at the lameness
* of the code.
*
* raise will *raise* an integer to a given power.
* root will return 0 on failure.
* disp is there because typing out System.out.println() sucks.
* pass makes me (a Python-er) feel at home here.
* stupid is helpful.
* shell interacts with the user.
* main is straight-forward.
*
* This program is command-line aware, e.g;
* $ java -jar vk_java_app.jar 16 2
* 4
* $
*
* I have to stick this in;
* #!/usr/bin/env python
* def root(num, base):
for x in range(2, num/base+1):
if x**base == num:
return x
* >>> root(16, 2)
* 4
*
* *sigh*
*/

public class Main {
public static int raise (int num, int base) {
int copy = num;
for (int pos=1; pos!=base; pos++) {
num = copy*num;
}
return num;
}
public static int root (int num, int base) {
int cap = num/base+1;
int[] range = new int[cap];
for (int start=0; start<=(num/base); start++) {
range[start] = start;
}
for (int pos=0; pos
if (raise(range[pos], base) == num) {
return range[pos];
}
}
return 0;
}
public static void disp(int msg) {
System.out.println(msg);
}
public static int pass() {
return 0;
}
public static void stupid() {
System.out.println("Stop being a dummy.");
}
public static int shell() {
InputStreamReader isr = new InputStreamReader( System.in );
BufferedReader stdin = new BufferedReader( isr );
try {
System.out.println("Enter a number: ");
String in_num = stdin.readLine();
if (in_num.equals("exit")) {
return 1;
}
System.out.println("Enter a base: ");
String in_base = stdin.readLine();
if (in_base.equals("exit")) {
return 1;
}
System.out.println("The root:");
disp(root(Integer.parseInt(in_num), Integer.parseInt(in_base)));
}
catch (java.io.IOException e) {
stupid();
return 0;
}
catch (java.lang.NumberFormatException e) {
stupid();
return 0;
}
catch (java.lang.NegativeArraySizeException e) {
stupid();
return 0;
}
return 0;
}
public static void main(String[] args) {
/*
disp(root(16, 2));
disp(root(49, 2));
disp(root(1000, 3));
disp(root(16,4));
disp(root(625, 5));
*/
try {
disp(root(Integer.parseInt(args[0]), Integer.parseInt(args[1])));
if (args[2].equals("quiet")) {
// UGLY!!!
System.exit(0);
}
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
// System.out.println(e);
pass();
}
System.out.println("(Type exit at any time to stop the application.)");
for (;;) {
if (shell() != 0) {
break;
}
}
}
}

Wednesday, June 18, 2008

[Internet] Opera Wins III

Webmonkey speed test;



This makes Opera, what, almost 4 times faster? Meh. I'll edit and post sunspider next.

Sunday, June 15, 2008

[Programming] Java.

Those of you that know me have undoubtedly heard my bitching about Java. Well, I am going to try and present a un-biased comparison between Java and other languages in relation to functionality. Yes - Rodney, this will be interesting.

[*] Ease of Coding:
> The Winner: Python
Many complain that Python syntax is too lax and that 'a variable can be ANYTHING!!!'.
Well, that's a good thing.
> Why Java Sucks at This:
Java syntax is pretty C-like, and I hate the verbosity. I do prefer Java syntax over Perl's, though Perl is infinitely more useful.

[*] Speed (Execution Time):
> The Winner: C++
I don't even need a valid argument here; if you doubt me, go take your code and write a flawless C++ equivalent. Then bring me profiling results from both projects (or don't, seeing as all I'm going to do is tell you 'I told you so.').
> Why Java Sucks at This:
Unless you can natively run Java bytecode (SPARC comps), then you know that you need a JVM, a JRE, a JDK, an SDK, an IDE, a UML editor, various plugins, lots of time, a high-speed bandwith connection, and lots of patience to get a complete working Java programming environment. I'm talking about 1gb+ of downloads.
After you put up with that crap, your Java code has to compile.
Then, your binary has to call the JVM.
Right before that, the JRE has got to run a trillion checks and prompt you for updates or tell you to by SUN's crap.
Then after the JVM's glacial load time, it will decide whether it feels like interpreting your Java or not.
When it does, it will (very slowly) check your code for errors or deprecated statements.
Then, if it hasn't randomly crashed or had memory leaks or encountered some bizarre error, it will convert the Java bytecode into something your OS can work with. Then, things happen. Slowly.

It can take a noob anywhere up to 4 hours to download & install Java, write a hello world CLI app, and then compile->interpret->and execute it. May I remind you that this can be done in bash with

$ echo "#include iostream.h\n int main(void){std::cout << 'Hello World.\n';}" >> hw.cpp && gcc hw.cpp -O3 -march=native -o hw && chmod 0777 hw && ./hw
#or
$ python -c "print 'Hello World.'"
#or
$ echo 'Hello World'
#or
$ tiemu -mod=83 -BASIC=':ClrHome:DISP "HELLO WORLD."'
#or
$ echo "(printf 'Hello World.')" |xargs mred
#or
$ zenity --info --text "Hello World."
#or
$ brainfuck "++>++++++>+++++<+[>[->+<]<->++++++++++<]>>.<[-]>[-<++>]<----------------. ---------------.+++++.<+++[-<++++++++++>]<.>>+.++++++++++.<<.>>+.------------.---.<<.>>---.+++.++++++++++++++.+.<<+.[-]++++++++++"
?

[*] Least Crappy:
> The Winner: Z80 ASM
No wasted code, fast, efficent (relatively), and powerful.
> Why Java Sucks at This:
Java is full of the essence of SUK.

* I DO expect flame.

[Internet] Opera Wins II.

There have been (in the past, as well as now) comments about Opera's lack of Facebook skillz and image loading issues. Well, suck on this bitches;


This page was loaded very quickly, and it didn't do any of that random 'page shaking' crap Gecko-based browsers (e.g Firefox, Flock) do. Also note that the chat and notification works perfectly, something even the latest firefox3rc sucks at.

Oh, and for you "I like AdBlock too much to switch!" and "Opera doesn't look right!" people, just look at the screenshot. No ads, and definitely a sexier interface than Firefox... Also featuring System Theme integration for Windows AND Linux AND Mac.


---
Yes, I use a Vista theme on XP. As much as I detest all things Microsoft, it makes NO F****** SENSE to press the damn Start button every time you want to shutdown your computer.

Thursday, June 12, 2008

[Other] OWNED! PWNT! LMFAO!








Nuff sed.

[Internet] Opera Wins.

Firefox 3 vs. Opera 9.5? As much as I hate to say this;

Opera WINS. Big time.

This isn't a formal comparison - but let's just consider these things;

* Cold Start Load Time Winner: Opera (by FAR)

* Warm Start Load Time Winner: Opera

* Standards Compliancy Winner: Opera

* Features Winner: Tie!!! Opera lacks features like the cool find and good spellcheck, but firefox is a real resource hog about it.

* Most Likely to be Supported Winner: Firefox (Though YOU can help change that.)

* Cooler Name Winner: Firefox (No contest. Opera is a pretty dumb name, no offense.)

* General Cool Factor Winner: Firefox (Now if Opera goes Open Source and gets a decent ad campaign...)

* Raw Speed Winner: Opera

* CSS/Javascript Speed Winner: Opera (by FAR)

* Page Load Time Winner: Opera

* Innovation/Integration Winner: Opera (it integrates very well with Linux with full static qt and gtk supported binaries - and it has it's own mail and chat and other cool stuff).

Thursday, June 5, 2008

[Other] Obama. Yes.

Obama and Clinton are talking, and to tell you the truth, it's been long overdue.

Well, they have 'spoken' to each other lately, just in a different scope of things (I hope).

In the earlier days, I thought that Ms. Clinton was running a dirty campaign and generally bitching a tad too much, but I realize that in the end - it's helped Obama.

Imagine if all the wonderful BS Clinton pulled out on Obama arose a week before November? Hell for Dems, I'd say.

Let's face it, we know there's going to be a democratic president, and we know now that it's going to Obama.

What we don't know is what the hell he's going to do that will fix partisanship and the remove the murky cloud the 'special interest' groups put over Washington. The rest of the 'issues' would go the same way with either Clinton/Obama I think. Their policies aren't radically different or anything.

If Clinton decides to bitch some more, and NOT run with Obama - the Democrats are going to be divided, weaker, and less likely to get things done!

Proof? Look at Congress. With all of the major talk a while back about the Dems sweeping the houses, we still have plenty of Gridlock, the War is still going on, and our health class [b]still[/b] does not have 1/4 the textbooks it needs (well, not that I'd like to see that one change but still).

Meh. I hope things get fixed.