Friday, 5 July 2024

Replace spaces

Have you ever found yourself staring at a folder full of files with spaces in their names, wishing for a quick way to tidy things up? As a fellow software engineer, I've been there too. While spaces in filenames are common in Windows, they can sometimes cause headaches, especially when working with scripts or command-line tools.


Today, I'm excited to share a nifty Microsoft PowerShell 7 solution that can help streamline your file organization by replacing those pesky spaces with underscores.


Let's dive into some code that will make your file management a breeze and potentially save you from future headaches. Whether you're a seasoned PowerShell pro or just getting started, this simple yet powerful piece of code is sure to become a valuable addition to your toolkit.


# Get all files in the current directory with spaces in their names and rename them, replacing spaces with underscores

Get-ChildItem -File |

    Where-Object { $_.Name -match '\s' } |
    Rename-Item -NewName { $_.Name -replace '\s+', '_' } -WhatIf

Renaming files that are in use by running processes can cause issues. Ensure that the items you're renaming are not actively being used by other applications. Remember to remove the -WhatIf parameter when you're ready to actually perform the rename operation.


File prefix

Picture this: You're knee-deep in a project, and you need a clean slate to work with. What do you do? You whip up a temporary playground – a fresh directory where you can toss all your project files without fear of messing up the originals.


But here's the kicker – you've got this nifty trick up your sleeve. You rename these files with a special prefix, like leaving breadcrumbs in a forest. Your go-to prefix? 'Gash'. It's your secret code that screams, "Hey, these files are just for now – feel free to bin them later!"


It's like creating your own little sandbox where you can build, break, and experiment to your heart's content. Pretty smart way to keep your work organized and your original files safe, if you ask me!


Here’s some Microsoft PowerShell code to rename files with our selected (preferred) prefix:


# Get all files in the current directory, excluding those that already start with 'gash'

Get-ChildItem -File |

    Where-Object { $_.Name -notmatch '^gash' } |

    Rename-Item -NewName { 'gash_' + $_.Name } -WhatIf


Renaming files that are in use by running processes can cause issues. Ensure that the items you're renaming are not actively being used by other applications.

WhatIf (risk mitigation) parameter: Use the -WhatIf parameter to simulate the rename operation without making actual changes. This can help you verify the expected outcome before committing to the change.

Remember to remove the -WhatIf parameter when you're ready to actually perform the rename operation


Wednesday, 27 March 2024

The Edington Music Festival

 I've been meaning to see and hear The Edington Music Festival for a while now, but I've not managed it yet. So thought I would write a few words on this long running music festival.


The Edington Music Festival is a festival of music within the liturgy, held in the 14th century Priory Church of St Katherine and All Saints in Edington, Wiltshire, UK. It is one of the oldest and most famous festivals of church music in the world, featuring over 80 musicians in three choirs, and offering new commissions, rediscovered music and music from the choral repertoire from the 16th century to the present day.


The festival was founded in 1956 by the organist and composer David Calcutt, and has since attracted many renowned singers, organists and composers to participate and perform. The theme of the 2024 festival is the extraordinary work of the 12th century Benedictine Abbess, Saint, mystic, poet and composer Hildegard of Bingen, whose 845th anniversary of her death is in 2024. The festival is free and open to the public, and visitors can enjoy the beautiful environment and the welcoming atmosphere of the Edington community.


The Edington Music Festival boasts a long history, possibly the longest running festival of church music in the world. Here's a quick rundown:

  • Founded in 1956 by Rev Ralph Dudley and David Calcutt, aiming to preserve the tradition of choral singing.
  • Began modestly with a weekend of choral liturgy, but its success led to an annual event. 
  • Currently, the festival lasts eight days with four daily services featuring three different choirs.
  • It focuses on sacred music, including beloved classics from the 16th century to the present day, alongside rediscovered pieces and newly commissioned works.
  • The festival has become a launchpad for many prominent singers, organists, and composers in the UK. 

