Calculating compound interest with Python 3

Compound stonks only go up! I have a growing interest in finance and analytics, so it felt like a great idea to start creating my own set of financial tools with Python. This article will explain how I created a simple but effective script for calculating compound interest with Python. I wrote this in Python 3 (as all new Python projects should be from now onwards), but the library dependencies are very lightweight, making this something that could easily be re-written from Python 2. ...

January 3, 2021 · 3 min · Tom

How to invoke UAC in a Windows Batch script

Here is my quick and easy way to raise the privilage level of a Windows Batch script; allowing you to run your code at an administrator level. This is not a new question and has been asked many times on StackOverflow forums. The best answer I was able to find was the following from dbenham: https://stackoverflow.com/questions/1894967/how-to-request-administrator-access-inside-a-batch-file/10052222#10052222 That being said there are many ways to skin this cat, so I came up with my own method, all be it derivative. The main difference in the following code is that you will always get a UAC prompt in my variant of the code, even if you are currently running it as an account that is a member of the local administrators group: ...

December 29, 2020 · 2 min · Tom

Copy Paste in vSphere before installing VMware tools

I’ve spent enough time building VMs in vSphere to know that the first few minutes between starting the VM and getting VMware Tools installed is agonising. Similar to my ‘Copy Paste With Powershell Sendkeys‘ script, I have another tool written in AutoIT which sends defined keyboard strokes to the system. So this is not exactly ‘copy paste in vSphere’, but it achieves the same goal. ...

May 18, 2020 · 2 min · Tom

Python 3 SSH with Paramiko

I have a number of projects which I am currently working on which usually involve a raspberry pi and so other TCP enabled object. One project, in particular, is to control a KVM server with buttons connected to a raspberry pi (follow on social media or RSS for that future post). I have been using Python 3 SSH with Paramiko to send commands KVM server from the pi. Here is how I do that… ...

May 15, 2020 · 3 min · Tom

How To: Python infinite loops with while true

Here is a quick guide on how to create an infinite loop in python using a ‘while true’ statement. There are number of reason that you might want to implement this; a great use case would be outputting a fluctuating variable to the terminal such as a temperature reading from a sensor. loops that make your brain hurt A ‘while true’ statement allows us to run a sequence of code until a particular condition is met. In order to make that sequence of code run in an infinite loop, we can set the condition to be one that is impossible to reach. Better still, we can simply omit the condition altogether to ensure that the while true loop never ends. ...

May 5, 2020 · 2 min · Tom

Prevent Screensavers and Lock-screens with Powershell

There might be a number of reasons to want to prevent your windows screensavers and lock-screens from engaging and in some cases (no doubt yours if you have hit this article from a search engine) local policy on the machine preventing you from changing these settings. Powershell lets us work around this problem and prevent the machine from locking or activating a screensaver. Prevent Screensavers and Lock-screens The bulk of the code below has been lifted from this great write up: https://dmitrysotnikov.wordpress.com/2009/06/29/prevent-desktop-lock-or-screensaver-with-powershell/ I just took things one step further by adding an infinite loop. My version of this code will run indefinitely. ...

March 26, 2020 · 2 min · Tom

Getting started with Python 3 - a beginner's cheat sheet

Python.Org I have been getting started with python 3 – I want to make this my primary scripting language. One way I like to assist myself whilst I learn the rope is to maintain a crib sheet filled with all the trivial things I would otherwise forget. Python 3 Cheat Sheet #Define Variables programming_languages: "Python", "VB", "C++", "C#" #Print Variables print(programming_languages) print('--------------------') #Basic for loop + variables for language in programming_languages: print(language) print('--------------------') #Basic Function def FuncExample(): i: 1 for language in programming_languages: #Concatinate Strings and Integers in print statements print("Language " + str(i) + ":" + language) #Increment Integer i += 1 FuncExample() print('--------------------') #Functions with Variables #1 - Strings def FuncVarExample1(fname, lname): #Print with CRLF print("First Name: " + fname + "\r\n" + "Last Name: " + lname) FuncVarExample1("Joe","Bloggs") print('--------------------') #Functions with Variables #2 - Integers + Returning Values def FuncVarExample2(x, y): #Basic integer maths return x+y #Concatenating Strings and Integers print("33 + 42: " + str(FuncVarExample2(33,42))) print('--------------------') You can also find more code snippets here: https://exitcode0.net/code-samples/ ...

November 23, 2019 · 1 min · Tom

Powershell - Checking the Language Mode

For security purposes, it is possible to control the language mode in a given Powershell session. These language modes can constrict which modules can be loaded during the life of a powershell session. Learn mode about Powershell langeuage modes: About Language Modes – Microsoft Detect the Current Language Mode $sLangMode: $ExecutionContext.SessionState.LanguageMode If ($sLangMode -ne “FullLanguage”){ Write-Host ” !! Unable to run scrit – Powershell Using Wrong Language Mode !! ” } Else{ ...

February 5, 2019 · 1 min · Tom

'Copy, Paste' With Powershell Sendkeys

This is really quick nugget of Powershell for anyone who is struggling to copy and paste into a particular window or dialog box. Perhaps it is a case of a website which prevents text form being sent to a field from the clipboard, or in my case, a windows UAC prompt. If you are following password best practices, your passwords should be long, complex and contain zero dictionary words. Furthermore, you should have a different password for every site and service. So, when a user interface doesn’t allow you to paste a password, life gets that little bit more difficult. ...

February 2, 2019 · 2 min · Tom