All Things Techie With Huge, Unstructured, Intuitive Leaps

Java - determine an image or file exists

One of our programmers asked me how to determine if an image or a file exists last week, so I thought that I would post this code snippet for anyone else that needs a reminder.

String thumbnail = <put the name of image or file here>
try{
   File iFile = new File(config.getServletContext().getRealPath("/")
    + "albums/" + thumbnail);  //we keep all of our images in a directory called albums
   
   if (iFile.exists()) {
    String thisImage = "albums/"+ thumbnail;
     }  else {
        String thisImage = "albums/"+ "noImage.jgp";
     }
}
catch (Exception e)
{
  System.out.println("Can't find image.");
}


Hope this helps someone.

Musings on Machine Consciousness or Artificial Consciousness

(click on photograph to enlarge)

I was walking along a country road and I came upon this scene picture above.  The picture really does no justice to the rolling hils, the lines, folds and textures as well as the light and dark areas.  As you eye takes in the panorama in real life, you realize that it is a magical place that makes you feel numinous.

And right in front of me, was a guy with a huge piece of paper, trying to capture the scene with a charcoal sketch in preparation for a painting.  The back of his VW stationwagon was lifted open and sketches were scattered all over the car.  I peeked at his sketches, and we started talking.

As it turned out, he was from Australia,  an ex-computer engineer, a mainframe guy who was now an artist and had been for over 20 years.  He earns his living with his art.

We got to talking about stuff, computers and such, and the magnificent scene in front of us, and the impossibility of reproducing and how it made us both feel numinous and from there we got on to consciousness.

I brought up the topic that Ray Kurzweil had predicted a machine with a soul with his book "The Age of A Spiritual Machine".  My new-friend begged to differ, citing that we really didn't know what consciousness was, so how could we emulate or even create it on doped silicon.

I wanted to beg to differ with the artist.  My own neural nets tell me that consciousness is an over-developed tropism.  Plants started it with phototropism for the leaves and geotropism for the roots, and after several hundred million years of evolution gone wild, the tropisms developed into senses, the brain evolved to process the sensory stimuli and it didn't stop.  We developed the ability to abstract, to think, and to integrate the sensory data to knowledge and preserve and pass it on to our species.

This got me to thinking about how a primitive artificial consciousness would be formulated in a computer.  We already have the prototypes with QoS circuits in servers monitored Quality of Service.  We have a heartbeat, plus all sorts of monitors that read and report on processes, cycles, peripherals, services and such.  Right now, these QoS circuits report to humans.  They would have to report to the machine itself.  And the machine would have to react to them.

How it reacts is the tricky part.  In humans, we react to our sensory input by abstracting it to a higher plane.  If for example, our heart skips a beat, we start worrying about a heart attack.  What it means for machine consciousness, is that the data integration into information and finally stringing information into knowledge has to be developed.  As a further step, knowledge must be abstracted into an ideal that can be applied to many other things.  For example, any child knows the following ideal:

Using this ideal, a child can match the above to this:

And with even a bit of cogitation, a child can match the abstract with this:

So, just to recap to this point, a computer would need sensory inputs from everything about itself, hardware and software, and then it would need some powerful inference tools to sort the Big Data from its sensors into information, and from there in knowledge and from there, into an abstract ideal, or an interface if you will, in programming language.

We haven't touched the world outside the computer yet.  But we are not done.  Once we have the knowledge bits, we need some emotions bits if we are to match the human experience.  I'm not saying that we really need that.  The computer conscious could be a Spock-on-steroids who has no emotions, but that wouldn't be fun, would it?

Emotions need qualitative judgements and reactions to those qualitative judgements.  In a human being, if we are worried, our performance is impaired.  If we were to match this in a machine, worry would spawn threads that would impair performance based on whether the machine was bummed out or not.  But how would a machine express happiness?  Would it be by innocuous things like playing mp3s when it should be doing floating point co-processing?

