Skip to content

Instantly share code, notes, and snippets.

@TomKearney
TomKearney / savings_calculator.py
Last active April 28, 2020 19:18
Savings calculator
annual_salary = int(input("Enter your annual salary: "))
percentage_to_save = float(input("Enter the % of your salary to save (eg for 10% enter 10): ") / 100
total_cost = int(input("Enter the cost of your dream home: "))
def calculate_savings_timeframe(salary, percentage_to_save, total_cost):
down_payment_target = total_cost * 0.25
savings_rate = float(0.04)
months = total_saved = 0
while total_saved <= down_payment_target:
@TomKearney
TomKearney / data-dictionary-tree.html
Created November 7, 2019 17:29
Data Dictionary Tree Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Tree Example</title>
<style>
.node {
@TomKearney
TomKearney / PrimeNgCalendarUtcDirective.ts
Created December 19, 2018 22:59
Angular override to attempt to workaround shortfalls of PrimeNg Calendar control
import { Directive, Host, Self, HostListener } from '@angular/core';
import { Calendar } from 'primeng/primeng';
import { getMomentDate } from '../datetime/date-time.utils';
@Directive({ selector: '[appUtcOverride]' })
export class PrimeNgCalendarUtcDirective {
constructor(@Host() @Self() private calendar: Calendar) {
}
@TomKearney
TomKearney / ModifyAccount.cs
Last active September 19, 2018 08:08
Entity Framework - modifying an entity
public AccountDo ModifyAccount(AccountDo account)
{
try
{
using (var dbContext = _dbContextFactory.Create())
{
dbContext.Accounts.Attach(Mapper.Map<Account>(account));
dbContext.SaveChanges(); // in this method, as the dirty objects should be flushed on dbContext.Dispose()
} // if we want to log the previous state, intercept the dbcontext methods: https://docs.microsoft.com/en-us/ef/ef6/fundamentals/logging-and-interception
@TomKearney
TomKearney / startup-tasks.txt
Created August 23, 2018 10:29
CMDER initialise with four windows
* -cur_console:d:c:\dev\projects\plutus -cur_console:C:C:\apps\cmder\icons\cmder.ico cmd /k "%ConEmuDir%\..\init.bat"
>* -cur_console:s1T50H -cur_console:d:C:\apps\cmder -cur_console:C:C:\apps\cmder\icons\cmder.ico cmd /k "%ConEmuDir%\..\init.bat"
>* -cur_console:s1T50V -cur_console:d:C:\apps\cmder -cur_console:C:C:\apps\cmder\icons\cmder.ico cmd /k "%ConEmuDir%\..\init.bat"
>* -cur_console:s2T50V -cur_console:d:C:\apps\cmder -cur_console:C:C:\apps\cmder\icons\cmder.ico cmd /k "%ConEmuDir%\..\init.bat"
@TomKearney
TomKearney / TimeZonePoC.cs
Created June 12, 2018 11:21
Proof of windows handling timezones and transitions between standard time and daylight savings time
Console.WriteLine("NOW: " + DateTime.UtcNow);
var timesOfYear = new List<Tuple<string, DateTime>>
{
Tuple.Create("Today (now)", DateTime.UtcNow),
Tuple.Create("Calgary Summer", new DateTime(2018, 6, 27, 14, 30, 0).ToUniversalTime()),
Tuple.Create("Calgary Winter", new DateTime(2018, 11, 21, 14, 00, 0).ToUniversalTime()),
Tuple.Create("In between DST", new DateTime(2018, 3, 19, 14, 30, 0).ToUniversalTime()),
Tuple.Create("Sydney/London crossover", new DateTime(2018, 3, 28, 07, 30, 0).ToUniversalTime()) // London still on GMT, Sydney in DST
};
@TomKearney
TomKearney / CalgaryTimeZones.cs
Last active March 26, 2018 11:05
Determine Calgary market open hours in different timezones
Console.WriteLine("NOW: " + DateTime.UtcNow);
var timesOfYear = new List<Tuple<string, DateTime>>
{
Tuple.Create("Today (now)", DateTime.UtcNow),
Tuple.Create("Calgary Summer", new DateTime(2018, 6, 27, 14, 30, 0).ToUniversalTime()),
Tuple.Create("Calgary Winter", new DateTime(2018, 11, 21, 14, 00, 0).ToUniversalTime()),
Tuple.Create("In between DST", new DateTime(2018, 3, 19, 14, 30, 0).ToUniversalTime())
};
@TomKearney
TomKearney / gist:07ef3cba61ced9e64664
Created February 19, 2015 17:37
Install Raven DB BoxStarter script
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions
Enable-RemoteDesktop
cinst RavenDB
@TomKearney
TomKearney / ScenarioInvoker_Steps.cs
Created June 27, 2012 12:52
Step file to invoke existing scenarios using naming convention.
[Binding]
public class ScenarioInvoker_Steps
{
[Given(@"Successfully run scenario (.*)")]
public void GivenSuccessfullyRunScenario(String featureAndScenarioName)
{
var parts = featureAndScenarioName.Split(new string[] {"S_"}, StringSplitOptions.RemoveEmptyEntries);
if(parts.Length != 2)
throw new ArgumentException("Invalid scenario reference string \"{0}\". Expecting string to be in the format F_N Feature Name S_N Scenario Name");