Site Sponsors:
It's about time ..  
If you ever need a simple way to manage a sortable, logical, human-editable day & time representation, then I cobbled yet another one together from the com.soft9000.DateInfo and com.soft9000.TimeInfo classes this morning:


package com.soft9000.dates;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
* TimeString24: A human-editable, sortable, 24-hour-clock-based time-format reader / writer.
*
* <p>The serialized date delimiter is "/", the time delimiter is ":".</p>
* <p>The ultimate representation is logic-sortable. Human-editable. 24-hour clock.</p>
* <p>Finally, because it is often desirable to put "garbage" into processed date fields,
* the use of &amp;Garbage-In Garbage-Out&amp; (Gigo) setters is supported
* for all individual fields. Note that a -1 in both the month and
* day areas is the isNull() condition.</p>
*
* (BC times, if used, COULD be <b>negative</b>?)
*
* @author profnagy
*/
public class TimeString24 {

private int Year = 0; // Gigo setter.
private int Month = -1; // 1 - 12. Gigo setter
private int Day = -1; // 1 - 31 (Gigo setter, user-specified days-in-month elsewhere are not strictly enforced)
private int Hour = 0; // 0 - 23. Gigo setter (only)
private int Minute = 0; // 0 - 59. Gigo setter (only)
private int Second = 0; // 0 - 59. Gigo setter (only)

/**
* isNull() construction.
*
*/
public TimeString24() {
super();
}

/**
* Create a time string from the classic Date type.
*
* @param date A java.util.Date
*/
public TimeString24(Date date) {
super();
assign(GetInfo(date));
}


/**
* Check to see if null construction was used.
*
* @return True of null construction values are used. False otherwise.
*/
public boolean isNull() {
return (Day == -1 && Month == -1);
}

/**
* Invalidate this object by putting null construction values back in-place.
*/
public void asNull() {
Day = Month = -1;
}

/**
* Assign the values for a date.
* @param Year The year
* @param iMonthNum The month
* @param Day The day
* @return True if all went well.
*/
public final boolean setDate(int iYear, int iMonthNum, int iDay) {
if (iMonthNum < 1 || iMonthNum > 12) {
return false;
}
if (iDay < 1 || iDay > 31) {
return false;
}
this.Year = iYear;
this.Month = iMonthNum;
this.Day = iDay;
return true;
}


/**
* Assign the values for a time.
* @param Hour The hour (24 hour clock)
* @param Minute The standard minute
* @param Second The standard second
* @return True if all went well.
*/
public final boolean setTime(int iHour, int iMinute, int iSecond) {
if (iHour < 0 || iHour > 23) {
return false;
}
if (iMinute < 0 || iMinute > 59) {
return false;
}
if (iSecond < 0 || iSecond > 59) {
return false;
}
this.Year = iHour;
this.Month = iMinute;
this.Day = iSecond;
return true;
}

/**
* Assign the values form a TimeString24.
*
* @param ref a TimeString24
* @return True if all went well.
*/
public final boolean assign(TimeString24 ref) {
if (ref != null) {
this.Second = ref.Second;
this.Minute = ref.Minute;
this.Hour = ref.Hour;
this.Day = ref.Day;
this.Month = ref.Month;
this.Year = ref.Year;
return true;
}
return false;
}

/**
* Pad-out an integer representation to the desired, sortable, size.
*
* @param iVal The integer
* @param minSize The file size (can be greater, will not be less)
* @return A string-parsable integer, as prefixed by '0' up-to the desired
* size.
*/
public static String Pad(int iVal, int minSize) {
if (minSize <= 0) {
minSize = 1;
}
boolean bNeg = false;
if (iVal == -1) {
bNeg = true;
minSize--; // negative sign will use a space -
iVal = java.lang.Math.abs(iVal);
}

StringBuilder sb = new StringBuilder();
sb.append(iVal);
if (sb.length() < minSize) {
int count = minSize - sb.length();
sb = new StringBuilder();
for (int ss = 0; ss < count; ss++) {
sb.append('0');
}
sb.append(iVal);
}
if (bNeg) {
String str = sb.toString();
sb = new StringBuilder();
sb.append("-");
sb.append(str);
}
return sb.toString();
}

/**
* Get the default "Date Only" string.
*
* @return YYY/MM/DD format
*/
public String adDateOnly() {
return (Pad(this.Year, 4) + "/" + Pad(this.Month, 2) + "/" + Pad(this.Day, 2));
}

/**
* Create a TimeString24() for the present second.
*
* @return An up-to-the-second TimeString24()
*/
public static TimeString24 GetToday() {
return GetInfo(GetDate());
}

/**
* Get today's Date
*
* @return Today's java.util.Date.
*/
public static Date GetDate() {
Calendar cal = new GregorianCalendar();
Date date = cal.getTime();
cal = null;
return date;
}

/**
* Create a TimeString24 from the classic Date type..
*
* @param date A classic Java Date type.
* @return Always returns a TimeString24.
*/
public static TimeString24 GetInfo(Date date) {
Calendar cal = new GregorianCalendar();
cal.setTime(date);
TimeString24 info = new TimeString24();
info.Year = cal.get(Calendar.YEAR);
info.Month = cal.get(Calendar.MONTH) + 1;
info.Day = cal.get(Calendar.DAY_OF_MONTH);
info.Hour = cal.get(Calendar.HOUR_OF_DAY);
info.Minute = cal.get(Calendar.MINUTE);
info.Second = cal.get(Calendar.SECOND);
cal = null;
return info;
}

/**
* Create a TimeString24 from the default toString() representation.
*
* @param sLine The toString() representation. The format is "2012/02/05
* 09:01:10"
* @return <font color='red'>NULL on error</font>.
*/
public static TimeString24 FromString(String sLine) {
if (sLine == null) {
return null;
}
TimeString24 result = new TimeString24();
if (result.fromString(sLine) == true) {
return result;
} else {
return null;
}
}

/**
* Format "2012/02/05 09:01:10"
*
* @return The parsable (fromString()) format.
*
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(Pad(this.Year, 4));
sb.append("/");
sb.append(Pad(this.Month, 2));
sb.append("/");
sb.append(Pad(this.Day, 2));
sb.append(" ");
sb.append(Pad(this.Hour, 2));
sb.append(":");
sb.append(Pad(this.Minute, 2));
sb.append(":");
sb.append(Pad(this.Second, 2));
return sb.toString();
}

/**
* Format "2012/02/05 09:01:10"
*
* @param sLine The classic "ENGLISH STRING" to parse
* @return True on success
*/
public boolean fromString(String sLine) {
String str = sLine.replaceAll("/", "\t");
str = str.replaceAll(":", "\t");
str = str.replaceAll(" ", "\t");
String[] array = str.split("\t");

try {
if (array.length == 6) {
this.Year = Integer.parseInt(array[0]);
this.Month = Integer.parseInt(array[1]);
this.Day = Integer.parseInt(array[2]);
this.Hour = Integer.parseInt(array[3]);
this.Minute = Integer.parseInt(array[4]);
this.Second = Integer.parseInt(array[5]);
return true;
}

} catch (Exception ex) {
}
assign(new TimeString24()); // null
return false;
}

/**
* @return the Day
*/
public int getDay() {
return Day;
}

/**
* @return the Hour
*/
public int getHour() {
return Hour;
}

/**
* @return the Minute
*/
public int getMinute() {
return Minute;
}

/**
* @return the Month
*/
public int getMonth() {
return Month;
}

/**
* @return the Second
*/
public int getSecond() {
return Second;
}

/**
* @return the Year
*/
public int getYear() {
return Year;
}

/**
* @param Day the Day to set. Gigo
*/
public void setDay(int Day) {
this.Day = Day;
}

/**
* @param Hour the Hour to set. Gigo
*/
public void setHour(int Hour) {
this.Hour = Hour;
}

/**
* @param Minute the Minute to set. Gigo
*/
public void setMinute(int Minute) {
this.Minute = Minute;
}

/**
* @param Month the Month to set. Gigo
*/
public void setMonth(int Month) {
this.Month = Month;
}

/**
* @param Second the Second to set. Gigo
*/
public void setSecond(int Second) {
this.Second = Second;
}

/**
* @param Year the Year to set. Gigo
*/
public void setYear(int Year) {
this.Year = Year;
}
}