My Australian friend said that we would never develop Artificial Consciousness.  Moi, I say that what I have brought up are mere details.  There will be frameworks upon frameworks that will give the computer a good idea of what is going on, how the computer should react, and that there is a whole other world outside the binary bits and bytes of the doped Gallium Arsenide matrices and PNP and NPN junctions in its transistor neurons. It's a scary thought when a computer first comes to the realization of an outside world, but damn, it would be exciting.   More to come.

E-ZPASS Malware Spam

The malware and virus injection spammers are getting more creative, and it has got me to wondering that this isn't originating from Russia.  Only Western hackers, and virus scum know about E-ZPass which is the transponder system on interstate highways in North America.  Some of the E-ZPass setups photograph your licence plate and send you a bill in the mail.  These guy want you to download your invoice.  Yeah, right.  Here is the email in its comic entiretyl





E-ZPass Collection Agency <refund@sttheresedombivli.org>

Dear customer,

You have not paid for driving on a toll road. This invoice is sent repeatedly,
please service your debt in the shortest possible time.

The invoice can be downloaded here.




There are a couple of ironic and funny things about this piece of malicious spam.  First, it is sent from a hacked inactive site of a Catholic girls school run by nuns in Dombivli, India.  The school is call St. Therese in Dombivli.  Going to the site lights up all of my antivirus protection and Chrome won't go there as well due the virus-laden site.  But if you look at the footer of the email, they have an entry call Phishing Policy, and that is exactly what they are doing -- phishing for your private information.

You would think that since this is a Window virus, Microsoft would have solved the virus problem long ago, but they don't have the will to, or Windows is such a piece of crap that it cannot be done.

Microsoft Word ~ Capitalizing Each Word

I had a list of things in a Word document and I wanted to capitalize each word.  I didn't know how.  I had to look it up. Here is how you do it.


Make sure that you are in the standard Home tab.   In the Font area of choices, look for the icon markedwith “Aa”.  After making sure that your text is selected, click on this icon & choose "Capitalize Each Word", the last of the selections as shown:


  • Sentence Case
  • Lower Case
  • UPPERCASE
  • Capitalize Each Word


Hope this helps someone.

27 Ways To Make Your Webpages Load Faster



 27 ways to make your webpages load faster


  1. Avoid a character set in the meta tag 
  2. Avoid bad requests
  3. Avoid CSS @import 
  4. Avoid landing page redirects
  5. Combine images using CSS sprites 
  6. Defer parsing of JavaScript 
  7. Enable gzip compression 
  8. Enable Keep-Alive 
  9. Inline small CSS 
  10. Inline small JavaScript 
  11. Leverage browser caching
  12. Minify CSS 
  13. Minify HTML
  14. Minify JavaScript
  15. Minimize redirects 
  16. Minimize request size 
  17. Optimize images
  18. Optimize the order of styles and scripts 
  19. Prefer asynchronous resources
  20. Put CSS in the document head 
  21. Remove query strings from static resources 
  22. Serve resources from a consistent URL 
  23. Serve scaled images 
  24. Specify a cache validator 
  25. Specify a character set early 
  26. Specify a Vary: Accept-Encoding header
  27. Specify image dimensions 
Hope this helps.

The "I Quit" Spam Insult Spam

I tell you, the spammers and malware guys are getting more and more entertaining.  I recently got a piece of spam that had the subject:

Subject:  Can you handle $365 every 100 minutes?

When I looked at the body of the message, it said this:


Hey,


I'm done taking crap from you. I've worked myself to the bone for 8 years now and you don't appreciate a thing I do for you.
You're arrogant, egotistical and you have no loyalty whatsoever. Every time I EVER did anything right, you always took credit for it…and I let you…because I was scared of losing my job.
A true leader takes the blame when things go wrong, and praises the people who did the job when things go right…YOU do it the opposite.

I found someone who takes me seriously:
http://somegoodservice.com/c.php?k=1 blah blah lots of parameters

I don't need you anymore.

Ciao.

See you tonight.
Timothy.


