Monday, 19 October 2020

A quick way to create dummy text using MSWord

 While creating a sample page, I needed to populate some sample text quickly without using any documents from the office. I started random typing, but I quickly remembered the built in marcos in Word for just such a purpose.

If you type in

=lorem()

and press enter, you get one line of Lorem Ipsum

if you type in 

=lorem(10)

and press enter, you get 10 lines.

If you prefer English to Latin, then type in 

=rand(10)

and press enter for 10 lines of 'random' text (not really random, but its text that is readable that I did not have to type) 

Confluence: How to create a 'DRAFT' watermark using CSS

I added the following to my Confluence page:



To do it, I put the following text in an HTML block at the top of the page:

<style>

.watermark {

    opacity: 0.5;

    color: BLACK;

    position: fixed;

    top: 45%;

    left: 50%;

font-size: 110px;

font-weight: 100;

    background: yellow;

padding-left: 50px;

padding-right: 50px;

}

.rotate {

  transform: rotate(-45deg);

  /* Legacy vendor prefixes that you probably don't need... */

  /* Safari */

  -webkit-transform: rotate(-45deg);

  /* Firefox */

  -moz-transform: rotate(-45deg);

  /* IE */

  -ms-transform: rotate(-45deg);

  /* Opera */

  -o-transform: rotate(-45deg);

  /* Internet Explorer */

  filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);

}

</style>

<div class="watermark rotate ">Draft</div>


It seems to work well across browser too.

Monday, 27 July 2020

Confluence: Buttons to toggle expander controls

While writing a simple page in Confluence, I used expander controls to help manage real estate. To help users, I added two buttons (expand all, collapse all) to enhance the user experience.

After a little experimentation, I deceided to use the OOTB icons as the trigger for the logic. A simple piece of JavaScript to check for the "chevron right" class in the anchor controls, and process the logic accordingly.

Here is the script (to be placed in an HTML control on the page)

<script language="JavaScript">
function expandUI(isClosed)
{ var a = document.getElementsByClassName("expand-control");
  var b = document.getElementsByClassName("expand-icon")
for (let i = 0; i < a.length; i++){
if (b[i].classList.contains("aui-iconfont-chevron-right") == isClosed)
{
a[i].click();
}
}
}
// make sure the page loads with the expanders expanded
window.addEventListener("load", function(){ expandUI(true); });
</script>
<input id="custombtn" type="button" value="Expand All" onClick="expandUI(true);">
<input id="custombtn2" type="button" value="Collapse All"  onClick="expandUI(false);">

Tuesday, 26 November 2019

Developer Training for PCI Compliance

In my current role, I have been tasked with providing 'Developer Training' as part of our PCI Compliance Audit. The challenge with this task is finding a solution that is acceptable to the Auditor, but not cost prohibitive. Using an external training company is an easy way but its very expensive and does not help when new starters come on board. Another option is to provide internal training (did someone say WebGoat?), but that can be a challenge with logistics and timing.

The solution we eventually deceided on was creating a Quiz using Office 365 Forms, which was based on the OWASP Top 10 and OWASP Secure Coding Practices. Access is restricted to users within the organisation and the results cannot be tampered with.

Its a simple, cost effective, extendable solution to an otherwise complicate problem. The next step is to create a suitable quiz to challenge a developers knowledge ........

Wednesday, 1 August 2018

PowerShell: How can I list/document all the items in my azure subscription?

The following script will create an Excel file with each Resource Group as a tab.

First, I created a password file to reference from the script (no passwords in clear text please)
"xxxx" | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\Temp\Password.txt" 

Here is the function - it will create seperate CSV files per resource group and then merge them intoa a single Excel file at the end.

BTW, you may want to change the hard coded directories, username and filenames as required..... enjoy

