Google Custom Search – Restricted to specific directory, and filetype…

Categories CSE, Custom Search Engine, Google, Information Technology, JavaScript

So I’ve been having trouble getting a new Google Custom Search to look only in a specific directory on my web server, as well as to only look at specific file types.   It seemed like this should have been SO easy…  But, it took me a bit to figure it out.  So here’s the information just in case anyone else needs it.

  1. Set up a new search engine, in Google Custom Search.
  2. Make sure that you have the root directory in the “Sites” section.  I used “www.mydomain.com”.
  3. You can enter refinements, but they only seem to work if the user clicks on them; not what I wanted.
  4. Go down to “Get Code” and grab the code block that is created for you.  For me it was this:
    • [code]<div id="cse" style="width: 100%;">Loading</div>
      <script src="http://www.google.com/jsapi" type="text/javascript"></script>
      <script type="text/javascript">
      google.load(‘search’, ‘1’, {language : ‘en’, style : google.loader.themes.MINIMALIST});
      google.setOnLoadCallback(function() {
      var customSearchOptions = {};
      var customSearchControl = new google.search.CustomSearchControl(
      ‘Custom Search ID’, customSearchOptions);
      customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
      customSearchControl.draw(‘cse’);
      }, true);
      </script>[/code]
  5. This will give you the basic search.  In order to add in the site restriction and the filetype restriction I changed it to:
    • [code]<div id="cse" style="width: 100%;">Loading</div>
      <script src="http://www.google.com/jsapi" type="text/javascript"></script>
      <script type="text/javascript">
      google.load(‘search’, ‘1’, {language : ‘en’, style : google.loader.themes.MINIMALIST});
      google.setOnLoadCallback(function(){
      var customSearchOptions ={};
      /* Add Custom Search Option to restrict directory */
      customSearchOptions [google.search.Search.RESTRICT_EXTENDED_ARGS]={"as_sitesearch": "www.myDomain.com/subDirectory1/subDirectory2/"};
      var customSearchControl = new google.search.CustomSearchControl("Custom Search ID", customSearchOptions );
      customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
      customSearchControl.draw(‘cse’);
      /* Add query addition to restrict filetype */
      customSearchControl.setSearchStartingCallback(
      this,
      function(control, searcher, query) {
      searcher.setQueryAddition("filetype:pdf OR filetype:PDF");
      }
      );
      }, true);
      </script>[/code]

    I hope that helps out anyone else who might be looking for a similar problem…

Move a file to a shared drive in Java

Categories Information Technology, Programming

I had a bit of trouble with this, in a program I’m writing at the moment. Every time I tried to move a file to a shared folder, on my computer, it would fail. Turns out, it (apparently) because Java doesn’t necessarily share my mapped drives. Here’s the code that I used to overcome this:


System.out.println("Try to move file");

try{
// create a net use command to map the drive...
String command = "c:\\windows\\system32\\net.exe use Z: \\\\172.16.1.74\\f$";
Process p = Runtime.getRuntime().exec(command);

// create an instance of the file to move
File f=new File(".\\myImage.jpg");

// make sure that the file actually exists
boolean fileExists=f.exists();
if(fileExists){
System.out.println("File Found");
}else{
System.out.println("File Not Found");
}

//create a random number and timestamp, for a unique file name
Random rand = new Random();
int randNum = rand.nextInt();
Date date=new Date();

// Create the new filename
String newFileName=new String("myImage_"+date.getTime()+"_"+randNum+".jpg");

//try to move the file
boolean moved=f.renameTo(new File("Z:\\Home\\ITS\\sigImages\\"+newFileName));
if(moved){
System.out.println("File moved -&gt; "+newFileName);
}else{
System.out.println("File Not moved");
}
}catch(Exception ex){
ex.printStackTrace();
};


I’m sure there is a more elegant way of doing this, that more experienced Java programmers will know. But, I could not find too much out there on the web… Hope this helps someone…

–Charles…

Search for non-duplicates bettween two tables.

Categories Information Technology, MySQL, PHP, Programming, Web Development

I recently had some issues trying to make sure that two columns from two different tables were the same.  After some random code writing, I came up with the following MySQL code…  Hope it helps others…

[code]
/* return from first table */
$checkTable1=@mysql_query("SELECT table1.column1 FROM table1 LEFT JOIN table2 ON table2.column2 = table1.coumn1 WHERE table2.column2 IS NULL");

/* return from second table */
$checkTable1=@mysql_query("SELECT table2.column2FROM table2 LEFT JOIN table1 ON table1.column1 = table2.column2 WHERE table1.column1 IS NULL");
[/code]

I’m sure there is a better way to accomplish it, but this worked for my needs…  Just a quick search, and then I added some extra code to update the tables if there are any discrepancies.

–Charles…

The IT Project-Tracking Database: Keep Your Key People in the Loop

Categories Information Technology, Information Technology Links, Web Development

via E-Commerce Times

A project-tracking database should not just be a nominal entity that exists for the sake of existence; rather, it should contain some key attributes that every person in the company can draw important conclusions from — and use them to form the basis of key decisions that impact not just the project itself, but also the overall vision and direction of the company.

Information Technology is a project-centric industry. Every task is either performed as a part of a project or constitutes rollup toward creating a new project. No individual, organization, department or company can escape the rigor of discipline and perseverance that project management enforces as prerequisites for success. However, information Technology often receives a bad rap for the relatively small number of successful initiatives as a percent of the total initiatives launched, compared with other departments.

Technologists are viewed as inherently more disciplined — and more capable of thinking and planning in a structured manner — than their “non-technical” counterparts. I believe this classification is unjust. No matter how trained the human mind, it still cannot replace the uber-productivity tools that assist project discipline today. Initiatives fail mid-stream or fail to take off not because they are not good initiatives, but because of the improper amalgamation of the prowess of the human mind with the appropriate technology (read tools) that it has created for its assistance….

Turn off the creation/use of thumbs.db files in windows 7

Categories Information Technology, Microsoft, Windows 7

Click start;

Type gpedit.msc in the search box or typr run and then type gpedit.msc in the run box.

Navigate to

  • User Configuration
  • Administrative Templates
  • Windows Components
  • Windows Explorer

Enable the following items:

  • Turn off the caching of thumbnails in hidden thumbs.db files.
  • Turn off caching of thumbnail pictures.

Reset computer if needed.

Hope that helps anyone else who has this ridiculous issue…