Published at: 07:10 am - Friday October 02 2009
For all those Java programmers who feel lonely in the land of .NET – here’s a class just for you!
using System;
namespace Biz.Your.Company.Goes.Here.Util
{
public sealed class SuccessException : Exception
{
public SuccessException() : base()
{
System.Environment.Exit(1);
}
public SuccessException(string msg) : base(msg)
{
System.Environment.Exit(1);
}
public SuccessException(string msg, Exception exception) : base(msg, exception)
{
System.Environment.Exit(1);
}
}
}
Published at: 06:03 pm - Friday March 27 2009
Comments are only effective if they threaten abuse.
/**
* Note: The following array MUST be sorted in order for BinarySearch to work. I have taken the liberty of
* creating it sorted to avoid this operation. If you really feel the need to break the manual sorting,
* uncomment the array.sort below this, and then go out and stand in front of traffic. thank you.
*/
string[] allowed_items = {"activate", "restore", "save", "update-relay", "verify-mount", "verify-restore"};
//Array.Sort(allowed_items);
if (Array.BinarySearch(allowed_items, list) >= 0) {
/* -.v.- */
}
Discovered by Noah Massey.
Published at: 08:03 am - Wednesday March 25 2009
Make sure you cover all your bases when reseting variables:
if ($flag == "yes") {
$form->creationDate = null;
$form->runCount = 0;
$form->statusCode = 1;
} else {
$form->creationDate = null;
$form->runCount = 0;
$form->statusCode = 1;
}
Discovered by @zewillow
Published at: 05:03 pm - Tuesday March 24 2009
Always run non-existent commands after unreachable code.
if [ `id -u` != 0 ]; then
sudo $0
exit $?
fi
if [ `dpkg -l | grep sun-java5 | wc -l` -eq 0 ]; then
sh /media/cdrom0/application/appupgrade; # causes reboot
else
sh /media/cdrom0/application/sysupgrade; # causes reboot
fi
sudo updat-java-alternatives -s java-6-sun;
exit 0;
Discovered by Noah Massey.
Published at: 12:03 pm - Wednesday March 18 2009
Readability is always more important than simple one-liners:
if ($form->minute == 0) {
$minute = "00";
} else if ($form->minute < 10) {
$minute = "0" . $form->minute;
} else {
$minute = $form->minute;
}
Discovered by @zewillow.
Published at: 02:03 pm - Tuesday March 17 2009
Always make sure your variables are properly initialized:
$list = $_SESSION['list'];
if ($list == null || $list == "") {
$list = $_SESSION['list'];
}
Discovered by @zewillow