William Edington was a 14th century English bishop and administrator. He served as Bishop of Winchester from 1346 till his death in 1366. He was also a key financial figure for King Edward III, acting as keeper of the wardrobe, treasurer and chancellor. He played a vital role in managing finances for the Hundred Years' War. As Bishop, he initiated a major rebuilding project of Winchester Cathedral and founded Edington Priory. 


The Edington Music Festival in 2024 will be held from Sunday, August 21st to Sunday, August 28th.  This marks the 65th year for the festival. 

Address:
Edington Priory Church
Monastery Road,
Edington,
Wiltshire
BA13 4QN
UK


See the following links for further information.

An overview of the Edington Music Festival


Edington Arts is a Registered Charity (no. 1187289), independent both of the Priory Church and of the Music Festival which takes place in it annually during August.


A Hidden English Gem
Edington’s majestic Priory church towers over this enchanting little village, tucked beneath the escarpment on the edge of Salisbury Plain, Wiltshire. Built in the 14th century by former Bishop of Winchester William of Edington, the Grade I listed building is now Wiltshire’s only perfect monastic church. Since 1956, supporters from far and wide have been helping local people to restore, maintain and improve this remarkable building.

The Friends organisation was founded in 1956 by the then Vicar of Edington, Canon Ralph Dudley.   Although most of the Friends live outside the parish, we’re united in our love of this great building.


Friends of The Priory Church of Edington - Charity overview


The theme of this year’s festival (2024) is the extraordinary work of the 12th century Benedictine Abbess, Saint, mystic, poet and composer Hildegard of Bingen; the 845th anniversary of her death is in 2024.


Edington church is unusual in that it was completed in a very short length of time (1352-61) and has remained largely unaltered since that time. It is one of the finest examples in the country of the transitional period between Decorated and Perpendicular Gothic architecture.


Edington Priory Church is famous for hosting the Edington Festival of Music Within the Liturgy (often known as the 'Edington Festival'): a week-long celebration of all that is best in church music. Participants come from many different Anglican and Roman Catholic cathedrals and Oxbridge colleges, and visitors travel to the Festival from all over the world. The midweek Evensong is always broadcast around the world by BBC Radio 3.



Monday, 19 February 2024

Drop-In Sessions

One of the services HMR Circle (Heywood, Middleton & Rochdale (Lancashire)) provides is a digital support (IT) drop-in session for people who wish to improve or require assistance with things IT related. These sessions are held at The Tottington Centre every Thursday between 1 and 2PM.


The Tottington Centre is a vital community hub in Tottington, near Bury in Lancashire, UK. It hosts various groups, events, and activities and includes a well-used library with almost 9000 books. Furthermore, the Tottington Tea Rooms, part of the Tottington Centre, is a popular spot and is now open to the public. Tottington is a town in the Metropolitan Borough of Bury in Greater Manchester, on the edge of the West Pennine Moors.


The Tottington Centre can be found in Market Street, Tottington, Lancashire BL8 3LL.


 

Sunday, 17 June 2018

Kipple

I recently read the book "Do Androids Dream of Electric Sheep?" by Philip K. Dick and couldn't help be amused by the following from the book (page 52):

Kipple is useless objects, like junk mail or match folders after you use the last match or gum wrappers or yesterday's homeopape. When nobody's around, kipple reproduces itself. For instance, if you to go bed leaving any kipple around your apartment, when you wake up there is twice as much of it. It always gets more and more. No one can win against kipple, except temporarily and maybe in one spot.

Wednesday, 30 May 2018

Word Count examples

In applying for some jobs, rather than sending in a CV, some posts require you to fill out an Evidence Questionnaire as a demonstration of your skills. Typically, each question could require you to use up to 100 words.

I searched the Internet to look web sites which give examples of what N words look like. For example, what 50, 100, 150 words etc look like. One site I came across was Word Count examples.

It's certainly useful to see what these amount of words (say 100) look like before putting pen to paper or keyboard to word processor.



Keywords: word count exmaples


Saturday, 26 May 2018

