Skip to content

Instantly share code, notes, and snippets.

@timiles
timiles / Rename-ItemsByLastWriteTime.ps1
Created February 8, 2019 19:59
PowerShell script to rename files ordered by last modified date
$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 October 25, 2018 09:14
Encode and decode between base 10 and base 36
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>
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 August 21, 2018 11:56
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…
// 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, '-']];
<!doctype html>
<html ng-app>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.10/angular.min.js"></script>
<script src="http://www.cornify.com/js/cornify.js"></script>
<style>
#cornifycount {
display: none;
}
@timiles
timiles / EnumHelper.cs
Created February 6, 2018 19:16
Convert enum type to readable dictionary values
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)
{
@timiles
timiles / bypass server certificate validation check
Last active September 29, 2017 15:43
bypass server certificate validation check
System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
@timiles
timiles / gist:2b634e31b68c3ce97144e905aa092858
Created July 26, 2017 10:10
ng lint teamcity step (bash)
ng lint
errorlevel=$?
if [ $errorlevel -ne 0 ]
then
echo "##teamcity[buildProblem description='Lint errors found, see Build Log for details']"
fi
@timiles
timiles / setup_git_configs.ps1
Last active September 22, 2016 09:08 — forked from deveshjeshani/setup-git-configs.ps1
git config settings
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 March 8, 2016 21:18
Download Barclays bank transactions from logged in view, as csv file. (Export feature does not include balance info.)
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();