Skip to content

Instantly share code, notes, and snippets.

@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, '-']];
@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 / 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();
@timiles
timiles / TestOutputAppender.cs
Last active November 25, 2015 16:52
log4net appender for xunit output. credit: http://stackoverflow.com/a/29907379/487544
using log4net.Appender;
using log4net.Core;
using log4net.Layout;
using Xunit.Abstractions;
public class TestOutputAppender : AppenderSkeleton
{
private readonly ITestOutputHelper _xunitTestOutputHelper;
using System;
using System.Diagnostics;
using System.Collections.Generic;
namespace FlimFlan.Diagnostics
{
public class ColorConsoleTraceListener : ConsoleTraceListener
{
Dictionary<TraceEventType, ConsoleColor> eventColor = new Dictionary<TraceEventType, ConsoleColor>();
@timiles
timiles / AppSettingsReader.cs
Last active August 29, 2015 14:15
Parse keys from config into IDictionary
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration;
using System.Linq;
internal static class AppSettingsReader
{
/// <summary>
@timiles
timiles / ObjectFromNameValueCollectionConverter.cs
Created December 16, 2014 18:46
ObjectFromNameValueCollectionConverter - useful for eg ConfigurationManager.AppSettings
public class ObjectFromNameValueCollectionConverter
{
public static T CreateFromNameValueCollection<T>(NameValueCollection nameValueCollection, string keyPrefix = "")
where T : new()
{
var target = new T();
Type type = target.GetType();
foreach (var key in nameValueCollection.AllKeys.Where(x => x.StartsWith(keyPrefix)))
{
var propertyName = key.Substring(keyPrefix.Length);
internal static System.Web.HttpContext FakeHttpContext()
{
var httpRequest = new System.Web.HttpRequest("", "http://localhost/", "");
var stringWriter = new System.IO.StringWriter();
var httpResponse = new System.Web.HttpResponse(stringWriter);
var httpContext = new System.Web.HttpContext(httpRequest, httpResponse);
var sessionContainer = new System.Web.SessionState.HttpSessionStateContainer(
"id", new System.Web.SessionState.SessionStateItemCollection(),
new System.Web.HttpStaticObjectsCollection(), 10, true,