Site Sponsors:
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

[ add comment ] ( 2251 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

[ add comment ] ( 5494 views )   |  permalink  |  related link
Parsing JSON using GSON 
IMHO, Google is fast emerging as the coolest mecca for plus-one innovations. -From Android (+1 on Java / Blackberry) to GWT (+1 on CORBA / XDR), there is simply no better place to watch savvy engineers "embrace and extend" several time-proven ideas.

Such is the case with Google's GSON for Java-Script Object Notation (JSON) (a +1 on json.org): Designed to be a better way to move data in and out of our projects (also known as "serialization"), Google's effort to one-up the ante around the "Fame, Fortune, or Fun" table should get our propellers spinning.



For example, SourceForge.net (also +1'ed by Google eventually hosting their OWN open software developer site) offers an excellent way to query their hosts for the stats on a project.


{
"oses": [["Windows", 29], ["Unknown", 5], ["Linux", 4], ["Macintosh", 2]],
"end_date": "2012-01-20 00:00:00",
"countries": [["United States", 16], ["Italy", 8], ["Ghana", 3], ["Romania", 3], ["United Kingdom", 3], ["Germany", 3], ["Egypt", 1], ["Israel", 1], ["France", 1], ["Hong Kong", 1]],
"downloads": [["2012-01-05 00:00:00", 4], ["2012-01-06 00:00:00", 4], ["2012-01-07 00:00:00", 0], ["2012-01-08 00:00:00", 0], ["2012-01-09 00:00:00", 0], ["2012-01-10 00:00:00", 0], ["2012-01-11 00:00:00", 0], ["2012-01-12 00:00:00", 0], ["2012-01-13 00:00:00", 1], ["2012-01-14 00:00:00", 1], ["2012-01-15 00:00:00", 0], ["2012-01-16 00:00:00", 6], ["2012-01-17 00:00:00", 15], ["2012-01-18 00:00:00", 6], ["2012-01-19 00:00:00", 0], ["2012-01-20 00:00:00", 3]],
"messages": ["Download statistics available since 2012-01-05 (when this project was registered)."],
"period": "daily",
"start_date": "2012-01-05 00:00:00",
"total": 40,
"stats_updated": "2012-01-26 09:01:09",
"summaries": {
"os": {
"top": "Windows",
"percent": 72,
"modifier_text": ""
},
"geo": {
"top": "United States",
"percent": 40,
"modifier_text": ""
},
"time": {
"downloads": 40
}
}
}


Detectable by JSON, we recently decided to use GSON to play with the results:


import com.google.gson.Gson;

public class Test {

public static void main(String... args) throws Exception {
String json =
"{\"oses\": [[\"Windows\", 29], [\"Unknown\", 5], [\"Linux\", 4], [\"Macintosh\", 2]], \"end_date\": \"2012-01-20 00:00:00\", \"countries\": [[\"United States\", 16], [\"Italy\", 8], [\"Ghana\", 3], [\"Romania\", 3], [\"United Kingdom\", 3], [\"Germany\", 3], [\"Egypt\", 1], [\"Israel\", 1], [\"France\", 1], [\"Hong Kong\", 1]], \"downloads\": [[\"2012-01-05 00:00:00\", 4], [\"2012-01-06 00:00:00\", 4], [\"2012-01-07 00:00:00\", 0], [\"2012-01-08 00:00:00\", 0], [\"2012-01-09 00:00:00\", 0], [\"2012-01-10 00:00:00\", 0], [\"2012-01-11 00:00:00\", 0], [\"2012-01-12 00:00:00\", 0], [\"2012-01-13 00:00:00\", 1], [\"2012-01-14 00:00:00\", 1], [\"2012-01-15 00:00:00\", 0], [\"2012-01-16 00:00:00\", 6], [\"2012-01-17 00:00:00\", 15], [\"2012-01-18 00:00:00\", 6], [\"2012-01-19 00:00:00\", 0], [\"2012-01-20 00:00:00\", 3]], \"messages\": [\"Download statistics available since 2012-01-05 (when this project was registered).\"], \"period\": \"daily\", \"start_date\": \"2012-01-05 00:00:00\", \"total\": 40, \"stats_updated\": \"2012-01-26 09:01:09\", \"summaries\": {\"os\": {\"top\": \"Windows\", \"percent\": 72, \"modifier_text\": \"\"}, \"geo\": {\"top\": \"United States\", \"percent\": 40, \"modifier_text\": \"\"}, \"time\": {\"downloads\": 40}}}";

// Wow - This was easy!
SourceForgeData01 data = new Gson().fromJson(json, SourceForgeData01.class);

// The data conversion:
System.out.println(data.toTDF());
}
}


Here are the supporting classes:


import com.google.gson.annotations.SerializedName;

/**
*
* @author profnagy
*/
class SourceForgeData01 {

@SerializedName("stats_updated")
public String statsUpdated = "";
@SerializedName("start_date")
public String startDate = "";
@SerializedName("end_date")
public String endDate = "";
@SerializedName("total")
public String totalDownload = "";
@SerializedName("summaries")
public DataDownloadSummary downloadArray = new DataDownloadSummary();

public String toTDF() {
StringBuilder sb = new StringBuilder();
sb.append(this.totalDownload);
sb.append("\t");
sb.append(this.startDate);
sb.append("\t");
sb.append(this.endDate);
sb.append("\t");
sb.append(this.statsUpdated);

sb.append("\t");
sb.append(this.downloadArray.os.top);
sb.append("\t");
sb.append(this.downloadArray.os.percent);
sb.append("%\t");
sb.append(this.downloadArray.geo.top);
sb.append("\t");
sb.append(this.downloadArray.geo.percent);
sb.append("%");
return sb.toString();
}
}


~ then, given the structure of "summaries" ~


/**
*
* @author profnagy
*/
class DataDownloadSummary {
public TopPercent os = new TopPercent();
public TopPercent geo = new TopPercent();
}


~ and finally ~


import com.google.gson.annotations.SerializedName;

/**
*
* @author profnagy
*/
public class TopPercent {
@SerializedName("top")
public String top = "";
@SerializedName("percent")
public int percent = -1;
}


Here is the result:


run:
40 2012-01-05 00:00:00 2012-01-20 00:00:00 2012-01-26 09:01:09 Windows 72% United States 40%
BUILD SUCCESSFUL (total time: 1 second)


While massively easy to parse tagged values & arrays, we have yet to discover a way to parse those untagged / anonymous record arrays (such as "downloads" in the above) without resorting to pre-processing. Never the less, when it comes time to parse classic JSON tagged values, GSON results are proving to be almost worthy of a "+2".

Enjoy,

-Rn



[ add comment ] ( 1921 views )   |  permalink  |  related link

<<First <Back | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Next> Last>>