Skip to content

Instantly share code, notes, and snippets.

View ahills60's full-sized avatar
🏠
Working from home

Andrew Hills ahills60

🏠
Working from home
View GitHub Profile
@ahills60
ahills60 / keybase.md
Created January 29, 2021 17:03
Keybase

Keybase proof

I hereby claim:

  • I am ahills60 on github.
  • I am andrewhills (https://keybase.io/andrewhills) on keybase.
  • I have a public key ASCuEzkROEF8LcLx8Vbib1tug1461_lAhQd-B6Yg0QklaAo

To claim this, I am signing this object:

@ahills60
ahills60 / find_duplicates.ps1
Last active August 20, 2020 21:58
PowerShell script for finding duplicate variable or label names. Useful for looking for duplicate label names in Microsoft Dynamics 365 AX label files.
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "Text files (*.txt)| *.txt"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
@ahills60
ahills60 / ceiling.c
Created October 8, 2018 16:57
Compute the ceiling of an integer division without floating point
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#define ceilu32(x, y) ((((((uint32_t) x) << 16) / (uint32_t) y) + 0xffff) >> 16)
int main(void)
{
uint16_t var1, var2, result;
@ahills60
ahills60 / delvars.py
Created October 8, 2018 15:52
Clearing variables (not modules) from a Python frame
import sys, copy
def clearvars():
varlist = copy.copy(sys._getframe(1).f_locals)
for var in varlist:
if "_" not in var and not isinstance(varlist[var], type(sys)):
print("Deleting %s..." % var)
del sys._getframe(1).f_locals[var]
@ahills60
ahills60 / MSWordFixTextbox.vba
Created January 26, 2017 18:53
Microsoft Word selection: change the font, its size and paragraph spacing to single (great for figures!)
Selection.Font.Name = "Arial"
Selection.Font.Size = 9
Selection.ParagraphFormat.LineSpacingRule = Word.WdLineSpacing.wdLineSpaceSingle
@ahills60
ahills60 / 0_reuse_code.js
Created August 9, 2016 11:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ahills60
ahills60 / div10bin.h
Created October 14, 2015 16:26
This function generates a string without sprintf or ifs but shift and adds only to divide by 10 and calculate remainders in base 10
#define useshort
#ifdef useshort
// For 16-bit integers (short)
#define DIVU10(q, r, n) q = (n >> 1) + (n >> 2); q += q >> 4; q += q >> 8; q >>= 3; r = n - (((q << 2) + q) << 1); n = q + (r > 9); r -= (((r > 9) << 2) + (r > 9)) << 1;
#define NOBITS 16
#define STRSIZE 26
#define DEFSTR {"0000000000000000 (00000)\n\r"};
#else
// For 32-bit integers (long)
@ahills60
ahills60 / PrettyNumbers.c
Created September 16, 2014 13:21
Function to convert (long long) integers to strings with thousand comma separators
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
char *PrettyNumbers(long long int inputBytes)
{
double tempVar = log10((double) inputBytes);
int noElements = (int) floor(tempVar / 3.0), n, remn = (int) (tempVar + 1) % 3;
char *output, tempString[4];
@ahills60
ahills60 / PrintMemory.c
Created September 16, 2014 11:49
Function to add units and format memory values nicely
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
char *PrintMemory(long long int inputBytes)
{
double tempVar = log10((double) inputBytes);
int noElements = (int) floor(tempVar / 3.0);
char *conv, units = '\0', *output;
@ahills60
ahills60 / autoscp
Created August 7, 2014 15:52
BASH script to run a command and then secure copy (scp) files. If scp was successful, files are deleted.
#!/bin/bash
# This script bootstraps another with parameters
# Take action based on input parameter
echo "Executing command..."
$1
if ["$?" -eq "0"]