Archive

Archive for July, 2008

FLEX 3 Catch Browser Exit or Close Event using Javascript and ExternalInterface

July 30th, 2008

Well after doing a bunch of searching and hacking away, I have managed to come up with a solution!

What I wanted was to set a variable when a change was made in my Flex application. (In my case it meant that a new module was loaded to my dashboard application) This way if a user loaded or deleted a module, the app would save their environment to a Shared Object.
Originally I had it was saving automatically, but user feedback said, only if I want to. This led me to prompting them when the close, but only if something has changed.

Here is how I did it:

First I declare a Bindable variable up at the top of my code (oh also import ExternalInterface)

import flash.external.ExternalInterface;
[Bindable] private var saveRequired:Boolean;

Second in my creationcomplete Event called init(), I add a callback to the ExternalInterface like so:

 private function init():void
		 {
          		if ( ExternalInterface.available ) {       			

          			ExternalInterface.addCallback("checkForUnsavedData",function():String {
          				if (saveRequired ) {
          					unsavedAlert();
          					return UNSAVED_DATA_WARNING;
          				}
						else return "";
					});
          		}
		 }

The following 2 functions are added to handle the Alert when the Javascript kicks off

private function unsavedAlert():void {
           Alert.show("Save?", "Save Alert", Alert.YES|Alert.NO ,this,SaveAlertHandler,null,Alert.YES);
          }

		private function SaveAlertHandler(e:CloseEvent):void {
		  	    if (e.detail == Alert.YES) {
		  	   		 setLSO();
		  	    }
		  	    saveRequired = new Boolean;
		  }

When you determine that a save is required set the variable saveRequired to anything. I wanted it to be a reminder when I went back to debug, so mine look like this…

saveRequired = "Popup on Browser Exit";

Finally….add this code between in your ./html-template/index.template.html

 <script language="JavaScript" type="text/javascript">
<!--
//alert(navigator.appName);
// Give user a chance to save modified data
window.onbeforeunload = function () {

	var warning = getFlexApp('SharedObjectBoard').checkForUnsavedData();
	if (warning != "")
		return warning;
	else
	return;
}

function getFlexApp(appName) {
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[appName];
	alert(appName);
  }
  else {
    return document[appName];
	}
}
 -->
</script>

Greg FLEX

Archiving Perl PHP RUBY Scripts to Evernote using File Auto Import and Some Perl Scripting

July 25th, 2008
Archiving Perl PHP RUBY Scripts to Evernote using File Auto Import and Some Perl Scripting
Today Evernote released a new version which added the ability to drag and drop pictures or text files directly to evernote.
For a while I’ve been thinking about putting all my perl scripts in evernote, but was not in the mood to
1) Open each file
2) Copy the text
3) Paste It to Evernote
Thats also repetiteve and I don’t do Repetitive without Perl!
Evernote Offers a nice little feature File Auto Import which can be found in the menus under
Account > Properties.
The problem is, It will not import .pl file or .cgi or .php for that matter. Only .txt and images, and maybe a few others but
definitely not .pl
So, I wrote a perl script that goes through my perl script parent directory.
NOTE:(I store all my scripts for the most part in one dir, and create sub directories under it. So It was quite easy for me.)
And then makes a copy of the file in the Evernote AutoImport directory with a nice Title and the .txt extension.
##This is the path to your Evernote Import Directory
$outdir = "C:\\temp\\EvernoteScripts";
# look in current directory
$dir = `pwd`;
chop($dir);
my @files = `find | grep ".pl" | grep -v ".swp" | grep -v ".doc"`;
 
 
foreach my $f (@files) {
	chop($f);
	$filenameOnly = `basename $f`;
	$directoryOnly = `dirname $f`;
	$newfile = substr($filenameOnly,0,index($filenameOnly,"."));
	print "$filenameOnly\n";
	$text = "\# Script : $filenameOnly\n"; ### Creates a title for the script which will be seen in Evernote!
	$text = $text . `cat $f`;
	$nf = "$outdir\\$newfile\.txt";
 
	open FILE, ">", $nf or die $!;
	print FILE "$text";	
	close FILE;
	sleep 2; ###Evernote basically exploded when it tried to read from the directory without a slight delay.	
}

Greg Perl

Jury Duty Phone Scam

