Skip to main content

Posts

vrms - Virtual Richard M. Stallman

Though I am aware that there are non-free packages lurking in my box, I want to be precise, thanks to Virtual Richard M. Stallman . Non-free packages installed on linux-conqueror fglrx-modaliases Identifiers supported by the ATI graphics driver linux-generic Complete Generic Linux kernel linux-restricted-modules- Non-free Linux 2.6.28 modules helper script linux-restricted-modules- Restricted Linux modules for generic kernels nvidia-173-kernel-source NVIDIA binary kernel module source nvidia-173-modaliases Modaliases for the NVIDIA binary X.Org driver nvidia-180-modaliases Modaliases for the NVIDIA binary X.Org driver nvidia-71-modaliases Modaliases for the NVIDIA binary X.Org driver nvidia-96-modaliases Modaliases for the NVIDIA binary X.Org driver nvidia-glx-173 NVIDIA binary Xorg driver skype Skype - Take a deep breath tangerine-icon-theme Tangerine Icon theme virtualbox-3.0 Sun Virt...

Linus’ discussion about goto statements

As discussed by Linus Torvalds 6 years ago, From: Linus Torvalds Subject: Re: any chance of 2.6.0-test*? Date: Sun, 12 Jan 2003 12:22:26 -0800 (PST) On Sun, 12 Jan 2003, Rob Wilkens wrote: > > However, I have always been taught, and have always believed that > “goto”s are inherently evil. They are the creators of spaghetti code No, you’ve been brainwashed by CS people who thought that Niklaus Wirth actually knew what he was talking about. He didn’t. He doesn’t have a frigging clue. > (you start reading through the code to understand it (months or years > after its written), and suddenly you jump to somewhere totally > unrelated, and then jump somewhere else backwards, and it all gets ugly > quickly). This makes later debugging of code total hell. Any if-statement is a goto. As are all structured loops. And sometimes structure is good. When it’s good, you should use it. And sometimes structure is _bad_, and gets into the way, and usi...

What is going on?

Warning: Pure train of thought. My primary hard drive has crashed so I have to switch to Windows temporarily. There is nothing special happening lately except for the fact that I am enjoying life to the fullest. I can say that I am on the right track. I really thank God for that. Personal projects are keeping me busy these days. Next month I will be pursuing my MSCS degree. Hopefully this time, I am mature enough to handle school stuffs. Anyway here are stuffs for you to check, When Nature is Freakier than Sci-Fi Artificial Intelligence Blizzard Entertainment CitiSecOnline - Philippines Online Stockbroker

IBM Signed Numeric Table

If you are dealing with IBM mainframes, you will see signed numbers written this way. { = 0 } = -0 A = 1 J = -1 B = 2 K = -2 C = 3 L = -3 D = 4 M = -4 E = 5 N = -5 F = 6 O = -6 G = 7 P = -7 H = 8 Q = -8 I = 9 R = -9 Enjoy! “Stupidity is doing the same things repeatedly and expecting different results!”

Recovering from a checked exception in Java

If you are working on the back-end, this might be of use. Very trivial but rarely used. /** * This class demonstrates how to recover from checked exceptions * @author Joset */ public class CheckedExceptionRecovery { /** * @param args the command line arguments */ public static void main(String... args) { InputStreamReader inputStreamReader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); int input = 0; boolean done = false; do { try { System.out.println("Please enter an integer: "); input = Integer.parseInt(bufferedReader.readLine().trim()); done = true; } catch (NumberFormatException numberFormatException) { System.out.println("Invalid input. Please try again."); } catch (IOException ioException) { System.out.println("C...

Controller (MVC) Tips for Java Servlets / JSP

I was inspired by a face-to-face technical interview awhile ago that is why I am writing this down. To avoid having the Servlet’s doXXX() methods clogged, use reflection by breaking down your controller code into modules. Here’s how. You must have the following. 1. Reflection Interface (ServletHandler.java) - An interface for reflection. Nice definition! 2. Main Servlet (MainServlet.java) - A class extending HttpServlet. 3. Module Handler (CreditHandler.java) - A class containing the module’s controller code, for this example, the Credit Module. in file ServletHandler.java , import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public interface ServletHandler { public abstract void setServlet(HttpServlet servlet); public abstract void handle(HttpServletRequest request, HttpServletResponse response); } in file MainServlet.java , protected void doGet(HttpServletRequest r...

Method Piercing in Java

There’s nothing new here. I just want to reiterate though. class TargetClass { private static String DB_PASSWORD = "sw0rdfish"; private static String getDatabasePassword() { return DB_PASSWORD; } } And the attack? import java.lang.reflect.Method; public class ClassPiercing { public static void main(String... args) throws Exception { Class targetClass = Class.forName("TargetClass"); Method[] methods = targetClass.getDeclaredMethods(); methods[0].setAccessible(true); String databasePassword = (String)methods[0].invoke(null, null); System.out.println("Database Password: " + databasePassword); } } Output: Database Password: sw0rdfish Check out Val’s Blog by clicking [here] . He has more examples.

Sad reality about Wrapper Classes in Java

Consider the snippet. Integer firstInteger = 1000; // autoboxing Integer secondInteger = 1000; //autoboxing if (firstInteger != secondInteger) { System.out.println("Different objects!"); } if(firstInteger.equals(secondInteger)) { System.out.println("Meaningfully equivalent!"); } Output: Different objects! Meaningfully equivalent! How about this one. Integer firstInteger = 100; // autoboxing Integer secondInteger = 100; //autoboxing if (firstInteger == secondInteger) { System.out.println("Equal objects!"); } if(firstInteger.equals(secondInteger)) { System.out.println("Meaningfully equivalent!"); } And the output? Equal objects! Meaningfully equivalent! And the explanation? Two instances of the wrapper objects will always be == when their primitive values are the same. - Boolean - Byte - Character from \u0000 to \u007F (0 to 127) - Short from -128 to 127 - Integer from -128 to 127 Tsk.

MD5 Hashing in Java

This is useful for storing passwords in a database though still vulnerable to md5 dictionary attacks, anyway, here’s a static method. public static String hash(String text) { String hashedString = ""; try { MessageDigest md5Hash = MessageDigest.getInstance("MD5"); md5Hash.update(text.getBytes(), 0, text.length()); hashedString = new BigInteger(1, md5Hash.digest()).toString(16); } catch (NoSuchAlgorithmException exception) { exception.printStackTrace(); } return hashedString; } This will return the MD5 hash. Have a great day!