Admin
1342 ar allen RD
Beaverton, OR 97008,
Canada, 23r4rd street

It's hilarious.  The URL domain for the link is somegoodservice.com.  I didn't bother checking it out, because of lot of sites that inject malware or viruses are legitimate sites.  They have been hacked with a weak password and the hackers add a new page that injects malware or viruses.  The new page is not seen unless you log in as admin and do a directory listing of all of the directories and look for a file that doesn't belong.

Note the address.  They can't decide where they are in Canada or the US with fake street names that don't even make sense.

I hope that nobody falls for this, but I bet that a fair amount are tempted just by sheer curiosity.


The Twegomaniac ~ The Twitter Follower/Unfollower Egomaniacs


My goodness, call me James Audubon and fly me to the moon.  I have discovered a new species of bird ~ the Twegomaniac.  This was a rare big that is becoming quite common.

The bird is part of fauna that exists in the Twitterverse.  There cry is "Follow Me, Follow Me" and to get you to do that, they follow you first.  But they are like the cuckoo bird who fools its host.  Once you abide by the Twitter netiquette and follow them, they unfollow you.  It's all about them.  They are the birdbrain egomaniacs who thinks that size matters.  They were born with a small size, and to try and enlarge it, instead of having the personality and content to get followers (like Jesus, Ghandi or Clint Eastwood's Empty Chair), they have to resort to trickery.  They just don't have the right stuff.

So how do you know if you have come across a Twegomaniac in your follow list?  The biggest clue is that you have never heard of them, and they have 100,000 follows and 200,000 followers.  The other identifying feature is a big asshole.

So how do you protect yourself from these odious creatures and droppings that they leave all over your home page before they leave.  There are a plethora of tools out there to help detect unfollowers.  I have been known to use the free aspect of manageflitter.com as a pest control method.  There are many more.  Beware of the Twegomaniac.

MySQL - Getting a List of Users by who logged in last

I have a list of users.  I collect their activity. I want to get a list of users, but I want to order it by who logged in last.  Some users haven't logged in in months and don't appear in the login table.  There are two tables.  One is a users table and the other is a loginTable.  The login time is recorded by a timestamp.  Here is one way of getting the list and ordering by the last login.


SELECT users.id, MAX(loginTable.timeIn), loginTable.userId  FROM  loginTable
right join users on loginTable.userId = users.id
ORDER BY MAX(loginTable.timeIn) DESC ;

The right join insures that we get all of the users, even those who don't appear in the loginTable.  This is a slow query for a large user table, but since we are collecting metrics it doesn't matter.

Hopes this help someone.

Smart Road JSON or XML Template For Messaging and Data Transmission and Receiving



With the Internet of Everything here among us, and GPS is ubiquitous in vehicles, and cars will have full internet capability, it will not be long before we have Smart Roads.  Each road will have an IP address.

I began wondering what the data package would look like for Smart Roads, and then I was struck with the axiom that the best way to predict the future is to invent it.

So without further ado, I cracked together and XML file of what the Smart Road dataset would look like.  Here is my first crack at creating a Smart Road Data Standard:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Smart Road Markup Language version 1.0-->