Posting code

The web site at the following URL can be used to format code suitable for posting in this blog.

http://codeformatter.blogspot.co.uk/



Keywords: posting code java powershell

List files for a specific date

There often comes a time when I'd like to list (select) files for a specific date. For example, if I'm looking for log files for a particular date.

The following PowerShell code can be used for this purpose.


1:  $path = 'C:\Family\powershell';
2:  $targetDate = '2018-04-09';
3:
4:  Get-ChildItem -Path $path -File |
5:    Where-Object {$_.LastWriteTime.ToString("yyyy-MM-dd") -eq $targetDate}
6:
7:  Write-Host 'All done now';
8:


In this example, I'm looking for files with a LastWriteTime of 2018-04-09. All other files will be ignored.


Keywords: powershell files lastwritetime target date

PowerShell about_Scopes

The following published Microsoft article explains the concept of scope in Windows PowerShell and shows how to set and change the scope of elements.

PowerShell Scopes

  • Global:
  • Local:
  • Script:
  • Private:
  • Numbered Scopes:


Click here to read the full article.



Keywords: powershell scopes


Wednesday, 11 April 2018

Open data search engines

If you're looking for datasets for the purpose of research, statistics, etc, one way to find the data is to use the following search term in a search engine:

open data search engine

This will give you a few items to be going on with. Worth trying.


Sunday, 8 April 2018

Ancient software

I was looking on the Internet today looking for PowerShell related information for a scriptblock I was writing when I came across this comment on one of the stackoverflow.com pages.

I don't work for a software company either. But that doesn't mean that your corporate computing environment gets a free pass on being stuck on ancient software. Staying current on your software is part of the cost of doing business today and if they're not willing to invest there, they're probably not investing in their people or other things that are important to keeping operations running.

On reading this, it certainly struck home for a number of reasons. How very true this comment is.


Tuesday, 11 July 2017

Using PowerShell to grep

PowerShell is not Unix of course, but nevertheless, it does have a useful cmdlet to emulate the very useful Unix grep command. This is achieved by the Select-String (finds text in strings and files) cmdlet.

In order to learn more about PowerShell and grep, have a read of Grep, the PowerShell way. It's an excellent article on a comparison between the two. When you read the article, you'll see reference to sls. This is just an alias for Select-String which saves you having to type out the cmdlet name in full.



PS> Get-Alias sls

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           sls -> Select-String
 
I use Select-String myself from time to time but never seem to remember the best way of using it. This article serves as an aide-memoire.


See also


Grep, the PowerShell way
https://communary.net/2014/11/10/grep-the-powershell-way/

Select-String (finds text in strings and files)
https://msdn.microsoft.com/en-us/powershell/reference/5.0/microsoft.powershell.utility/select-string



Keywords: unix grep sls select-string search text file

Sunday, 15 January 2017

Loading a PowerShell assembly

From time to time I write a PowerShell program which makes use of the System.Windows.Forms Namespace. As the documentation reminds us “The System.Windows.Forms namespace contains classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows operating system”.

In order to make use of this namespace, the relevant assembly needs to be loaded. Up until now I’ve been loading the assembly with the .NET Framework class:

[System.Reflection.Assembly]:: LoadWithPartialName ("System.Windows.Forms") | Out-Null
[System.Reflection.Assembly]:: LoadWithPartialName ("System.Drawing") | Out-Null

Use of the "Assembly" class is discouraged as this API is now obsolete so I now use the "Add-Type" cmdlet:

Add-Type -AssemblyName "System.Windows.Forms";
Add-Type -AssemblyName "System.Drawing";

Loading the assembly with the name alone doesn’t take into account any versions. So, if you wish to load an assembly with a particular version, a different syntax of the command will be required. For the scripts I’m writing, this hasn’t given me a problem although I guess I may have to think about this issue sometime in the future.




Keywords: load powershell assembly

Sunday, 3 July 2016

Instant SQL Formatter (beautify)