July 23rd, 2008

All, I just recieved an email which circulated from a senior VP at my company. Here is the exact email.

DO NOT DELETE WITHOUT READING!

Jury Duty Scam

This has been verified by the FBI (their link is also included below). Please pass this on to everyone in your email address book. It is spreading fast so be prepared should you get this call. Most of us take those summonses for jury duty seriously, but enough people skip out on their civic duty, that a new and ominous kind of fraud has surfaced.

The caller claims to be a jury coordinator. If you protest that you never received a summons for jury duty, the scammer asks you for your Social Security number and date of birth so he or she can verify the information and cancel the arrest warrant. Give out any of this information and bingo; your identity was just stolen.

The fraud has been reported so far in 11 states, including Oklahoma, Illinois, and C olorado. This (swindle) is particularly insidious because they use intimidation over the phone to try to bully people into giving information by pretending they are with the court system. The FBI and the federal court system have issued nationwide alerts on their web sites, warning consumers about the fraud.

Check it out here: <http://www.fbi.gov/page2/june06/jury_scams060206.htm>

And here:  <http://www.snopes.com/crime/fraud/juryduty.asp><http://www.snopes.com/crime/fraud/juryduty.asp>

 

Greg Uncategorized

Smoked Pepper Halibut

July 19th, 2008

 

Smoked Pepper Halibut

Smoked Pepper Halibut
Rated  by 3 people
Rate This   
100s of main-dish recipes plus suggestions for simple go-with dishes to make a meal complete.
 
4 servings
Prep: 15 minutes
Marinate: 30 minutes
Grill: 8 minutes
 

Ingredients

Directions

Thaw fish, if frozen. Rinse fish; pat dry with paper towels. If necessary, cut fish into 4 serving-size pieces. For marinade, in a blender container combine chipotle peppers, adobo sauce, sweet pepper, lime juice, oregano, and garlic. Cover and blend until pureed. Transfer half of the marinade to a shallow dish; set aside remaining marinade.

Add fish steaks to dish, spooning some of the marinade over fish. Cover and marinate at room temperature for 30 minutes.

Drain fish, discarding marinade. Sprinkle fish with salt. Grill fish on the greased rack of an uncovered grill directly over medium coals for 8 to 12 minutes or until fish flakes easily when tested with a fork, turning once halfway through grilling. Heat reserved marinade and serve as sauce with fish. Makes 4 servings.

 

Greg Uncategorized

How Do I import and iCal .ics file into Outlook

July 18th, 2008
In outlook….Go To
File > Import and Export
 
 
Choose Import and iCalendar or vCalendar file (.vcs)
 
 
 
Now Browse to your .ics file and Click OK!
 

Greg How-To

How Do I Import a CSV File into Outlook Caledar

July 17th, 2008

 

Import CSV Caledar into Outlook
 
For this example I am using Outook 2003. You can get your version by going to the outlook menu
Help > About
 
However it should not matter.
 
 
Go to File > Import and Export
 
 
You will get a menu that looks like this. Choose “Import from another program or file”
 
 
choose Comma Seperated Value (Windows)
 
 
 
Now Browse to your download schedule and Click Next!
 
 
 
Choose Calendar
 
 
Click Finish!
 

Greg How-To

Test of SyntaxHylighter

July 17th, 2008
#!c:\\perl\\bin
#use strict;
use WWW::Mechanize;
use HTTP::Cookies;
use HTML::TableExtract;
use Net::Whois::IP qw(whoisip_query);
use chilkat;
our $count = 0;
my %Whitelist =
(
'67.228.182.163' =&amp;amp;amp;amp;gt; 'Xoopit',
'ip.ip.ip.ip' =&amp;amp;amp;amp;gt; 'Work'
&amp;amp;lt;code&amp;amp;gt;);

Greg Uncategorized

Monitor GMAIL Account Activity Using Perl

July 9th, 2008
As recently noted over at my favorite website lifehacker.com…Google has recently added a nice feature to GMAIL that allows you to see your account activity.
If you scroll to the bottom of you Inbox, you will see something that looks like this.
This really got me thinking. This is a great feature, however its lacking in a few areas.

1) I’d like to know when suspicious activity is occuring. Although the likelyhood is low (that someone is trying to hack in…at least I  think), I’d still like to have alerts that tell me there is an issue.

