Skip to content

Instantly share code, notes, and snippets.

Tim Iles timiles

  • London, UK
View GitHub Profile
@timiles
timiles / Rename-ItemsByDateTaken.ps1
Last active Feb 9, 2019
PowerShell script to prefix files by Date Taken from EXIF data
View Rename-ItemsByDateTaken.ps1
function Get-DateTakenFromExifData {
param([String] $filePath)
try {
$imgData = New-Object System.Drawing.Bitmap($filePath)
try {
[byte[]]$dateTakenExifData = $imgData.GetPropertyItem(36867).Value
[string]$dateString = [System.Text.Encoding]::ASCII.GetString($dateTakenExifData)
return [datetime]::ParseExact($dateString, "yyyy:MM:dd HH:mm:ss`0", $null)
}
@timiles
timiles / Rename-ItemsByLastWriteTime.ps1
Created Feb 8, 2019
PowerShell script to rename files ordered by last modified date
View Rename-ItemsByLastWriteTime.ps1
$files = Get-ChildItem | Sort-Object LastWriteTime
For ($i=0; $i -lt $files.Length; $i++) {
$from = $files[$i].Name
$to = "$($i.ToString('000')) $from"
Write-Host "Renaming `"$from`" to `"$to`""
Rename-Item $from $to
}
@timiles
timiles / Base36.cs
Created Oct 25, 2018
Encode and decode between base 10 and base 36
View Base36.cs
public static class Base36
{
private const string Digits = "0123456789abcdefghijklmnopqrstuvwxyz";
private const string Max = "1y2p0ij32e8e7";
/// <summary>
/// Converts from base 10 to base 36.
/// </summary>
/// <param name="value">Value to convert</param>
View EnumSnakeCaseExtensions.cs
using System;
using System.Text.RegularExpressions;
public static class EnumSnakeCaseExtensions
{
public static string ToSnakeCase(this Enum value)
{
return Regex.Replace(value.ToString(), @"(\p{Ll})(\p{Lu})", "$1_$2").ToLower();
}
@timiles
timiles / kenken.js
Created Aug 21, 2018
KenKen is a Sudoku-like puzzle. I solved one just by lots of guessing, and was surprised that I got it perfectly right first time. I wondered if actually there were many solutions and I had found just one. So I wrote a bit of code, and actually it turns out I was just lucky. I think KenKen is a stupid puzzle that requires brute forcing rather th…
View kenken.js
// These values are specific to the problem I was solving
const GRID_SIZE = 6;
const BLOCK_CELL_INDICES = [[0, 6], [1, 2], [3, 4], [5, 11], [7, 13], [8, 14], [9, 15], [10, 16],
[12, 18], [17, 23], [19, 20], [21, 22], [24, 25], [26, 32], [27, 33], [28, 29], [30, 31], [34, 35]];
const BLOCK_RULES = [[1, '-'], [3, '/'], [4, '-'], [4, '-'], [4, '-'], [1, '-'], [5, '+'], [2, '-'], [10, '*'],
[2, '-'], [2, '/'], [2, '-'], [6, '*'], [1, '-'], [3, '-'], [2, '/'], [4, '-'], [3, '-']];
@timiles
timiles / EnumHelper.cs
Created Feb 6, 2018
Convert enum type to readable dictionary values
View EnumHelper.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text.RegularExpressions;
public static class EnumHelper
{
public static IDictionary<int, string> ToDictionary(this Type enumType)
{
View gist:2b634e31b68c3ce97144e905aa092858
ng lint
errorlevel=$?
if [ $errorlevel -ne 0 ]
then
echo "##teamcity[buildProblem description='Lint errors found, see Build Log for details']"
fi
View setup_git_configs.ps1
git config --global remote.origin.prune true
git config --global alias.lg "log --oneline --graph --decorate"
git config --global color.ui.auto true
git config --global color.status.added "green normal bold"
git config --global color.status.changed "red normal bold"
git config --global color.status.updated "green normal bold"
git config --global color.status.untracked "yellow normal bold"
git config --global color.branch.remote "red normal bold"
git config --global color.branch.local "magenta normal bold"
git config --global color.diff.old "red bold"
@timiles
timiles / download-transactions.js
Last active Mar 8, 2016
Download Barclays bank transactions from logged in view, as csv file. (Export feature does not include balance info.)
View download-transactions.js
String.prototype.cleanMoney = function() {
return this.replace('-', '').replace('£', '').replace(',', '');
}
var csv = '';
var trs = $('#filterable-ftb tr');
for (var index = 1; index < trs.length; index++) {
var tr = trs[index];
var col0 = $('td[headers=header-date]', tr).text().trim();
View TestOutputAppender.cs
using log4net.Appender;
using log4net.Core;
using log4net.Layout;
using Xunit.Abstractions;
public class TestOutputAppender : AppenderSkeleton
{
private readonly ITestOutputHelper _xunitTestOutputHelper;
You can’t perform that action at this time.