Skip to content

Instantly share code, notes, and snippets.

@srkirkland
srkirkland / mockextension.cs
Created November 28, 2016 19:47
Moq extensions to turn queryable set of data into a mocked db set that will return that data
public static class MockExtensions
{
public static Mock<DbSet<T>> MockDbSet<T>(this IQueryable<T> data) where T : class, new()
{
var mockSet = new Mock<DbSet<T>>();
mockSet.As<IQueryable<T>>().Setup(m => m.Provider).Returns(data.Provider);
mockSet.As<IQueryable<T>>().Setup(m => m.Expression).Returns(data.Expression);
mockSet.As<IQueryable<T>>().Setup(m => m.ElementType).Returns(data.ElementType);
mockSet.As<IQueryable<T>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
@srkirkland
srkirkland / outgoingips.ps1
Created December 6, 2016 23:54
powershell for outgoing IP addresses
Get-AzureRmResource -ResourceGroupName "Default-Web-WestUS" -ResourceType Microsoft.Web/sites `
-ResourceName prepurchasing -ApiVersion 2015-08-01 | select -expand Properties |
ft @{l=”OutboundIPAddresses”; e={$_.OutboundIPAddresses -split “,”}}
@srkirkland
srkirkland / authtokenfilter.cs
Created May 25, 2017 17:29
Token filter for securing APIs
using System;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Configuration;
using System.Web.Http;
using System.Web.Http.Controllers;
namespace GivingService.Attributes
{
@srkirkland
srkirkland / context.jsx
Created November 29, 2017 18:15
notes about how to enable context in TSX
// Main Type of the context
export interface ProviderContext {
name: String;
}
// Provider
export default class App extends React.Component<{}, {}> {
static childContextTypes = {
name: PropTypes.string
}
@srkirkland
srkirkland / failing.tsx
Created November 29, 2017 22:29
failing typescript stuff
Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op.
Please check the code for the HelloWorld component.
@srkirkland
srkirkland / minst.ipynb
Created December 13, 2017 22:51
minst example for appdev presentation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@srkirkland
srkirkland / migrate.sql
Created April 18, 2019 22:06
use loop and declare variables to call procedure
BEGIN
FOR i IN (SELECT DUPPIDM as pidm FROM MIGRATEPIDMS) LOOP
declare
P_APPL_NO_OUT NUMBER;
term NUMBER;
num_apps NUMBER;
begin
select count(*) into num_apps from saradap where saradap_pidm = i.pidm;
@srkirkland
srkirkland / startup.cs
Created July 1, 2020 19:19
return 403 instead of redirect for API
.AddCookie(cookies =>
{
cookies.Events.OnRedirectToAccessDenied = ctx =>
{
if (ctx.Request.Path.StartsWithSegments("/api"))
{
ctx.Response.StatusCode = (int)HttpStatusCode.Forbidden;
return Task.CompletedTask;
}
return cookies.Events.OnRedirectToAccessDenied(ctx);
@srkirkland
srkirkland / csv_to_point_feature.py
Last active November 4, 2020 23:32
convert and merge csv in arcgis
import arcpy
import pandas as pd
import os
import re
homepath=r"C:\Users\postit\Downloads\testing"
output_path = os.path.join(homepath,"features")
arcpy.env.workspace = output_path
if not os.path.exists(output_path):
@srkirkland
srkirkland / README
Created January 31, 2022 19:03
SSH dotnet
Just an example of running an ssh command on a remote server.
PK file needs to come from somewhere -- I think ideally Secret Vault but also base64 encoded secret would be a good choice.
Library used is https://www.nuget.org/packages/SSH.NET