2)  I’d also like tracking details in case there is an issue, I can try to figure out who it is,and where they are coming from.  Actually, when I first looked at this, I noticed someone or somethign was hitting me from 67.228.182.163. Using my technical efficentcies…I was able to track it back to Xoopit. Another service I found over at lifehacker.com.

The process was basically taking the IP in the activity window and doing a whois lookup. The problem is that the whois, generally returns the ISP. However, luckily there was an RWHOIS available. That pointed me to Xoopit!
Well, from here I decided to write a script that will run every 30 mins, Alert me if something looks suspicious.

It does the following.
1) Logs into Gmail.
2) Pulls up Account Activity Page
3) Parses Page.
4) If IP is not in the whitelist…
a. does a Whois Loopup on the IP
b. generates

5) If the count of suspicious IP’s is > 0. Sends and email using Gmail as SMTP server to whomever cares to know.
HERE IS THE CODE:
Use it as you wish. If you have issues or like it, please leave comments.
#!c:\\perl\\bin
#use strict;
use WWW::Mechanize;
use HTTP::Cookies;
use HTML::TableExtract;
use Net::Whois::IP qw(whoisip_query);
use chilkat;
our $count = 0;
my %Whitelist = 
		( 	
			'67.228.182.163' => 'Xoopit',			
			'ip.ip.ip.ip' => 'Work'			
		);
 
my $capture = GetGoogleActivity();	
my $HTML = ParseActivity($capture);
 
print "Count = $count\n";
if ($count > 0) {
	DoEmail("GMAIL: Possible Suspicious Activity", $HTML);
}
 
 
 
sub GetGoogleActivity {
###go to login page and login.
	my $url = "https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=1k96igf4806cy&ltmpl=default&ltmplcache=2&hl=en";
	my $username = "someone@gmail.com";
	my $password = "password";
	my $mech = WWW::Mechanize->new();
	$mech->cookie_jar(HTTP::Cookies->new());
	$mech->get($url);
	$mech->form_number(1);
	$mech->field(Email => $username);
	$mech->field(Passwd => $password);
	$mech->click();
	#Go to the next link, now that we are logged in.
	$url = 'https://mail.google.com/mail/?ui=2&ik=46e3aa5be5&view=ac';
	$mech->get($url);
	my $output_page = $mech->content();
	return $output_page;
}
 
sub ParseActivity {
my ($capture) = @_;
 
$te = HTML::TableExtract->new( depth => 3, count => 1);
$te->parse($capture);
$table = $te->first_table_found;
foreach $ts ($te->tables) {
     foreach $row ($ts->rows) {
		#for my $r (@$row) {
			$type = @$row->[0];
			$ip = @$row->[1];
			$when = @$row->[2];
			$type = RemoveWhiteSpace($type);
			chop($ip);
			$ip = RemoveWhiteSpace($ip);
 
			$when = RemoveWhiteSpace($when);	
			print "Whitelisted IP [$ip] = $Whitelist{$ip}\n";
			if ($ip !=~ "?") { 
					if (! $Whitelist{$ip}) {
						#if (($ip !=~ "?") && (! $Whitelist{$ip})) {
						$HTML = $HTML . "<table broder=\"1\">\n<th colspan=\"3\" align=\"left\">Connection From $ip</th>\n<tr>\n<td>$type</td><td>$when</td><td>$ip</td>\n</tr>\n";
						#print "$type\t$when\t$ip\n\n";
						$HTML = Whois($ip,$HTML);
						$HTML = $HTML . "</table>\n";
					}
			}		
				#}
 
 
			#$html = "$html" . "$town \t $d<br>\n";
			#$count++;
		}
	}
	return $HTML;	
}
 
sub Whois {
	$count++;
	my ($IP,$html) = @_;	
	print "Looking up $IP\n";
	my $response = whoisip_query($IP); 
	foreach (sort keys(%{$response}) ) { 
		$html = $html . "<tr><td colspan=\"2\">$_</td><td>$response->{$_}</td></tr>\n";		 
	}
	return $html;
}
 
sub RemoveWhiteSpace {
	my ($val) = @_;
	for ($val) {
		s/\*//; #Also removes *
		s/^\s+//;
		s/\s+$//;		
	}
return $val;
}
 