<smart_road>  
<!-- Main Element.  It consists of a header, data and trailer elements. -->


    <header>
      <!-- Header Element.  -->

      <ref_number></ref_number> <!-- This could be a database Primary Key Identifier.  -->
      <country></country>
      <state></state>
      <province></province>
      <county></county>
      <township></township>
      <ip6_address></ip6_address> <!-- Each Smart Road will have their own IP address.  -->
      <start_gps></start_gps>
      <classification></classification> <!-- There could be subclassifications like carriageways etc.  -->
      <end_gps></end_gps>
      <length_kms></length_kms>
      <maximum_speed_limit></maximum_speed_limit>
      <options></options> <!-- This could be a control element for suppressing some header info on subsequent exchanges.  -->

     </header>

  <data> <!-- Message Section.  -->
  <data_sent>
     <general_data> <!-- This section contains general data sent to the vehicles  -->
            <alerts>
                   <current_alerts></current_alerts>
                   <upcoming_alerts></upcoming_alerts>
             </alerts>
            <flags></flags>
           <messages>
              <alerts></alerts>
              <construction></construction>
              <law_enforcement></law_enforcement>
              <traffic></traffic>
              <weather></weather>
             <misc></misc>
            <user_specific>
                 <destination_address></destination_address>
                 <ack_flag> </ack_flag>
                <message_payload></message_payload>
                <delivery_receipt></delivery_receipt>
            </user_specific>
         </messages>
    </general_data> 
      <location_specific_data><!-- This section contains location-specific sent to the vehicles  -->
          <current_gps_marker>
               <current_maximum_allowable_speed></current_maximum_allowable_speed>
                <alerts>
                      <current_alerts></current_alerts>
                      <upcoming_alerts></upcoming_alerts>
                </alerts>
                <flags></flags>
               <messages>
               <alerts></alerts>
               <construction></construction>
               <law_enforcement></law_enforcement>
               <traffic></traffic>
               <weather></weather>
              <misc></misc>
               <user_specific><!-- It is anticipated that if a vehicle's onboard messaging is not working, one can billboard messages -->
               <!-- This can also be used to send violation notices and service-related messages to the vehicle -->
                     <destination_address></destination_address>
                     <ack_flag> </ack_flag>
                    <message_payload></message_payload>
                    <delivery_receipt></delivery_receipt>
               </user_specific>
              </messages>
       </current_gps_marker>
      </location_specific_data>
   </data_sent>
   <data_received>
        <vehicle>
           <type></type>
           <description></description>
           <direction></direction>
           <velocity></velocity>
           <timestamp></timestamp>
        </vehicle>
   </data_received>
  </data>

  <meta-data>
  <!-- Big Data meta data on usage stats etc.-->
  </meta-data>
  <trailer>
    <protocols_supported> </protocols_supported><!-- Various devices will have their own native Smart Road protocols -->
    <device_types></device_types>
    <end></end>
    
  </trailer>
</smart_road>

This is just a first iteration.  It needs to be tested and validated in real time.  It is anticipated that the vehicle will send its GPS coordinates to the database defined by the IP address, and the location specific data will be returned.

Java - How to calculate and find out how many seconds to an event in the future

Java lesson.  Let's suppose that you have an event happening in the future.  The date and time of that event is stored in a database and you want to calculate how many seconds there are to that event. Once you get seconds, you can divide by 60 to get minutes, and again by 60 to get hours and then by 24 to get days etc.

Here is a code snippet that lets you do that:

Date now = new Date();
Timestamp eventStart = rs.getTimestamp("eventStart");
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(eventStart);
Date endInterval = gc.getTime();
long difference = Math.abs(endInterval.getTime() - now.getTime());
long secondsToEvent = difference / (1000);

Date is java.util.Date. Timestamp is java.sql.Timestamp.

Hope this helps someone.

How to find and show line numbers in Wordpad



I had an exception, an error that was being thrown from a compiled .jsp file.  Strangely, the console would not give me the line number of the uncompiled jsp, but rather it gave me the line that was causing the exception in the compiled jsp file that was in the work directory.

I didn't feel like opening the file in text editor in Eclipse to locate the line, so I opened the jsp_java file with Wordpad.  The trouble is that Wordpad doesn't show line numbers.  I found the line numbers in Wordpad with this hack:

1) Select the entire text with Select All (CRTL +A will do it).

2) Expand the bullets menu item and click on the numbered list eg 1. 2. 3. etc

3) Every single new line will now be numbered and you scroll down to the offending line.

Hope this helps someone.

Code Snippet for Creating Secure Token in Java



Tokens can be used for many things.  Among them are Single Sign On, or saving an identification number without exposing it to the web.  Here is a quick code snippet to create a 16 character token

First you need an import:

import java.security.SecureRandom;

here is the code snippet:

String token1 = null;
SecureRandom secureRandom = new SecureRandom();
String secString = new BigInteger(130, secureRandom).toString(32);
token1 = secString.substring(0, 15);  //creates a 16 character token

Alter the substring end value to change the size of the token.

Hope this helps someone.

Amazon Mobile Ads API


Amazon

Dear Developer,
We are very excited to announce that the Amazon Mobile Ads API is now
available for iOS apps. Now you can monetize apps across platforms,
including Android, iOS and Kindle Fire tablets and Fire phones.

With the Amazon Mobile Ads API, you have the opportunity to earn
more and you are paid on ad impressions served instead of clicks on
 ads. The Amazon Mobile Ads API is easy to integrate and delivers
highly-relevant banners, rich media and higher paying interstitials
from Amazon and brand advertisers ensuring great experience for
 your users.

With this release, we are also expanding ad serving to users in Italy
and Spain across both Android and iOS. Starting today, the Amazon
Mobile Ad Network is serving ads to Android and iOS users in the US,
 the UK, Germany, France, Spain and Italy.

Developers currently using the Amazon Mobile Ads API in their iOS
 apps share their experience*:

“Amazon Mobile Ads API is consistently delivering 20% higher eCPM
 on both Android and iOS platforms compared to other ad networks.
In addition to increased earnings, the high-quality tailored ads provides
 an engaging experience for our users achieving 25% higher CTR”
                               - Tim Oswald, Co-Founder & CEO of Harpan LLC.

“Amazon Mobile Ad Network is a top ad network for our iOS and Android
apps. Our eCPM with Amazon Mobile Ad Network are higher across the board.”
                              - Todd Moore, Founder & CEO of TMSOFT LLC.
* Your results may vary.

For a limited time, when you send the first ad request from a qualified app,
 you will receive a guaranteed $6 CPM on interstitial ads (up to a maximum
of 1 million impressions per app per month). Qualifying apps now include
 iOS apps. Please find more details here.
    To get started with the Amazon Mobile Ads API check out our Developer
    Portal here as well as our blog with tips on ad mediation and tracking ad 
    events inside your apps.

    Best Regards,
    Your Amazon Mobile Ad Network team

    Diffusion Without Photoshop Filters

    (click on picture for panorama view)

    I photographed this bucolic scene in the country, and I knew that because of the dramatic clouds and fields that I was going to make it look like a painting.  My normal way of doing this, as an uber geek, is to feed it into Photoshop, and use an array of software filters.

    However, it was raining that day, and I had my camera in a ziplock bag.  I decided to shoot through the ziplock bag for a diffusion screen.  It turned out fantastic.  The result is above.  It is a great way to get diffusion without Photoshop software image manipulation filters.

    A Java class to escape illegal characters



    Here is a Java Class to escape illegal characters with a static method:



    package com.mypackage;

    import java.util.HashMap;
    import java.util.regex.Pattern;

    /**
     * The Class StringHelper.
     */
    public class StringHelper {

      /**
    * Escapes characters that have special meaning to regular expressions.
    * 
    * @param s
    *            String to be escaped
    * @return escaped String
    */
      public static String fixString(String s){


        int length = s.length();
        int newLength = length;
        // first check for characters that might
        // be dangerous and calculate a length
        // of the string that has escapes.
        for (int i=0; i<length; i++){
          char c = s.charAt(i);
          if (!((c>='0' && c<='9') || (c>='A' && c<='Z') || (c>='a' && c<='z'))){
            newLength += 1;
          }
        }
        if (length == newLength){
          // nothing to escape in the string
          return s;
        }
        StringBuffer sb = new StringBuffer(newLength);
        for (int i=0; i<length; i++){
          char c = s.charAt(i);
          if (!((c>='0' && c<='9') || (c>='A' && c<='Z') || (c>='a' && c<='z'))){
            sb.append('\\');
          }
          sb.append(c);
        }
        return sb.toString();
      }
    }

    Hope this helps someone.