'Gotta love these quiet mornings!

-Rn


[ view entry ] ( 1358 views )   |  permalink  |  related link
Banman: An easy way to protect web content 
We just release a new project. Know as "Banman", the project is designed to stop robots from stealing web content.

Uploading the content of the zip file + renaming index_example.php to index.php will create a complete web site experience.

By default (*), logs are stored under the "ban_ip_list" folder. If logging does not seem to work & reports are not showing-up, then be sure to enable write-and-read access to whatever you change the banned.php::$dir_only_ip variable to.

(*) Since Banman is new, for the moment it would be relatively safe to use the default file & folder names. By all means run it a few times using the defaults.

After you decide to use the program, at a minimum consider changing both the name of the sub-folders, as well as the name the "banman.php" webmaster interface.

Also note that the variables listed in the default html view should also be changed. -While great for demonstrating what Banman can do, their values are set way too strict for most user-facing 'web applications.

Enjoy!

R.A. Nagy
President
Soft9000.com

[ view entry ] ( 2336 views )   |  permalink  |  related link
PHP = Fast & Cheap? 
Okay - I admit it - I am careful. So careful in fact, that what our CLIENTS pay us to do from 9-5 is pretty much the OPPOSITE of what we do on the weekends.

The difference, I suppose, is time. Unlike many, we simply have no time to keep doing things over & over & over again...

So while we work on many a trendy 'tech for-hire, here in the home office using excessive, expensive, toss-out technologies is simply a "no no."

Why? Because - much like upgrading a word processor - we seldom find need to use the hottest new features. The right tool, for the right job?

Indeed, no matter how easy a vendor makes it for us to use their latest opiate, the fact remains that we've simply only had enough time to ''do things over'' about ... uh ... once per decade?

So as we also junked the heavyweight database - even the free stuff - in favor of using flat files, this weekend we decided to show off a little flat-file goodness under PHP.

You can see the results for yourself. While far from complete, the effort for the weekend was a nice face-lift for my oldest web-site (since 1997!) -Known as The Quote For Today, not only does that site run on a rinky-dink shared little server, but it does so far faster & better than it ever did while running under the more expensive stuff...

So here's to faster, cheaper... & better?

(... and our tech was not even 20 years old... Perhaps this means that even MODERN undertakings (let alone ancient space programs) can indeed enjoy all three, with the choice of only two?)

Enjoy the site,

-Rn

[ view entry ] ( 5549 views )   |  permalink  |  related link

<<First <Back | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | Next> Last>>