Skip to content

Instantly share code, notes, and snippets.

@timyhac
timyhac / SQLiteCrudTableGateway.cs
Last active October 10, 2022 23:15
Implements a generic table gateway for SQLite that supports Create, Read, Update and Delete operations.
namespace DapperTest
{
using Dapper;
using System.Data;
using static Dapper.SqlMapper;
namespace DapperTest
{
interface IDbConnectionFactory
@timyhac
timyhac / ef-auto-migrate.cs
Last active November 21, 2020 01:59
How to add Entity Framework Database migrations on startup
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
// Other classes can found at https://docs.microsoft.com/en-us/ef/core/get-started/overview/first-app
// Requires generation of migrations using ef tools
// Standalone, this is a bad idea
@timyhac
timyhac / DynamoDBHistoricalData.py
Created October 4, 2016 06:33
AWS Lambda function to keep historical data for a table
from __future__ import print_function
import json
import boto3
import datetime
dynamodb = boto3.resource('dynamodb', region_name='ap-southeast-1')
table = dynamodb.Table('TableNameHistory')
@timyhac
timyhac / SET_PROXY.sh
Created June 29, 2016 02:40
Set proxy in linux from command line
PROXY="http://username:password@host:port"
export http_proxy=$PROXY
export https_proxy=$PROXY
@timyhac
timyhac / TestSQLconnection.ps1
Created June 23, 2016 02:38
Test sql connection using sqlcmd
PS C:\> sqlcmd -S 'localhost\SQLEXPRESS' -U username -P RealPassword -Q "select getdate()"
-----------------------
2016-06-23 12:37:12.523
(1 rows affected)
PS C:\> sqlcmd -S 'localhost\SQLEXPRESS' -U -U username -P FakePassword -Q "select getdate()"
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login failed for user 'username'..
@timyhac
timyhac / CreateWindowsEC2InstanceLogin.ps1
Created June 22, 2016 04:50
Create Windows EC2 instance and remote desktop to it
Function Start-Countdown
{ <#
.SYNOPSIS
Provide a graphical countdown if you need to pause a script for a period of time
.PARAMETER Seconds
Time, in seconds, that the function will pause
.PARAMETER Messge
Message you want displayed while waiting
.EXAMPLE
Start-Countdown -Seconds 30 -Message Please wait while Active Directory replicates data...
@timyhac
timyhac / PortForward.bat
Created June 22, 2016 03:09
Set up and teardown port forwarding to a remote target PC on a VPN
set LISTENADDRESS=10.40.1.10
set CONNECTADDRESS=10.1.1.20
netsh interface portproxy add v4tov4 listenport=80 listenaddress=%LISTENADDRESS% connectport=63000 connectaddress=%CONNECTADDRESS%
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=%LISTENADDRESS% connectport=63001 connectaddress=%CONNECTADDRESS%
netsh interface portproxy add v4tov4 listenport=44818 listenaddress=%LISTENADDRESS% connectport=63002 connectaddress=%CONNECTADDRESS%
netsh interface portproxy show all
pause
@timyhac
timyhac / PortForward_Remote.bat
Created June 22, 2016 03:09
Set up and tear down port forwarding for a remote host attached to a VPN
set LISTENADDRESS=192.168.1.58
set CONNECTADDRESS=10.1.1.10
netsh interface portproxy add v4tov4 listenport=63000 listenaddress=%LISTENADDRESS% connectport=80 connectaddress=%CONNECTADDRESS%
netsh interface portproxy add v4tov4 listenport=63001 listenaddress=%LISTENADDRESS% connectport=2222 connectaddress=%CONNECTADDRESS%
netsh interface portproxy add v4tov4 listenport=63002 listenaddress=%LISTENADDRESS% connectport=44818 connectaddress=%CONNECTADDRESS%
netsh interface portproxy show all
pause
@timyhac
timyhac / NewGuid.ps1
Created June 22, 2016 01:50
Get new Guid as string in powershell
$MyGuid = ([guid]::NewGuid()).Guid
@timyhac
timyhac / GetMSSQLBackupFolder.ps1
Last active June 21, 2016 06:07
Get SQL Server Backup Folder powershell
Import-Module sqlps
Function GetMSSQLBackupFolder
{
param([string]$ServerInstance)
# taken from https://www.mssqltips.com/sqlservertip/1966/function-to-return-default-sql-server-backup-folder/
$GetBackupFolder = "EXEC master.dbo.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer',N'BackupDirectory'"
return (Invoke-sqlcmd -ServerInstance $ServerInstance -Query $GetBackupFolder).Data