sub DoEmail {
my ($title,$description) = @_;
# file: GMail.pl
print "$title\n $description\n";
# Perl script to send email using GMail as the SMTP server.	
 
 
$mailman = new chilkat::CkMailMan();
$mailman->UnlockComponent('anything for 30-day trial');
 
# Set your SMTP server's hostname
$mailman->put_SmtpHost('smtp.gmail.com');
 
# GMail requires a login/password to send mail.
# Strings containing a '@' should always be in single quotes.
$mailman->put_SmtpUsername('someone@gmail.com');
$mailman->put_SmtpPassword("password");
 
# The default SMTP port is 25.  When using it, GMail requires STARTTLS.
$mailman->put_StartTLS(true);
 
# Alternatively, you may comment-out the STARTTLS line and instead use SSL
# on port 465 by commenting-in these 2 lines:
# $mailman->put_SmtpPort(465);
# $mailman->put_SmtpSsl(true);
 
# If you are connected to a network that blocks outbound port 25 connections,
# use GMail's alternative port 587.  You'll need STARTTLS, so uncomment the 
# STARTTLS line and make sure the two lines for SMTP SSL are commented out.
$mailman->put_SmtpPort(587);
 
$mht = new chilkat::CkMht();
$mht->UnlockComponent('anything for 30-day trial');
 
open(INFO, ">GmailActivity.html");
$body = "<html>
<head>
<html>$description
</html>";
print INFO "$body";
close INFO;
 
# Instantiate a new email object.
$email = new chilkat::CkEmail();
$email = $mht->GetEmail('GmailActivity.html');
$email->put_Subject($title);
#$email->put_Body($body);
$email->put_From('Greg The Great! <someone@gmail.com>');
 
# Add some recipients
$email->AddTo('Email','someone@gmail.com');
 
 
 
$success = $mailman->SendEmail($email);
if (! $success)
    {
	$mailman->SaveLastError('lastError.txt');	
    }
else 
{
	# The log will contain information allowing you to verify
	# what actually happened.
	# If you see an error "Error authenticating server credentials!" this is 
	# normal and OK.
	$mailman->SaveLastError('lastInfo.txt');	
}
 
}

Greg Perl

Import Subscriptions into Google Reader

July 3rd, 2008

 1) Go to http://www.google.com/reader (you must have a google  account)

 
2) Click Manage Subscriptions in the feeds pane as seen above.
 
3) Click the Import/Export Tab
4) Browse to the file you want to import
5) and then click Upoad
 

Greg How-To

Using Evernote and BlogJet Simplify my Wordpress Blogging!

July 2nd, 2008

Although I have been in the technology field for ~10 years, I am rather new to blogging, and am quite frustrated with how difficult is seems to be to post an entry which has a bunch of images in it. This is especially true when you are writing up a how to with screen shots and the like. I don’t want to FTP all the images up and then hard code references to them in my blog entry. That is painful, and we’ve come to far to be doing anything manually.

So what I do is the following, and uses a combination of BlogJet and Evernote.

Both have greate features, but like anything else in this world, unless google wrote it, you need 2 tools to do the job of one….so that’s what I do. Using this method streamlines image uploads in your blog and make the task of blogging absolutly painless…

*I invite you to please comment and let myself and others know a better way or the way you do handle your blogging.

HERE GOES….

The Net-Net of what happens is this:
1) Create Note In Evernote.
2) Export to HTML
3) Select all HTML page
4) Paste into BlogJog (images and text come too)
5) Publish Blog Entry using BlogJog.
 

First you must create the Note in Evernote. One of the many, many, many beauties of Evernote, is it allows to copy images, directly from the clipboard. So that when I am writing a tutorial, I can just paste everything directly into Evernote. Once your note is created….

Here are step by step instructions.

In the Evernote menu.
Note > Export
 
 
2 ) Choose your save location
 
 
3) Browse to your Save location
 
 
4) Open the Blog entry in your favorite Browser (Firefox of course)
 
 
5) CTRL-A or Edit > Select ALL (in firefox browser window)
 
 
6) Drag and Drop in BlogJet (image below in a past post pasted to BlogJet)
 
 
7) PUBLISH IT!!!!

Greg Cool Stuff, How-To