Search This Blog

Wednesday, October 10, 2018

Java SVG Maker

Sick again at home and I decided to do the same program in Java!

Got to my last post for some background: Powershell SVG Maker

Here's the code...

import java.io.IOException;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.awt.image.BufferedImage;

public class SVGMaker {

    public static void main(String[] args) {
        String inFilePath = args[0]; // "LesleyatHonda.12.Dither.Part.White.png";
        String outFilePath = args[1]; //"LesleyatHonda.12.Dither.Part.White.svg";
        int SVGScale = 10;
        String newLine = System.lineSeparator();

        try {
            BufferedImage image = ImageIO.read(new File(inFilePath));
            File outFile = new File(outFilePath);
            FileOutputStream OutFOS = new FileOutputStream(outFile);
            OutputStreamWriter outOSW = new OutputStreamWriter(OutFOS,"UTF-8");
            outOSW.write("<xml version\"1.0\" encoding=\"UTF-8\"?>");outOSW.write(newLine);
            outOSW.write("<svg version\"1.1\" baseProfile=\"full\" width=\""+(image.getWidth()*SVGScale)+"\" height=\""+(image.getHeight()*SVGScale)+"\" xmlns=\"http://www.w3.org/2000/svg\">");outOSW.write(newLine);
            for (int ypos = 0 ; ypos < image.getHeight() ; ypos++ ) {
                for (int xpos = 0 ; xpos < image.getWidth() ; xpos++ ) {
                    int pixel = image.getRGB(xpos,ypos);
                    int pAlpha = (pixel>>24) & 0xff;
                    int pRed = (pixel>>16) & 0xff;
                    int pGreen = (pixel>>8) & 0xff;
                    int pBlue = pixel & 0xff;
                    outOSW.write("<rect Fill\"#"+String.format("%02X",pRed)+String.format("%02X",pGreen)+String.format("%02X",pBlue)+"\" x=\""+(xpos*SVGScale)+"\" y=\""+(ypos*SVGScale)+"\" width=\""+SVGScale+"\" height=\""+SVGScale+"\"/>");outOSW.write(newLine);
                }
            }
            outOSW.write("</svg>"");outOSW.write(newLine);
            outOSW.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}





Here's the run line...

java SVGMaker LesleyatHonda.12.Dither.Part.White.png LesleyatHonda.12.Dither.Part.White.svg


Producing...





Tuesday, October 9, 2018

Powershell SVG Maker

I was going to sit around ill at hone and make an SVG one little square at a time in Inkscape of this image I use...



However, after 4 dots I got bored.

I know that an SVG file is an XML based descriptor of images and shapes and know that I can use  minimal information to make a test file that is similar to the following 2x2 block...

<xml version="1.0" encoding="UTF-8"?>
<svg version="1.1" baseProfile="full" width="20" height="20" xmlns="http://www.w3.org/2000/svg">
<rect fill="#000000" x="0" y="0" width="10" height="10"/>
<rect fill="#000000" x="10" y="0" width="10" height="10"/>
<rect fill="#ffffff" x="0" y="10" width="10" height="10"/>
<rect fill="#000000" x="10" y="10" width="10" height="10"/>
</svg
>

So... by grabbing the image, and looping through the pixels we can create all the rects we need. we can even keep the original color of the pixels. This routine also has a scaling factor in it.


$FilePath = 'LesleyatHonda.12.Dither.Part.White.png' $Image = [System.Drawing.Image]::FromFile($filePath) # Simple dirty UTF-8 outfile << THIS IS MPORTANT!! $OutFilePath = 'LesleyatHonda.svg' $SVGScale = 10 '<?xml version="1.0" encoding="UTF-8"?>' | Out-File $OutFilePath -Encoding utf8 '<svg version="1.1" baseProfile="full" width="'+($Image.Width*$SVGScale)+'" height="'+($Image.Width*$SVGScale)+'" xmlns="http://www.w3.org/2000/svg">' | Out-File $OutFilePath -Append -Encoding utf8 For($ypos=0;$ypos -lt $Image.Height;$ypos++){ For($xpos=0;$xpos -lt $Image.Width;$xpos++){ $Pixel = $Image.GetPixel($xpos,$ypos) '<rect fill="#'+($Pixel.Name.substring(2,6))+'" x="'+($xpos*$SVGScale)+'" y="'+($ypos*$SVGScale)+'" width="'+$SVGScale+'" height="'+$SVGScale+'"/>' | Out-File $OutFilePath -Append -Encoding utf8 } }; '</svg>' | Out-File $OutFilePath -Append -Encoding utf8














Thursday, October 4, 2018

Notes View Exporter


Modify the variables at the top and let'r rip!




## Notes View Exporter in Powershell

Set-Location 'C:\Program Files (x86)\IBM\Notes' ## Notes Program Dir
$dominoServiceName = 'Appsrv001/MyCompany'
$dbName = 'names.nsf'
$viewName = 'Groups'


$session = $null; $session = New-Object -ComObject Lotus.NotesSession; $session.Initialize(); 'Notes version: '+$session.NotesVersion
$db = $null; $db = $session.GetDatabase($DominoServiceName, $dbName, 1);'DB Title: '+$db.Title
$view = $null; $view = $db.GetView($viewName);'Entry Count: '+$view.EntryCount

$oOut=@(); $count = 0;     $dtStart = (get-date)
if($view.EntryCount -gt 0){
    $doc = $view.getFirstDocument();
    $viewcolumns = $view | select -ExpandProperty Columns
    While ($doc -ne $null){
        if (($count/100) -eq [int]($count/100)){$dtCurr = (get-date); 'Count: '+$count+' of '+$view.EntryCount+': '+$dtCurr.Hour.ToString('#0')+':'+$dtCurr.Minute.ToString('#0')+':'+$dtCurr.Second.ToString('#0')+'.'+$dtCurr.Millisecond.ToString('###0')}                   
        $oItem = $null; $oItem = New-Object PSObject
        for ($i=0;$i-lt$viewcolumns.count;$i++){
            $val=$null;$val=if($viewcolumns[$i].Formula -gt ''){$viewcolumns[$i].Formula}else{$viewcolumns[$i].Itemname};
            $oItem = $oItem | Add-Member @{(''+$i+'. '+$viewcolumns[$i].title)=[string]''+($session.Evaluate($val,$doc))} -PassThru
        };
        $oOut += $oItem
        $doc=$view.GetNextDocument($doc); $count++
    }
}

$YYYYMMDDhhmmss = $dtStart.year.ToString('###0')+$dtStart.Month.ToString('#0')+$dtCurr.Day.ToString('#0')+$dtCurr.Hour.ToString('#0')+$dtCurr.Minute.ToString('#0')+$dtCurr.Second.ToString('#0')
$oOut | export-csv ('c:\data\notesviewexport'+$YYYYMMDDhhmmss+'.csv')
$oOut | Export-Clixml ('c:\data\notesviewexport'+$YYYYMMDDhhmmss+'.xml')

Tuesday, July 31, 2018

Getting to Office 365 Calendar entries

I occasionally have to do low level analysis on items in a mailbox. Here's a how I typically have to do it.

Basically its.. 


  1. Get credentials
  2. Instantiate environment & containers
  3. Create collection
  4. Do stuff with collection

like this...

## Generic work session stuff start
##
$ExCreds = get-credential


<# I put this stuff in my profile and is a little more than needed for this topic
Enable-PSRemoting -Force
Set-ExecutionPolicy RemoteSigned -Force
Import-Module AzureAD
Import-Module LyncOnlineConnector
Import-Module MSOnline
Import-Module SkypeOnlineConnector
#>

Connect-AzureAD -Credential $ExCreds
Connect-MsolService -Credential $ExCreds
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri"https://outlook.office365.com/powershell-liveid/" -Credential $ExCreds -Authentication "Basic" -AllowRedirection
Import-PSSession $ExchangeSession
$lyncSession = New-CsOnlineSession -Credential $ExCreds
Import-PSSession $lyncSession
## 
## Generic work session stuff end


$usermail='lesley@mycompany.com'

$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP2
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)
# $service.UseDefaultCredentials = $true
$creds = New-ObjectSystem.Net.NetworkCredential($ExCreds.UserName.ToString(),$ExCreds.GetNetworkCredential().password.ToString()) 
$service.Credentials = $creds 
Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll" 
$folderid= new-objectMicrosoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$Usermail)   
$service.Url = $uri

$Calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
$exportCollection = @()
#Define Date to Query
$StartDate = (Get-Date).AddDays(-1)
$EndDate = (Get-Date).AddDays(7)
$CalendarView = New-ObjectMicrosoft.Exchange.WebServices.Data.CalendarView($StartDate,$EndDate,1000)   
$CalendarItems = $service.FindAppointments($Calendar.Id,$CalendarView

$counter =  0''foreach ($CalendarItem in $CalendarItems){''+$counter+' '+$CalendarItem.subject;$counter++}
'''Total entries: '+$CalendarItems.TotalCount


0 Ape Pilot Check-Ins
1 Final prep for leadership meeting
2 Catch-up
Elfs Pilot Area Check In
4 Q1 ADM Pre-Review (before Pam)
5 Foundations for a Leader
6 FTL - Module 4
7 WildSpark Monthly - Don't be McFly
8 POD Pilot Visit
9 Mad Pilot Area Check-In
10 POD Staffing Plan Update to Comp
11 HR Project - Team Meeting
12 POD Career Path Policies - Open Items
13 Reporting in High
14 Foundations for a Leader - Facilitator Touch Base
15 High Reporting
16 Review 1 with Dept Mgrs
17 Weekly POD Meeting
18 Monthly Connect/Update
19 Review for POD
20 Follow Up on Staffing Plan for Org Design
21 Smart Shine
22 Dental Cleaning
23 FTL Touchbase
24 Weekly POD Project
25 Ape Pilot Check-Ins
26 Back to School Forms
27 Elfs Pilot Area Check In
28 Org Design Staffing Plan

Total entries: 29