I quite often have a need to reformat RDBMS SQL statements into something readable and consistent. The advantage of doing this is the statements are easier on the eye to read.

Two web sites I find useful in this respect are:

http://www.dpriver.com/pp/sqlformat.htm

http://sqlformat.org/


Keywords: sql format beautify

Sunday, 3 April 2016

Gnuplot and graphs

Gnuplot is a command-line driven graphing utility for various platforms. I have used this in the past and the product came to mind again as I was learning to create graphs using R. At present I'm I've not gone back to Gnuplot as I'm creating my statistics graphs using R.


See also

http://www.gnuplot.info/

https://en.wikipedia.org/wiki/Gnuplot

R (programming language)
https://en.wikipedia.org/wiki/R_(programming_language)

https://www.r-project.org/about.html


Keywords: r language, gnuplot, software

CERN and ROOT

ROOT is an object-oriented program and library developed by CERN. It was originally designed for particle physics data analysis and contains several features specific to this field, but it is also used in other applications such as astronomy and data mining.

It provides all the functionalities needed to deal with big data processing, statistical analysis, visualisation and storage.

Rene Brun and Fons Rademakers,
ROOT - An Object Oriented Data Analysis Framework,
Proceedings AIHENP'96 Workshop, Lausanne, Sep. 1996, Nucl. Inst. & Meth. in Phys. Res. A 389 (1997) 81-86.

I noted this with interest as I was looking for something else relating to statistics. I don't think I'll be taking this language any further at present as I've other things to learn.



Keywords: root cern software

Saturday, 26 March 2016

Online Distance Calculator

Distance calculator is a tool for calculating the distance between two cities or places on map.

Distance units available when obtaining the distance are:

  • Kilometers
  • Miles
  • Meters

Upon entering the start location and end location cities, the result is shown as both as the crow flies (great circle distance) and the driving distance if this journey were taken by road.

Really useful and helpful web site if one wants to find distances between two cities.

See also


Sunday, 28 February 2016

COMP102 for 2015 Tri T1 Course (Java)

Victoria University of Wellington, School Of Engineering and Computer Science hosts the Java course “Introduction to Computer Program Design: COMP102 2015 Trimester T1” (https://ecs.victoria.ac.nz/Courses/COMP102_2015T1/WebHome).

The purpose of the course is:

Quote

This course introduces the fundamentals of programming in a high-level programming language (Java), using an object oriented approach to program design. Students develop their programming skills by constructing computer programs for a variety of applications. The course provides a foundation for all later courses in computer science, and develops programming skills useful for students in many other disciplines.

Unquote

Given that Java assignment files can be downloaded, I felt it's a useful way to practice my Java skills as seen from the perspective of Victoria University of Wellington.



Keywords: java new zealand cs computer science

Friday, 15 January 2016

Oracle ODP.NET and Windows PowerShell


The above link is an interesting article on the subject of using Oracle ODP.NET and Windows PowerShell to access to Oracle databases.

In order to do this, a complete package called ODAC ( Oracle Data Access Components ) from Oracle can be downloaded to provide the components in order to achieve this.

The site 'Data Provider for .NET Developer's Guide' (http://docs.oracle.com/cd/E51173_01/win.122/e17732/client.htm#ODPNT0008) describes the Oracle Data Provider for .NET classes which will be helpful in developing any Oracle ODP.NET application or script.

The Data Provider for .NET Developer's Guide can be found at http://docs.oracle.com/cd/E51173_01/win.122/e17732/toc.htm



Keywords: oracle powershell odp .net

Saturday, 3 October 2015

Learning Statistics

I've recently taken an interest in statistics and I'm making efforts to learn more about the subject. One useful Internet resource is the Australian Bureau of Statistics web site.

In particular, The 'Understanding statistics' page aims to support your statistical literacy development and assist you understand, evaluate and communicate statistical data and information. Data sets are also available from the ABS web site which can be used in a statistical context to learn and consolidate ones knowledge of the subject.


Keywords: abs statistics australian bureau