A very minimal but complete example of using D3-Tip with D3.js

There are a number of ways to get rollover tool tips working with your data visualizations in d3. The simplest I’ve found is a script from Justin Palmer.

[gist https://gist.github.com/nyquist212/10479200 /]
Advertisements

Example to connect to a SQLite database using R Project for Statistical Computing

Getting source data into your R environment is the first step in data or statistical analysis, whether this be in R or R-Studio. Often this data resides in relational data stores. For those new to R, this is how to access the SQLite database from R.

Edit highlighted lines as appropriate.

# Load the SQLite library
  library("RSQLite");
  
# Assign the sqlite datbase and full path to a variable
  dbfile = "/Library/WebServer/Documents/Dash2.5/data/livedb.sqlite";
  
# Instantiate the dbDriver to a convenient object
  sqlite = dbDriver("SQLite");
  
# Assign the connection string to a connection object
  mydb = dbConnect(sqlite, dbfile);
  
# Request a list of tables using the connection object
  dbListTables(mydb);
  
# Assign the results of a SQL query to an object
  results = dbSendQuery(mydb, "SELECT * FROM DailyCensus");
  
# Return results from a custom object to a data.frame
  data = fetch(results);
  
# Print data frame to console
  data;
  
# Clear the results and close the connection
  dbClearResult(results);

PowerShell WebClient example to download a password secured file and email the completion status.

I seem to have got a lot of comments and questions on this from an earlier post so I promised to update this to include email status alerts. This is mainly for those enterprise folks that that haven’t yet move to PS v3 (though this works too on v3).

Automating a status email can be done with a simple function which takes two parameters as text strings.

  1. A subject line
  2. A body or detail message
## Define a simple function to send email alerts ##
function sendEmail ($subject, $detail) {
    $mail = New-Object System.Net.Mail.MailMessage
    $mail.From = "sender@yourdomain.com";
    $mail.To.Add("recipient@theirdomain.org");
    $mail.Subject = $subject;
    $mail.Body = $detail;
    $smtp = New-Object System.Net.Mail.SmtpClient -ArgumentList "your.smtpserver.com";
    $smtp.Credentials = New-Object System.Net.NetworkCredential("yourdomain\yourusername", "yourpassword");
    $smtp.UseDefaultCredentials = $true
    $smtp.Send($mail);
}

Next, the PowerShell code to perform the web download. I’m using a “Try, Catch”
block so we can get any error message into the body of an email to report failure status.


$date = Get-Date -format yyMMdd;
$mypath = "C:\tmp";

Try{
    ## Define the target URL ##
	$url = "http://colinwhite.net/foo.csv";

    ## Instantiate a WebClient Object from the .Net classes ##
	$request = New-Object System.Net.Webclient

    ## credentials for the proxy
    $request.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials

    ## Define the website login password ##
	$passwd	= ConvertTo-SecureString "YourPassword" -AsPlainText -Force;

    ## Define the website login username ##
	$request.Credentials = New-Object System.Management.Automation.PSCredential ("YourUserName", $passwd);

    ## Make the Get request and pipe output to the destination file ##
	$request.Downloadstring($url) | Out-File "$($mypath)\foo $($mydate).csv" -force;

    ## Send an email confirming the download completed ##
	sendEmail ("Downloaded $($date)", "Downloaded successfully to $($mypath\foo $($mydate).csv")	

    ### Send a success message to the console. Uncomment this for testing ##
    #Write-Host("Download Finished")

}

Catch [System.Net.WebException], [System.IO.IOException] {
    ## If there's an error send a message to the console ##
	#Write-Host "Nothing to download: (404)";

    ## Send an email indicating a download error ##
	sendEmail ("Failed Download on $($date)", "Nothing to download - $_error")

    ## Exit gracefully ##
	Exit

	}

Throw this all into one long PowerShell script (download.ps1) then add it to the Windows Scheduler as a Scheduled Task and you should be good to go.