# create a function to merge the csv files we have created
Function Merge-CSVFiles 
                Param( 
                                $CSVPath = "C:\csv\", ## Soruce CSV Folder 
                                $XLOutput="c:\Temp\csv\data.xlsx" ## Output file name 
                ) 
  
                $csvFiles = Get-ChildItem ("$CSVPath\*") -Include *.csv 
                $Excel = New-Object -ComObject excel.application 
                $Excel.visible = $false 
                $Excel.sheetsInNewWorkbook = $csvFiles.Count 
                $workbooks = $excel.Workbooks.Add() 
                $CSVSheet = 1 
  
                Foreach ($CSV in $Csvfiles) 
                { 
                                $worksheets = $workbooks.worksheets 
                                $CSVFullPath = $CSV.FullName 
                                $SheetName = ($CSV.name -split "\.")[0] 
                                $worksheet = $worksheets.Item($CSVSheet) 
                                $worksheet.Name = $SheetName 
                                $TxtConnector = ("TEXT;" + $CSVFullPath) 
                                $CellRef = $worksheet.Range("A1") 
                                $Connector = $worksheet.QueryTables.add($TxtConnector,$CellRef) 
                                $worksheet.QueryTables.item($Connector.name).TextFileCommaDelimiter = $True 
                                $worksheet.QueryTables.item($Connector.name).TextFileParseType  = 1 
                                $worksheet.QueryTables.item($Connector.name).Refresh() 
                                $worksheet.QueryTables.item($Connector.name).delete() 
                                $worksheet.UsedRange.EntireColumn.AutoFit() 
                                $CSVSheet++ 
                } 
  
                $workbooks.SaveAs($XLOutput,51) 
                $workbooks.Saved = $true 
                $workbooks.Close() 
                [System.Runtime.Interopservices.Marshal]::ReleaseComObject($workbooks) | Out-Null 
                $excel.Quit() 
                [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null 
                [System.GC]::Collect() 
                [System.GC]::WaitForPendingFinalizers() 
  

# define the working folder for the csv files  
$targetDir = "c:\temp\csv" 
  
# Extract the credential using password.txt as the password source 
$user = "richard.leeman@mycustomdomain.com" 

# the location of the password file created above
$file = "C:\Temp\Password.txt" 
$myCred=New-Object -TypeName System.Management.Automation.PSCredential  -ArgumentList $user, (Get-Content $file | ConvertTo-SecureString) 
Connect-AzureRmAccount -Credential $mycred 
  
# get all the assets 
$data = Get-AzureRmResource | Sort-Object ResourceGroupName, ResourceType 
  
# get a distinct list of resource groups 
$distinctRG = $data | Select-Object ResourceGroupName -Unique 
  
# export the data to CSV 
$len = $distinctRG.Length; 
  
$a = New-Object -comobject Excel.Application 
$a.Visible = $False 
  
for ($i=0;$i -lt $len; $i++) { 
                $name = $distinctRG[$i] 
                $filename = "$targetDir\$($name.ResourceGroupName).csv" 
                
                # Export the data to a file - PowerShell is awesome
                $data | Where-Object -FilterScript { $_.ResourceGroupName -eq $name.ResourceGroupName} | Sort-Object ResourceType, Name |  Export-Csv -Path $filename 

# merge all the files into the final document
Merge-CSVFiles -CSVPath $targetDir -XLOutput "$targetDir\MyCloudAssets.xlsx" 

Wednesday, 28 February 2018

Visual Studio: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project

I encountered this issue when trying to compile some old code.

I tried to download the SDK, but there are no active links.

My resolution was to install Visual C++' support in Visual Studio 2015 by re-running the installer.​ Its like killing a fly with a hand-grenade (3GB install), but as least it resolved the problem.

IE11 - Critical Error: Object doesn't support property or method 'addEventListener'

Add this code within the body tag and all is good.

 <script type="text/javascript">
        /* IE11 Fix */
        if (typeof (UserAgentInfo) != 'undefined' && !window.addEventListener) {
            UserAgentInfo.strBrowser = 1;
        }
    </script>​